1 | <?php |
||
33 | abstract class AbstractDataTablesProvider implements DataTablesProviderInterface { |
||
34 | |||
35 | use ButtonTwigExtensionTrait; |
||
36 | use RouterTrait; |
||
37 | use TranslatorTrait; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param RouterInterface $router The router. |
||
43 | * @param TranslatorInterface $translator The translator. |
||
44 | * @param ButtonTwigExtension $buttonTwigExtension The button Twig extension. |
||
45 | */ |
||
46 | public function __construct(RouterInterface $router, TranslatorInterface $translator, ButtonTwigExtension $buttonTwigExtension) { |
||
51 | |||
52 | /** |
||
53 | * {@inheritDoc} |
||
54 | */ |
||
55 | public function getCSVExporter() { |
||
58 | |||
59 | /** |
||
60 | * {@inheritDoc} |
||
61 | */ |
||
62 | public function getEditor() { |
||
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | */ |
||
69 | public function getMethod() { |
||
72 | |||
73 | /** |
||
74 | * {@inheritDoc} |
||
75 | */ |
||
76 | public function getOptions() { |
||
84 | |||
85 | /** |
||
86 | * Render the DataTables buttons. |
||
87 | * |
||
88 | * @param object $entity The entity. |
||
89 | * @param string $editRoute The edit route. |
||
90 | * @param string $deleteRoute The delete route. |
||
91 | * @param bool $enableDelete Enable delete ? |
||
92 | * @return string Returns the DataTables buttons. |
||
93 | * @throws InvalidParameterException Throws an invalid parameter exception if a parameter is invalid. |
||
94 | * @throws RouteNotFoundException Throws a route not found exception if the route doesn't exist. |
||
95 | * @throws MissingMandatoryParametersException Throws a missing mandatory parameter exception if a mandatory exception is missing. |
||
96 | * @deprecated since 3.4.0 use "WBW\Bundle\JQuery\DataTablesBundle\Provider\AbstractDataTablesProvider::renderRowButtons()" instead |
||
97 | */ |
||
98 | protected function renderButtons($entity, $editRoute, $deleteRoute = null, $enableDelete = true) { |
||
104 | |||
105 | /** |
||
106 | * Render a date. |
||
107 | * |
||
108 | * @param DateTime $date The date. |
||
109 | * @param string $format The format. |
||
110 | * @return string Returns the rendered date. |
||
111 | */ |
||
112 | protected function renderDate(DateTime $date = null, $format = "Y-m-d") { |
||
115 | |||
116 | /** |
||
117 | * Render a date/time. |
||
118 | * |
||
119 | * @param DateTime $date The date/time. |
||
120 | * @param string $format The format. |
||
121 | * @return string Returns the rendered date/time. |
||
122 | */ |
||
123 | protected function renderDateTime(DateTime $date = null, $format = DateTimeRenderer::DATETIME_FORMAT) { |
||
126 | |||
127 | /** |
||
128 | * Render a float. |
||
129 | * |
||
130 | * @param float $number The number. |
||
131 | * @param int $decimals The decimals. |
||
132 | * @param string $decPoint The decimal point. |
||
133 | * @param string $thousandsSep The thousands separator. |
||
134 | * @return string Returns the rendered number. |
||
135 | */ |
||
136 | protected function renderFloat($number, $decimals = 2, $decPoint = ".", $thousandsSep = ",") { |
||
142 | |||
143 | /** |
||
144 | * Render the DataTables row buttons. |
||
145 | * |
||
146 | * @param object $entity The entity. |
||
147 | * @param string|null $editRoute The edit route. |
||
148 | * @param string|null $deleteRoute The delete route. |
||
149 | * @param string|null $showRoute The show route. |
||
150 | * @return string Returns the DataTables row buttons. |
||
151 | * @throws InvalidParameterException Throws an invalid parameter exception if a parameter is invalid. |
||
152 | * @throws RouteNotFoundException Throws a route not found exception if the route doesn't exist. |
||
153 | * @throws MissingMandatoryParametersException Throws a missing mandatory parameter exception if a mandatory exception is missing. |
||
154 | */ |
||
155 | protected function renderRowButtons($entity, $editRoute = null, $deleteRoute = null, $showRoute = null) { |
||
193 | |||
194 | /** |
||
195 | * Wrap a content. |
||
196 | * |
||
197 | * @param string|null $prefix The prefix |
||
198 | * @param string $content The content. |
||
199 | * @param string|null $suffix The suffix. |
||
200 | * @return string Returns the wrapped content. |
||
201 | */ |
||
202 | protected function wrapContent($prefix, $content, $suffix) { |
||
216 | } |
||
217 |
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.