@@ -16,9 +16,9 @@ |
||
16 | 16 | $configuration = new Configuration(); |
17 | 17 | $config = $this->processConfiguration($configuration, $configs); |
18 | 18 | |
19 | - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
19 | + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
20 | 20 | $loader->load('services.xml'); |
21 | - $ymlLoader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
21 | + $ymlLoader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
22 | 22 | $ymlLoader->load('data_grid.yml'); |
23 | 23 | |
24 | 24 | $container->getDefinition('data_grid.configuration') |
@@ -30,9 +30,9 @@ |
||
30 | 30 | ]; |
31 | 31 | } |
32 | 32 | |
33 | - public function generateGrid(Environment $environment, DataGrid $grid, array $attributes = []){ |
|
33 | + public function generateGrid(Environment $environment, DataGrid $grid, array $attributes = []) { |
|
34 | 34 | $template = $grid->getTemplate(); |
35 | - if (!$template->hasBlock('grid_table', [])){ |
|
35 | + if (!$template->hasBlock('grid_table', [])) { |
|
36 | 36 | $template = $environment->loadTemplate(self::DEFAULT_TEMPLATE); |
37 | 37 | $grid->setTemplate($template); |
38 | 38 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | { |
27 | 27 | $this->container = $container; |
28 | 28 | foreach ($config as $key => $value) { |
29 | - $setter = 'set' . ucfirst($key); |
|
29 | + $setter = 'set'.ucfirst($key); |
|
30 | 30 | if (method_exists($this, $setter)) { |
31 | 31 | $this->$setter($value); |
32 | 32 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | protected function checkConfiguration() |
41 | 41 | { |
42 | - if (!is_string($this->attribute) && $this->value === null){ |
|
42 | + if (!is_string($this->attribute) && $this->value === null) { |
|
43 | 43 | throw new Exception('attribute or value property must be set for DataColumn'); |
44 | 44 | } |
45 | 45 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | public function getFilterContent() |
58 | 58 | { |
59 | - if ($this->hasFilter()){ |
|
59 | + if ($this->hasFilter()) { |
|
60 | 60 | return $this->filter->render($this->attribute, $this->filterValue); |
61 | 61 | } |
62 | 62 | return ''; |
@@ -70,26 +70,26 @@ discard block |
||
70 | 70 | : htmlspecialchars($result); |
71 | 71 | } |
72 | 72 | |
73 | - public function getAttribute(){ |
|
73 | + public function getAttribute() { |
|
74 | 74 | return $this->attribute; |
75 | 75 | } |
76 | 76 | |
77 | - protected function getCellValue($entity){ |
|
78 | - if (is_callable($this->value)){ |
|
77 | + protected function getCellValue($entity) { |
|
78 | + if (is_callable($this->value)) { |
|
79 | 79 | return call_user_func_array($this->value, [$entity]); |
80 | - } elseif ($this->value !== null){ |
|
80 | + } elseif ($this->value !== null) { |
|
81 | 81 | return $this->value; |
82 | 82 | } else { |
83 | 83 | return $this->getEntityAttribute($entity, $this->attribute); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - protected function getEntityAttribute($entity, $attribute){ |
|
88 | - $attribute = preg_replace_callback('/_([A-z]?)/', function($matches){ |
|
87 | + protected function getEntityAttribute($entity, $attribute) { |
|
88 | + $attribute = preg_replace_callback('/_([A-z]?)/', function($matches) { |
|
89 | 89 | return isset($matches[1]) ? strtoupper($matches[1]) : ''; |
90 | 90 | }, $attribute); |
91 | 91 | $getter = 'get'.ucfirst($attribute); |
92 | - if (method_exists($entity, $getter)){ |
|
92 | + if (method_exists($entity, $getter)) { |
|
93 | 93 | return $entity->$getter(); |
94 | 94 | } |
95 | 95 | throw new Exception('Unknown property '.$attribute.' in '.get_class($entity)); |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | function getCellContent($entity, ?DataGrid $grid) |
42 | 42 | { |
43 | 43 | return preg_replace_callback('/\{(\w+)\}/', function($matches) use ($entity, $grid) { |
44 | - if ($this->isButtonVisible($matches[1])){ |
|
45 | - if (array_key_exists($matches[1], $this->buttons) && is_callable($this->buttons[$matches[1]])){ |
|
44 | + if ($this->isButtonVisible($matches[1])) { |
|
45 | + if (array_key_exists($matches[1], $this->buttons) && is_callable($this->buttons[$matches[1]])) { |
|
46 | 46 | return call_user_func_array($this->buttons[$matches[1]], [ |
47 | 47 | $entity, |
48 | 48 | $this->generateUrl($entity, $matches[1], $grid) |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @return mixed|string |
66 | 66 | * @throws Exception |
67 | 67 | */ |
68 | - protected function generateUrl($entity, $action, $grid){ |
|
69 | - if ($this->urlGenerator != null && is_callable($this->urlGenerator)){ |
|
68 | + protected function generateUrl($entity, $action, $grid) { |
|
69 | + if ($this->urlGenerator != null && is_callable($this->urlGenerator)) { |
|
70 | 70 | return call_user_func_array($this->urlGenerator, [$entity, $action, $grid->getRouter()]); |
71 | 71 | } elseif (method_exists($entity, 'getId')) { |
72 | 72 | return $grid->getRouter()->generate($this->pathPrefix.$action, ['id' => $entity->getId()]); |
@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | */ |
33 | 33 | protected $container; |
34 | 34 | |
35 | - public function __construct(ContainerInterface $container,array $config = []) |
|
35 | + public function __construct(ContainerInterface $container, array $config = []) |
|
36 | 36 | { |
37 | 37 | |
38 | 38 | $this->container = $container; |
39 | - foreach ($config as $key => $value){ |
|
39 | + foreach ($config as $key => $value) { |
|
40 | 40 | $setter = 'set'.ucfirst($key); |
41 | - if (method_exists($this, $setter)){ |
|
41 | + if (method_exists($this, $setter)) { |
|
42 | 42 | $this->$setter($value); |
43 | 43 | } |
44 | 44 | } |
45 | 45 | $this->checkConfiguration(); |
46 | 46 | } |
47 | 47 | |
48 | - protected function checkConfiguration(){ |
|
48 | + protected function checkConfiguration() { |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | - public function getAttributes(){ |
|
52 | + public function getAttributes() { |
|
53 | 53 | return $this->attributes; |
54 | 54 | } |
55 | 55 | |
56 | - public function hasAttributes(){ |
|
56 | + public function hasAttributes() { |
|
57 | 57 | return !empty($this->attributes); |
58 | 58 | } |
59 | 59 | /** |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | { |
95 | 95 | $this->label = $label; |
96 | 96 | } |
97 | - public function hasFilter(){ |
|
97 | + public function hasFilter() { |
|
98 | 98 | return is_subclass_of($this->filter, AbstractFilter::class); |
99 | 99 | } |
100 | 100 | |
101 | - public function getFilter(){ |
|
101 | + public function getFilter() { |
|
102 | 102 | return $this->filter; |
103 | 103 | } |
104 | 104 | |
105 | - public function setFilter(array $filter){ |
|
105 | + public function setFilter(array $filter) { |
|
106 | 106 | $filterClass = $filter['class']; |
107 | 107 | unset($filter['class']); |
108 | 108 | $filter['template'] = $this->template; |
@@ -112,26 +112,26 @@ discard block |
||
112 | 112 | |
113 | 113 | |
114 | 114 | |
115 | - public function hasSort(){ |
|
115 | + public function hasSort() { |
|
116 | 116 | return $this->sort !== false && !empty($this->attribute); |
117 | 117 | } |
118 | 118 | |
119 | - public function setSort($direction){ |
|
119 | + public function setSort($direction) { |
|
120 | 120 | $this->sort = $direction; |
121 | 121 | } |
122 | 122 | |
123 | - public function getSort(){ |
|
123 | + public function getSort() { |
|
124 | 124 | return $this->sort; |
125 | 125 | } |
126 | 126 | |
127 | - public function getAttribute(){ |
|
127 | + public function getAttribute() { |
|
128 | 128 | return null; |
129 | 129 | } |
130 | 130 | |
131 | - public function getFilterValue(){ |
|
131 | + public function getFilterValue() { |
|
132 | 132 | return $this->filterValue; |
133 | 133 | } |
134 | - public function setFilterValue($value){ |
|
134 | + public function setFilterValue($value) { |
|
135 | 135 | $this->filterValue = $value; |
136 | 136 | } |
137 | 137 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | public function setTemplate($template): void |
156 | 156 | { |
157 | 157 | $this->template = $template; |
158 | - if ($this->hasFilter()){ |
|
158 | + if ($this->hasFilter()) { |
|
159 | 159 | $this->filter->setTemplate($template); |
160 | 160 | } |
161 | 161 | } |
@@ -13,9 +13,9 @@ |
||
13 | 13 | |
14 | 14 | function getCellContent($entity, ?DataGrid $grid) |
15 | 15 | { |
16 | - if (is_callable($this->value)){ |
|
16 | + if (is_callable($this->value)) { |
|
17 | 17 | $result = call_user_func_array($this->value, [$entity]); |
18 | - } elseif ($this->value !== null){ |
|
18 | + } elseif ($this->value !== null) { |
|
19 | 19 | $result = $this->value == true ? $this->trueValue : $this->falseValue; |
20 | 20 | } else { |
21 | 21 | $result = $this->getEntityAttribute($entity, $this->attribute) == true ? $this->trueValue : $this->falseValue; |
@@ -14,9 +14,9 @@ |
||
14 | 14 | public function getCellContent($entity, ?DataGrid $grid) |
15 | 15 | { |
16 | 16 | $value = $this->getCellValue($entity); |
17 | - if ($value instanceof DateTime){ |
|
17 | + if ($value instanceof DateTime) { |
|
18 | 18 | return $value->format($this->dateFormat); |
19 | - } elseif (is_string($value) && $this->dateFormat != null){ |
|
19 | + } elseif (is_string($value) && $this->dateFormat != null) { |
|
20 | 20 | return date($this->dateFormat, strtotime($value)); |
21 | 21 | } |
22 | 22 | return (string)$value; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function addColumn(string $columnClass, array $config = []): DataGridBuilderInterface |
45 | 45 | { |
46 | 46 | if (!is_subclass_of($columnClass, AbstractColumn::class)) { |
47 | - throw new InvalidArgumentException('Expected subclass of' . AbstractColumn::class); |
|
47 | + throw new InvalidArgumentException('Expected subclass of'.AbstractColumn::class); |
|
48 | 48 | } |
49 | 49 | $this->columns[] = new $columnClass($this->container, array_merge(['template' => $this->options['template']], $config)); |
50 | 50 | return $this; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function setTemplate(string $path) : DataGridBuilderInterface |
67 | 67 | { |
68 | 68 | $this->options['template'] = $path; |
69 | - foreach ($this->columns as $column){ |
|
69 | + foreach ($this->columns as $column) { |
|
70 | 70 | $column->setTemplate($path); |
71 | 71 | } |
72 | 72 | return $this; |