@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | { |
20 | 20 | $this->_registerDebugbar(); |
21 | 21 | $this->publishes([ |
22 | - __DIR__.'/config/config.php' => config_path('widgetize.php'), |
|
22 | + __DIR__ . '/config/config.php' => config_path('widgetize.php'), |
|
23 | 23 | ]); |
24 | 24 | |
25 | 25 | $this->defineDirectives(); |
26 | - $this->loadViewsFrom($this->app->basePath().'/app/Widgets/', 'Widgets'); |
|
26 | + $this->loadViewsFrom($this->app->basePath() . '/app/Widgets/', 'Widgets'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | { |
41 | 41 | $omitParenthesis = version_compare($this->app->version(), '5.3', '<'); |
42 | 42 | |
43 | - Blade::directive('widget', function ($expression) use ($omitParenthesis) { |
|
43 | + Blade::directive('widget', function($expression) use ($omitParenthesis) { |
|
44 | 44 | $expression = $omitParenthesis ? $expression : "($expression)"; |
45 | - if(strpos($expression, 'slotable') == false){ |
|
45 | + if (strpos($expression, 'slotable') == false) { |
|
46 | 46 | return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderWidget{$expression}; ?>"; |
47 | 47 | } |
48 | 48 | $this->expression = preg_replace('/\bslotable\b/u', '', $expression); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | $this->defineSlotDirectives($omitParenthesis); |
52 | 52 | |
53 | - Blade::directive('endwidget', function(){ |
|
53 | + Blade::directive('endwidget', function() { |
|
54 | 54 | $expression = $this->expression; |
55 | 55 | return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderWidget{$expression}; ?>"; |
56 | 56 | }); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->startSlot{$slotName};?>"; |
74 | 74 | }); |
75 | 75 | |
76 | - Blade::directive('endslot', function(){ |
|
76 | + Blade::directive('endslot', function() { |
|
77 | 77 | $contentKey = '$content'; |
78 | 78 | return "<?php |
79 | 79 | $contentKey = ob_get_clean(); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function register() |
91 | 91 | { |
92 | - $this->mergeConfigFrom(__DIR__.'/config/config.php', 'widgetize'); |
|
92 | + $this->mergeConfigFrom(__DIR__ . '/config/config.php', 'widgetize'); |
|
93 | 93 | $this->commands('command.imanghafoori.widget'); |
94 | 94 | app(RouteMacros::class)->registerMacros(); |
95 | 95 | app(SingletonServices::class)->registerSingletons($this->app); |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | |
98 | 98 | private function _registerDebugbar() |
99 | 99 | { |
100 | - if (! $this->app->offsetExists('debugbar')) { |
|
100 | + if (!$this->app->offsetExists('debugbar')) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | - $this->app->singleton('widgetize.debugger', function () { |
|
104 | + $this->app->singleton('widgetize.debugger', function() { |
|
105 | 105 | return new MessagesCollector('Widgets'); |
106 | 106 | }); |
107 | 107 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | if (is_array($widget)) { |
37 | - $widget = (object) $widget; |
|
37 | + $widget = (object)$widget; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | event('widgetize.rendering_widget', [$widget]); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | return resolve($widget); |
59 | 59 | } |
60 | 60 | |
61 | - $widget = app()->getNamespace().'Widgets\\'.$widget; |
|
61 | + $widget = app()->getNamespace() . 'Widgets\\' . $widget; |
|
62 | 62 | |
63 | 63 | return resolve($widget); |
64 | 64 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | private function generateHtml($widget, ...$args) |
75 | 75 | { |
76 | 76 | // Everything inside this function is executed only when the cache is not available. |
77 | - $expensivePhpCode = function () use ($widget, $args) { |
|
77 | + $expensivePhpCode = function() use ($widget, $args) { |
|
78 | 78 | $this->makeDataForView($widget, $args); |
79 | 79 | |
80 | 80 | $this->assignSlots(); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | private function makeDataForView($widget, array $args) |
100 | 100 | { |
101 | - $expensiveCode = function () use ($widget, $args) { |
|
101 | + $expensiveCode = function() use ($widget, $args) { |
|
102 | 102 | $viewData = $this->callController($widget, $args); |
103 | 103 | |
104 | 104 | if ($widget->presenter) { |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | try { |
135 | 135 | $this->html = view($widget->template, $data)->render(); |
136 | 136 | } catch (\Throwable $t) { |
137 | - throw new \ErrorException('There was some error rendering '.get_class($widget).', template file: \''.$widget->template.'\' Error: '.$t->getMessage()); |
|
137 | + throw new \ErrorException('There was some error rendering ' . get_class($widget) . ', template file: \'' . $widget->template . '\' Error: ' . $t->getMessage()); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | // We try to minify the html before storing it in cache to save space. |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | private function callController($widget, array $args) |
155 | 155 | { |
156 | - if (! isset($widget->controller)) { |
|
156 | + if (!isset($widget->controller)) { |
|
157 | 157 | $viewData = []; |
158 | 158 | } elseif (is_array($widget->controller) && is_string($widget->controller[0])) { |
159 | 159 | $viewData = call_user_func_array($widget->controller, $args); |
@@ -4,26 +4,26 @@ |
||
4 | 4 | |
5 | 5 | trait SlotRenderer |
6 | 6 | { |
7 | - protected $slotName; |
|
7 | + protected $slotName; |
|
8 | 8 | |
9 | - protected $slots = []; |
|
9 | + protected $slots = []; |
|
10 | 10 | |
11 | - public function startSlot($name) |
|
12 | - { |
|
13 | - if(ob_start()){ |
|
14 | - $this->slotName = $name; |
|
15 | - } |
|
16 | - } |
|
11 | + public function startSlot($name) |
|
12 | + { |
|
13 | + if(ob_start()){ |
|
14 | + $this->slotName = $name; |
|
15 | + } |
|
16 | + } |
|
17 | 17 | |
18 | - public function renderSlot($data) |
|
19 | - { |
|
20 | - $this->slots[$this->slotName] = $data ?? ""; |
|
21 | - } |
|
18 | + public function renderSlot($data) |
|
19 | + { |
|
20 | + $this->slots[$this->slotName] = $data ?? ""; |
|
21 | + } |
|
22 | 22 | |
23 | - public function hasSlot() |
|
24 | - { |
|
25 | - return !empty($this->slots); |
|
26 | - } |
|
23 | + public function hasSlot() |
|
24 | + { |
|
25 | + return !empty($this->slots); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Assign slots to $_viewData |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | public function startSlot($name) |
12 | 12 | { |
13 | - if(ob_start()){ |
|
13 | + if (ob_start()) { |
|
14 | 14 | $this->slotName = $name; |
15 | 15 | } |
16 | 16 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | private function assignSlots() |
32 | 32 | { |
33 | - if($this->hasSlot()) |
|
33 | + if ($this->hasSlot()) |
|
34 | 34 | $this->_viewData = array_merge($this->_viewData, $this->slots); |
35 | 35 | } |
36 | 36 | } |
37 | 37 | \ No newline at end of file |
@@ -30,7 +30,8 @@ |
||
30 | 30 | */ |
31 | 31 | private function assignSlots() |
32 | 32 | { |
33 | - if($this->hasSlot()) |
|
34 | - $this->_viewData = array_merge($this->_viewData, $this->slots); |
|
33 | + if($this->hasSlot()) { |
|
34 | + $this->_viewData = array_merge($this->_viewData, $this->slots); |
|
35 | + } |
|
35 | 36 | } |
36 | 37 | } |
37 | 38 | \ No newline at end of file |