1 <?php
2
3 /*
4 * This file is part of the Brickrouge package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Brickrouge;
13
14 /**
15 * Interface for classes implementing CSS class names.
16 *
17 * Classes implementing the interface should provide the {@link css_class} and
18 * {@link css_class_names} magic properties.
19 *
20 * @property-read string $css_class The CSS class of the instance.
21 * @property-read array[string]mixed $css_class_names The CSS class names of the instance.
22 */
23 trait CSSClassNamesProperty
24 {
25 /**
26 * Return the rendered CSS class of the instance.
27 *
28 * @param string|array $modifiers CSS class names modifiers
29 *
30 * @return string
31 */
32 public function css_class($modifiers=null)
33 {
34 return render_css_class($this->css_class_names, $modifiers);
35 }
36
37 /**
38 * Returns the CSS class of the instance.
39 *
40 * @return string
41 */
42 protected function get_css_class()
43 {
44 return $this->css_class();
45 }
46
47 /**
48 * Returns the CSS class names of the instance.
49 *
50 * @return array[string]mixed
51 */
52 abstract protected function get_css_class_names();
53
54 /**
55 * The method is declared as abstract because the {@link get_css_class()} and
56 * {@link get_css_class_names()} method are meant to be mapped to magic properties.
57 *
58 * @param string $property
59 */
60 abstract public function __get($property);
61 }