-
Notifications
You must be signed in to change notification settings - Fork 141
/
Factory.php
99 lines (89 loc) · 2.42 KB
/
Factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Liuggio\ExcelBundle;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* Factory for PHPExcel objects, StreamedResponse, and PHPExcel_Writer_IWriter.
*
* @package Liuggio\ExcelBundle
*/
class Factory
{
private $phpExcelIO;
public function __construct($phpExcelIO = '\PHPExcel_IOFactory')
{
$this->phpExcelIO = $phpExcelIO;
}
/**
* Creates an empty PHPExcel Object if the filename is empty, otherwise loads the file into the object.
*
* @param string $filename
*
* @return \PHPExcel
*/
public function createPHPExcelObject($filename = null)
{
return (null === $filename) ? new \PHPExcel() : call_user_func(array($this->phpExcelIO, 'load'), $filename);
}
/**
* Create a worksheet drawing
* @return \PHPExcel_Worksheet_Drawing
*/
public function createPHPExcelWorksheetDrawing()
{
return new \PHPExcel_Worksheet_Drawing();
}
/**
* Create a reader
*
* @param string $type
*
*
* @return \PHPExcel_Reader_IReader
*/
public function createReader($type = 'Excel5')
{
return call_user_func(array($this->phpExcelIO, 'createReader'), $type);
}
/**
* Create a writer given the PHPExcelObject and the type,
* the type could be one of PHPExcel_IOFactory::$_autoResolveClasses
*
* @param \PHPExcel $phpExcelObject
* @param string $type
*
*
* @return \PHPExcel_Writer_IWriter
*/
public function createWriter(\PHPExcel $phpExcelObject, $type = 'Excel5')
{
return call_user_func(array($this->phpExcelIO, 'createWriter'), $phpExcelObject, $type);
}
/**
* Stream the file as Response.
*
* @param \PHPExcel_Writer_IWriter $writer
* @param int $status
* @param array $headers
*
* @return StreamedResponse
*/
public function createStreamedResponse(\PHPExcel_Writer_IWriter $writer, $status = 200, $headers = array())
{
return new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
},
$status,
$headers
);
}
/**
* Create a PHPExcel Helper HTML Object
*
* @return \PHPExcel_Helper_HTML
*/
public function createHelperHTML()
{
return new \PHPExcel_Helper_HTML();
}
}