1 | <?php |
||
26 | class Exporter extends NewExcelFile |
||
27 | { |
||
28 | /** Current supported files type */ |
||
29 | const TYPE_CSV = 'csv'; |
||
30 | const TYPE_XLS = 'xls'; |
||
31 | const TYPE_XLSX = 'xlsx'; |
||
32 | |||
33 | /** |
||
34 | * Parameters. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $params = []; |
||
39 | |||
40 | /** |
||
41 | * Export file format. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $format = self::TYPE_CSV; |
||
46 | |||
47 | /** |
||
48 | * Type of data to export. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $type = ''; |
||
53 | |||
54 | /** |
||
55 | * Returns the parameters. |
||
56 | * |
||
57 | * @param string $key |
||
58 | * |
||
59 | * @return string|\Illuminate\Database\Eloquent\Model|null |
||
60 | */ |
||
61 | public function getParams($key = null) |
||
69 | |||
70 | /** |
||
71 | * Start importing. |
||
72 | * |
||
73 | * @param string $className |
||
74 | * @param string $format |
||
75 | * @param array $params |
||
76 | * |
||
77 | * @return array['full', 'path', 'file', 'title', 'ext'] |
||
78 | */ |
||
79 | public function exportFile($className, $format = self::TYPE_CSV, array $params = []) |
||
95 | |||
96 | /** |
||
97 | * Returns export file name. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getFilename() |
||
105 | |||
106 | /** |
||
107 | * Construct the export class full name. |
||
108 | * |
||
109 | * @param string $type |
||
110 | * |
||
111 | * @return string |
||
112 | * |
||
113 | * @throws LaravelExcelException |
||
114 | */ |
||
115 | protected function getHandlerClassName($type) |
||
126 | } |
||
127 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.