@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface HooksContract |
6 | 6 | { |
7 | - /** |
|
8 | - * @return void |
|
9 | - */ |
|
10 | - public function run(); |
|
7 | + /** |
|
8 | + * @return void |
|
9 | + */ |
|
10 | + public function run(); |
|
11 | 11 | } |
@@ -6,8 +6,8 @@ |
||
6 | 6 | |
7 | 7 | interface ProviderContract |
8 | 8 | { |
9 | - /** |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function register(Application $app); |
|
9 | + /** |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function register(Application $app); |
|
13 | 13 | } |
@@ -9,5 +9,5 @@ |
||
9 | 9 | /** |
10 | 10 | * @return void |
11 | 11 | */ |
12 | - public function register(Application $app); |
|
12 | + public function register( Application $app ); |
|
13 | 13 | } |
@@ -68,9 +68,11 @@ discard block |
||
68 | 68 | { |
69 | 69 | if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
70 | 70 | $this->storage[$property] = $value; |
71 | - } elseif (!isset($this->$property)) { |
|
71 | + } |
|
72 | + elseif (!isset($this->$property)) { |
|
72 | 73 | $this->$property = $value; |
73 | - } else { |
|
74 | + } |
|
75 | + else { |
|
74 | 76 | throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
75 | 77 | } |
76 | 78 | } |
@@ -165,7 +167,8 @@ discard block |
||
165 | 167 | { |
166 | 168 | try { |
167 | 169 | return $this->make($parameter->getClass()->name); |
168 | - } catch (Exception $error) { |
|
170 | + } |
|
171 | + catch (Exception $error) { |
|
169 | 172 | if ($parameter->isOptional()) { |
170 | 173 | return $parameter->getDefaultValue(); |
171 | 174 | } |
@@ -11,226 +11,226 @@ |
||
11 | 11 | |
12 | 12 | abstract class Container |
13 | 13 | { |
14 | - const PROTECTED_PROPERTIES = [ |
|
15 | - 'instance', |
|
16 | - 'services', |
|
17 | - 'session', |
|
18 | - 'storage', |
|
19 | - ]; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var static |
|
23 | - */ |
|
24 | - protected static $instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * The container's bound services. |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $services = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $session = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * The container's storage items. |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $storage = []; |
|
42 | - |
|
43 | - /** |
|
44 | - * @return static |
|
45 | - */ |
|
46 | - public static function load() |
|
47 | - { |
|
48 | - if (empty(static::$instance)) { |
|
49 | - static::$instance = new static(); |
|
50 | - } |
|
51 | - return static::$instance; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $property |
|
56 | - * @return mixed |
|
57 | - */ |
|
58 | - public function __get($property) |
|
59 | - { |
|
60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
61 | - return $this->$property; |
|
62 | - } |
|
63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | - if (defined($constant)) { |
|
65 | - return constant($constant); |
|
66 | - } |
|
67 | - return Arr::get($this->storage, $property, null); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param string $property |
|
72 | - * @param string $value |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function __set($property, $value) |
|
76 | - { |
|
77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
78 | - $this->storage[$property] = $value; |
|
79 | - } elseif (!isset($this->$property)) { |
|
80 | - $this->$property = $value; |
|
81 | - } else { |
|
82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Bind a service to the container. |
|
88 | - * @param string $alias |
|
89 | - * @param mixed $concrete |
|
90 | - * @return mixed |
|
91 | - */ |
|
92 | - public function bind($alias, $concrete) |
|
93 | - { |
|
94 | - $this->services[$alias] = $concrete; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Request a service from the container. |
|
99 | - * @param mixed $abstract |
|
100 | - * @return mixed |
|
101 | - */ |
|
102 | - public function make($abstract) |
|
103 | - { |
|
104 | - if (!isset($this->services[$abstract])) { |
|
105 | - $abstract = $this->addNamespace($abstract); |
|
106 | - } |
|
107 | - if (isset($this->services[$abstract])) { |
|
108 | - $abstract = $this->services[$abstract]; |
|
109 | - } |
|
110 | - if (is_callable($abstract)) { |
|
111 | - return call_user_func_array($abstract, [$this]); |
|
112 | - } |
|
113 | - if (is_object($abstract)) { |
|
114 | - return $abstract; |
|
115 | - } |
|
116 | - return $this->resolve($abstract); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function sessionClear() |
|
123 | - { |
|
124 | - $this->session = []; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return mixed |
|
129 | - */ |
|
130 | - public function sessionGet($key, $fallback = '') |
|
131 | - { |
|
132 | - $value = Arr::get($this->session, $key, $fallback); |
|
133 | - unset($this->session[$key]); |
|
134 | - return $value; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public function sessionSet($key, $value) |
|
141 | - { |
|
142 | - $this->session[$key] = $value; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Bind a singleton instance to the container. |
|
147 | - * @param string $alias |
|
148 | - * @param callable|string|null $binding |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - public function singleton($alias, $binding) |
|
152 | - { |
|
153 | - $this->bind($alias, $this->make($binding)); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Prefix the current namespace to the abstract if absent. |
|
158 | - * @param string $abstract |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - protected function addNamespace($abstract) |
|
162 | - { |
|
163 | - if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
164 | - $abstract = __NAMESPACE__.'\\'.$abstract; |
|
165 | - } |
|
166 | - return $abstract; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Resolve a service from the container. |
|
171 | - * @param mixed $concrete |
|
172 | - * @return mixed |
|
173 | - * @throws Exception |
|
174 | - */ |
|
175 | - protected function resolve($concrete) |
|
176 | - { |
|
177 | - if ($concrete instanceof Closure) { |
|
178 | - return $concrete($this); |
|
179 | - } |
|
180 | - $reflector = new ReflectionClass($concrete); |
|
181 | - if (!$reflector->isInstantiable()) { |
|
182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
183 | - } |
|
184 | - $constructor = $reflector->getConstructor(); |
|
185 | - if (empty($constructor)) { |
|
186 | - return new $concrete(); |
|
187 | - } |
|
188 | - return $reflector->newInstanceArgs( |
|
189 | - $this->resolveDependencies($constructor->getParameters()) |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Resolve a class based dependency from the container. |
|
195 | - * @return mixed |
|
196 | - * @throws Exception |
|
197 | - */ |
|
198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
199 | - { |
|
200 | - try { |
|
201 | - return $this->make($parameter->getClass()->name); |
|
202 | - } catch (Exception $error) { |
|
203 | - if ($parameter->isOptional()) { |
|
204 | - return $parameter->getDefaultValue(); |
|
205 | - } |
|
206 | - throw $error; |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Resolve all of the dependencies from the ReflectionParameters. |
|
212 | - * @return array |
|
213 | - */ |
|
214 | - protected function resolveDependencies(array $dependencies) |
|
215 | - { |
|
216 | - $results = []; |
|
217 | - foreach ($dependencies as $dependency) { |
|
218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
219 | - ? $this->resolveClass($dependency) |
|
220 | - : $this->resolveDependency($dependency); |
|
221 | - } |
|
222 | - return $results; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Resolve a single ReflectionParameter dependency. |
|
227 | - * @return array|null |
|
228 | - */ |
|
229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
230 | - { |
|
231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
232 | - return $parameter->getDefaultValue(); |
|
233 | - } |
|
234 | - return null; |
|
235 | - } |
|
14 | + const PROTECTED_PROPERTIES = [ |
|
15 | + 'instance', |
|
16 | + 'services', |
|
17 | + 'session', |
|
18 | + 'storage', |
|
19 | + ]; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var static |
|
23 | + */ |
|
24 | + protected static $instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * The container's bound services. |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $services = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $session = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * The container's storage items. |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $storage = []; |
|
42 | + |
|
43 | + /** |
|
44 | + * @return static |
|
45 | + */ |
|
46 | + public static function load() |
|
47 | + { |
|
48 | + if (empty(static::$instance)) { |
|
49 | + static::$instance = new static(); |
|
50 | + } |
|
51 | + return static::$instance; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $property |
|
56 | + * @return mixed |
|
57 | + */ |
|
58 | + public function __get($property) |
|
59 | + { |
|
60 | + if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
61 | + return $this->$property; |
|
62 | + } |
|
63 | + $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | + if (defined($constant)) { |
|
65 | + return constant($constant); |
|
66 | + } |
|
67 | + return Arr::get($this->storage, $property, null); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param string $property |
|
72 | + * @param string $value |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function __set($property, $value) |
|
76 | + { |
|
77 | + if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
78 | + $this->storage[$property] = $value; |
|
79 | + } elseif (!isset($this->$property)) { |
|
80 | + $this->$property = $value; |
|
81 | + } else { |
|
82 | + throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Bind a service to the container. |
|
88 | + * @param string $alias |
|
89 | + * @param mixed $concrete |
|
90 | + * @return mixed |
|
91 | + */ |
|
92 | + public function bind($alias, $concrete) |
|
93 | + { |
|
94 | + $this->services[$alias] = $concrete; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Request a service from the container. |
|
99 | + * @param mixed $abstract |
|
100 | + * @return mixed |
|
101 | + */ |
|
102 | + public function make($abstract) |
|
103 | + { |
|
104 | + if (!isset($this->services[$abstract])) { |
|
105 | + $abstract = $this->addNamespace($abstract); |
|
106 | + } |
|
107 | + if (isset($this->services[$abstract])) { |
|
108 | + $abstract = $this->services[$abstract]; |
|
109 | + } |
|
110 | + if (is_callable($abstract)) { |
|
111 | + return call_user_func_array($abstract, [$this]); |
|
112 | + } |
|
113 | + if (is_object($abstract)) { |
|
114 | + return $abstract; |
|
115 | + } |
|
116 | + return $this->resolve($abstract); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function sessionClear() |
|
123 | + { |
|
124 | + $this->session = []; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return mixed |
|
129 | + */ |
|
130 | + public function sessionGet($key, $fallback = '') |
|
131 | + { |
|
132 | + $value = Arr::get($this->session, $key, $fallback); |
|
133 | + unset($this->session[$key]); |
|
134 | + return $value; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public function sessionSet($key, $value) |
|
141 | + { |
|
142 | + $this->session[$key] = $value; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Bind a singleton instance to the container. |
|
147 | + * @param string $alias |
|
148 | + * @param callable|string|null $binding |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + public function singleton($alias, $binding) |
|
152 | + { |
|
153 | + $this->bind($alias, $this->make($binding)); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Prefix the current namespace to the abstract if absent. |
|
158 | + * @param string $abstract |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + protected function addNamespace($abstract) |
|
162 | + { |
|
163 | + if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
164 | + $abstract = __NAMESPACE__.'\\'.$abstract; |
|
165 | + } |
|
166 | + return $abstract; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Resolve a service from the container. |
|
171 | + * @param mixed $concrete |
|
172 | + * @return mixed |
|
173 | + * @throws Exception |
|
174 | + */ |
|
175 | + protected function resolve($concrete) |
|
176 | + { |
|
177 | + if ($concrete instanceof Closure) { |
|
178 | + return $concrete($this); |
|
179 | + } |
|
180 | + $reflector = new ReflectionClass($concrete); |
|
181 | + if (!$reflector->isInstantiable()) { |
|
182 | + throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
183 | + } |
|
184 | + $constructor = $reflector->getConstructor(); |
|
185 | + if (empty($constructor)) { |
|
186 | + return new $concrete(); |
|
187 | + } |
|
188 | + return $reflector->newInstanceArgs( |
|
189 | + $this->resolveDependencies($constructor->getParameters()) |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Resolve a class based dependency from the container. |
|
195 | + * @return mixed |
|
196 | + * @throws Exception |
|
197 | + */ |
|
198 | + protected function resolveClass(ReflectionParameter $parameter) |
|
199 | + { |
|
200 | + try { |
|
201 | + return $this->make($parameter->getClass()->name); |
|
202 | + } catch (Exception $error) { |
|
203 | + if ($parameter->isOptional()) { |
|
204 | + return $parameter->getDefaultValue(); |
|
205 | + } |
|
206 | + throw $error; |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Resolve all of the dependencies from the ReflectionParameters. |
|
212 | + * @return array |
|
213 | + */ |
|
214 | + protected function resolveDependencies(array $dependencies) |
|
215 | + { |
|
216 | + $results = []; |
|
217 | + foreach ($dependencies as $dependency) { |
|
218 | + $results[] = !is_null($class = $dependency->getClass()) |
|
219 | + ? $this->resolveClass($dependency) |
|
220 | + : $this->resolveDependency($dependency); |
|
221 | + } |
|
222 | + return $results; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Resolve a single ReflectionParameter dependency. |
|
227 | + * @return array|null |
|
228 | + */ |
|
229 | + protected function resolveDependency(ReflectionParameter $parameter) |
|
230 | + { |
|
231 | + if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
232 | + return $parameter->getDefaultValue(); |
|
233 | + } |
|
234 | + return null; |
|
235 | + } |
|
236 | 236 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public static function load() |
47 | 47 | { |
48 | - if (empty(static::$instance)) { |
|
48 | + if( empty(static::$instance) ) { |
|
49 | 49 | static::$instance = new static(); |
50 | 50 | } |
51 | 51 | return static::$instance; |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | * @param string $property |
56 | 56 | * @return mixed |
57 | 57 | */ |
58 | - public function __get($property) |
|
58 | + public function __get( $property ) |
|
59 | 59 | { |
60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
60 | + if( property_exists( $this, $property ) && !in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
61 | 61 | return $this->$property; |
62 | 62 | } |
63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | - if (defined($constant)) { |
|
65 | - return constant($constant); |
|
63 | + $constant = 'static::'.strtoupper( Str::snakeCase( $property ) ); |
|
64 | + if( defined( $constant ) ) { |
|
65 | + return constant( $constant ); |
|
66 | 66 | } |
67 | - return Arr::get($this->storage, $property, null); |
|
67 | + return Arr::get( $this->storage, $property, null ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | * @param string $value |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public function __set($property, $value) |
|
75 | + public function __set( $property, $value ) |
|
76 | 76 | { |
77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
77 | + if( !property_exists( $this, $property ) || in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
78 | 78 | $this->storage[$property] = $value; |
79 | - } elseif (!isset($this->$property)) { |
|
79 | + } elseif( !isset($this->$property) ) { |
|
80 | 80 | $this->$property = $value; |
81 | 81 | } else { |
82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
82 | + throw new Exception( sprintf( 'The "%s" property cannot be changed once set.', $property ) ); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param mixed $concrete |
90 | 90 | * @return mixed |
91 | 91 | */ |
92 | - public function bind($alias, $concrete) |
|
92 | + public function bind( $alias, $concrete ) |
|
93 | 93 | { |
94 | 94 | $this->services[$alias] = $concrete; |
95 | 95 | } |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | * @param mixed $abstract |
100 | 100 | * @return mixed |
101 | 101 | */ |
102 | - public function make($abstract) |
|
102 | + public function make( $abstract ) |
|
103 | 103 | { |
104 | - if (!isset($this->services[$abstract])) { |
|
105 | - $abstract = $this->addNamespace($abstract); |
|
104 | + if( !isset($this->services[$abstract]) ) { |
|
105 | + $abstract = $this->addNamespace( $abstract ); |
|
106 | 106 | } |
107 | - if (isset($this->services[$abstract])) { |
|
107 | + if( isset($this->services[$abstract]) ) { |
|
108 | 108 | $abstract = $this->services[$abstract]; |
109 | 109 | } |
110 | - if (is_callable($abstract)) { |
|
111 | - return call_user_func_array($abstract, [$this]); |
|
110 | + if( is_callable( $abstract ) ) { |
|
111 | + return call_user_func_array( $abstract, [$this] ); |
|
112 | 112 | } |
113 | - if (is_object($abstract)) { |
|
113 | + if( is_object( $abstract ) ) { |
|
114 | 114 | return $abstract; |
115 | 115 | } |
116 | - return $this->resolve($abstract); |
|
116 | + return $this->resolve( $abstract ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * @return mixed |
129 | 129 | */ |
130 | - public function sessionGet($key, $fallback = '') |
|
130 | + public function sessionGet( $key, $fallback = '' ) |
|
131 | 131 | { |
132 | - $value = Arr::get($this->session, $key, $fallback); |
|
132 | + $value = Arr::get( $this->session, $key, $fallback ); |
|
133 | 133 | unset($this->session[$key]); |
134 | 134 | return $value; |
135 | 135 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * @return void |
139 | 139 | */ |
140 | - public function sessionSet($key, $value) |
|
140 | + public function sessionSet( $key, $value ) |
|
141 | 141 | { |
142 | 142 | $this->session[$key] = $value; |
143 | 143 | } |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param callable|string|null $binding |
149 | 149 | * @return void |
150 | 150 | */ |
151 | - public function singleton($alias, $binding) |
|
151 | + public function singleton( $alias, $binding ) |
|
152 | 152 | { |
153 | - $this->bind($alias, $this->make($binding)); |
|
153 | + $this->bind( $alias, $this->make( $binding ) ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param string $abstract |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - protected function addNamespace($abstract) |
|
161 | + protected function addNamespace( $abstract ) |
|
162 | 162 | { |
163 | - if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
163 | + if( !Str::contains( $abstract, __NAMESPACE__ ) && !class_exists( $abstract ) ) { |
|
164 | 164 | $abstract = __NAMESPACE__.'\\'.$abstract; |
165 | 165 | } |
166 | 166 | return $abstract; |
@@ -172,21 +172,21 @@ discard block |
||
172 | 172 | * @return mixed |
173 | 173 | * @throws Exception |
174 | 174 | */ |
175 | - protected function resolve($concrete) |
|
175 | + protected function resolve( $concrete ) |
|
176 | 176 | { |
177 | - if ($concrete instanceof Closure) { |
|
178 | - return $concrete($this); |
|
177 | + if( $concrete instanceof Closure ) { |
|
178 | + return $concrete( $this ); |
|
179 | 179 | } |
180 | - $reflector = new ReflectionClass($concrete); |
|
181 | - if (!$reflector->isInstantiable()) { |
|
182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
180 | + $reflector = new ReflectionClass( $concrete ); |
|
181 | + if( !$reflector->isInstantiable() ) { |
|
182 | + throw new Exception( 'Target ['.$concrete.'] is not instantiable.' ); |
|
183 | 183 | } |
184 | 184 | $constructor = $reflector->getConstructor(); |
185 | - if (empty($constructor)) { |
|
185 | + if( empty($constructor) ) { |
|
186 | 186 | return new $concrete(); |
187 | 187 | } |
188 | 188 | return $reflector->newInstanceArgs( |
189 | - $this->resolveDependencies($constructor->getParameters()) |
|
189 | + $this->resolveDependencies( $constructor->getParameters() ) |
|
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @return mixed |
196 | 196 | * @throws Exception |
197 | 197 | */ |
198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
198 | + protected function resolveClass( ReflectionParameter $parameter ) |
|
199 | 199 | { |
200 | 200 | try { |
201 | - return $this->make($parameter->getClass()->name); |
|
202 | - } catch (Exception $error) { |
|
203 | - if ($parameter->isOptional()) { |
|
201 | + return $this->make( $parameter->getClass()->name ); |
|
202 | + } catch( Exception $error ) { |
|
203 | + if( $parameter->isOptional() ) { |
|
204 | 204 | return $parameter->getDefaultValue(); |
205 | 205 | } |
206 | 206 | throw $error; |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | * Resolve all of the dependencies from the ReflectionParameters. |
212 | 212 | * @return array |
213 | 213 | */ |
214 | - protected function resolveDependencies(array $dependencies) |
|
214 | + protected function resolveDependencies( array $dependencies ) |
|
215 | 215 | { |
216 | 216 | $results = []; |
217 | - foreach ($dependencies as $dependency) { |
|
218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
219 | - ? $this->resolveClass($dependency) |
|
220 | - : $this->resolveDependency($dependency); |
|
217 | + foreach( $dependencies as $dependency ) { |
|
218 | + $results[] = !is_null( $class = $dependency->getClass() ) |
|
219 | + ? $this->resolveClass( $dependency ) |
|
220 | + : $this->resolveDependency( $dependency ); |
|
221 | 221 | } |
222 | 222 | return $results; |
223 | 223 | } |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | * Resolve a single ReflectionParameter dependency. |
227 | 227 | * @return array|null |
228 | 228 | */ |
229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
229 | + protected function resolveDependency( ReflectionParameter $parameter ) |
|
230 | 230 | { |
231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
231 | + if( $parameter->isArray() && $parameter->isDefaultValueAvailable() ) { |
|
232 | 232 | return $parameter->getDefaultValue(); |
233 | 233 | } |
234 | 234 | return null; |
@@ -7,12 +7,12 @@ |
||
7 | 7 | |
8 | 8 | class RegisterTaxonomy |
9 | 9 | { |
10 | - /** |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function handle(Command $command) |
|
14 | - { |
|
15 | - register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
16 | - register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
17 | - } |
|
10 | + /** |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function handle(Command $command) |
|
14 | + { |
|
15 | + register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
16 | + register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
17 | + } |
|
18 | 18 | } |
@@ -10,9 +10,9 @@ |
||
10 | 10 | /** |
11 | 11 | * @return void |
12 | 12 | */ |
13 | - public function handle(Command $command) |
|
13 | + public function handle( Command $command ) |
|
14 | 14 | { |
15 | - register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
16 | - register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
15 | + register_taxonomy( Application::TAXONOMY, Application::POST_TYPE, $command->args ); |
|
16 | + register_taxonomy_for_object_type( Application::TAXONOMY, Application::POST_TYPE ); |
|
17 | 17 | } |
18 | 18 | } |
@@ -6,16 +6,16 @@ |
||
6 | 6 | |
7 | 7 | class RegisterPostType |
8 | 8 | { |
9 | - /** |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function handle(Command $command) |
|
13 | - { |
|
14 | - if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
15 | - register_post_type($command->postType, $command->args); |
|
16 | - glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
17 | - $command->postType => $command->columns, |
|
18 | - ]); |
|
19 | - } |
|
20 | - } |
|
9 | + /** |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function handle(Command $command) |
|
13 | + { |
|
14 | + if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
15 | + register_post_type($command->postType, $command->args); |
|
16 | + glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
17 | + $command->postType => $command->columns, |
|
18 | + ]); |
|
19 | + } |
|
20 | + } |
|
21 | 21 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | /** |
10 | 10 | * @return void |
11 | 11 | */ |
12 | - public function handle(Command $command) |
|
12 | + public function handle( Command $command ) |
|
13 | 13 | { |
14 | - if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
15 | - register_post_type($command->postType, $command->args); |
|
16 | - glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
14 | + if( !in_array( $command->postType, get_post_types( ['_builtin' => true] ) ) ) { |
|
15 | + register_post_type( $command->postType, $command->args ); |
|
16 | + glsr()->postTypeColumns = wp_parse_args( glsr()->postTypeColumns, [ |
|
17 | 17 | $command->postType => $command->columns, |
18 | - ]); |
|
18 | + ] ); |
|
19 | 19 | } |
20 | 20 | } |
21 | 21 | } |
@@ -148,7 +148,8 @@ |
||
148 | 148 | { |
149 | 149 | if ('parent_id' == $postId) { |
150 | 150 | $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
151 | - } elseif ('post_id' == $postId) { |
|
151 | + } |
|
152 | + elseif ('post_id' == $postId) { |
|
152 | 153 | $postId = intval(get_the_ID()); |
153 | 154 | } |
154 | 155 | return $postId; |
@@ -14,248 +14,248 @@ |
||
14 | 14 | |
15 | 15 | abstract class Shortcode implements ShortcodeContract |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $partialName; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $partialName; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $shortcodeName; |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $shortcodeName; |
|
26 | 26 | |
27 | - public function __construct() |
|
28 | - { |
|
29 | - $this->partialName = $this->getShortcodePartialName(); |
|
30 | - $this->shortcodeName = $this->getShortcodeName(); |
|
31 | - } |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + $this->partialName = $this->getShortcodePartialName(); |
|
30 | + $this->shortcodeName = $this->getShortcodeName(); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param string|array $atts |
|
35 | - * @param string $type |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
39 | - { |
|
40 | - $args = $this->normalizeArgs($args, $type); |
|
41 | - $atts = $this->normalizeAtts($atts, $type); |
|
42 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
43 | - if (!empty($atts['title'])) { |
|
44 | - $atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']); |
|
45 | - } |
|
46 | - $html = glsr(Builder::class)->div((string) $partial, [ |
|
47 | - 'class' => 'glsr glsr-'.glsr(Style::class)->get(), |
|
48 | - 'data-shortcode' => Str::snakeCase($this->partialName), |
|
49 | - 'data-type' => $type, |
|
50 | - 'data-atts' => $atts['json'], // I prefer to have this attribute displayed last |
|
51 | - ]); |
|
52 | - return $args['before_widget'].$atts['title'].$html.$args['after_widget']; |
|
53 | - } |
|
33 | + /** |
|
34 | + * @param string|array $atts |
|
35 | + * @param string $type |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function build($atts, array $args = [], $type = 'shortcode') |
|
39 | + { |
|
40 | + $args = $this->normalizeArgs($args, $type); |
|
41 | + $atts = $this->normalizeAtts($atts, $type); |
|
42 | + $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
43 | + if (!empty($atts['title'])) { |
|
44 | + $atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']); |
|
45 | + } |
|
46 | + $html = glsr(Builder::class)->div((string) $partial, [ |
|
47 | + 'class' => 'glsr glsr-'.glsr(Style::class)->get(), |
|
48 | + 'data-shortcode' => Str::snakeCase($this->partialName), |
|
49 | + 'data-type' => $type, |
|
50 | + 'data-atts' => $atts['json'], // I prefer to have this attribute displayed last |
|
51 | + ]); |
|
52 | + return $args['before_widget'].$atts['title'].$html.$args['after_widget']; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritdoc} |
|
57 | - */ |
|
58 | - public function buildBlock($atts = []) |
|
59 | - { |
|
60 | - return $this->build($atts, [], 'block'); |
|
61 | - } |
|
55 | + /** |
|
56 | + * {@inheritdoc} |
|
57 | + */ |
|
58 | + public function buildBlock($atts = []) |
|
59 | + { |
|
60 | + return $this->build($atts, [], 'block'); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - public function buildShortcode($atts = []) |
|
67 | - { |
|
68 | - return $this->build($atts, [], 'shortcode'); |
|
69 | - } |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + public function buildShortcode($atts = []) |
|
67 | + { |
|
68 | + return $this->build($atts, [], 'shortcode'); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getDefaults($atts) |
|
75 | - { |
|
76 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
77 | - } |
|
71 | + /** |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getDefaults($atts) |
|
75 | + { |
|
76 | + return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getHideOptions() |
|
83 | - { |
|
84 | - $options = $this->hideOptions(); |
|
85 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
86 | - } |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getHideOptions() |
|
83 | + { |
|
84 | + $options = $this->hideOptions(); |
|
85 | + return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getShortClassName($replace = '', $search = 'Shortcode') |
|
92 | - { |
|
93 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
94 | - } |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getShortClassName($replace = '', $search = 'Shortcode') |
|
92 | + { |
|
93 | + return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function getShortcodeDefaultsClassName() |
|
100 | - { |
|
101 | - $className = Str::replaceLast('Shortcode', 'Defaults', get_class($this)); |
|
102 | - return str_replace('Shortcodes', 'Defaults', $className); |
|
103 | - } |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function getShortcodeDefaultsClassName() |
|
100 | + { |
|
101 | + $className = Str::replaceLast('Shortcode', 'Defaults', get_class($this)); |
|
102 | + return str_replace('Shortcodes', 'Defaults', $className); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function getShortcodeName() |
|
109 | - { |
|
110 | - return Str::snakeCase($this->getShortClassName()); |
|
111 | - } |
|
105 | + /** |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function getShortcodeName() |
|
109 | + { |
|
110 | + return Str::snakeCase($this->getShortClassName()); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function getShortcodePartialName() |
|
117 | - { |
|
118 | - return Str::dashCase($this->getShortClassName()); |
|
119 | - } |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function getShortcodePartialName() |
|
117 | + { |
|
118 | + return Str::dashCase($this->getShortClassName()); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @param array|string $args |
|
123 | - * @param string $type |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function normalizeArgs($args, $type = 'shortcode') |
|
127 | - { |
|
128 | - $args = wp_parse_args($args, [ |
|
129 | - 'before_widget' => '', |
|
130 | - 'after_widget' => '', |
|
131 | - 'before_title' => '<h2 class="glsr-title">', |
|
132 | - 'after_title' => '</h2>', |
|
133 | - ]); |
|
134 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
135 | - } |
|
121 | + /** |
|
122 | + * @param array|string $args |
|
123 | + * @param string $type |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function normalizeArgs($args, $type = 'shortcode') |
|
127 | + { |
|
128 | + $args = wp_parse_args($args, [ |
|
129 | + 'before_widget' => '', |
|
130 | + 'after_widget' => '', |
|
131 | + 'before_title' => '<h2 class="glsr-title">', |
|
132 | + 'after_title' => '</h2>', |
|
133 | + ]); |
|
134 | + return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @param array|string $atts |
|
139 | - * @param string $type |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
143 | - { |
|
144 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
145 | - $atts = $this->getDefaults($atts); |
|
146 | - array_walk($atts, function (&$value, $key) { |
|
147 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
148 | - if (!method_exists($this, $methodName)) { |
|
149 | - return; |
|
150 | - } |
|
151 | - $value = $this->$methodName($value); |
|
152 | - }); |
|
153 | - $this->setId($atts); |
|
154 | - return $atts; |
|
155 | - } |
|
137 | + /** |
|
138 | + * @param array|string $atts |
|
139 | + * @param string $type |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function normalizeAtts($atts, $type = 'shortcode') |
|
143 | + { |
|
144 | + $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
145 | + $atts = $this->getDefaults($atts); |
|
146 | + array_walk($atts, function (&$value, $key) { |
|
147 | + $methodName = Helper::buildMethodName($key, 'normalize'); |
|
148 | + if (!method_exists($this, $methodName)) { |
|
149 | + return; |
|
150 | + } |
|
151 | + $value = $this->$methodName($value); |
|
152 | + }); |
|
153 | + $this->setId($atts); |
|
154 | + return $atts; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - abstract protected function hideOptions(); |
|
157 | + /** |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + abstract protected function hideOptions(); |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param string $postId |
|
164 | - * @return int|string |
|
165 | - */ |
|
166 | - protected function normalizeAssignedTo($postId) |
|
167 | - { |
|
168 | - if ('parent_id' == $postId) { |
|
169 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
170 | - } elseif ('post_id' == $postId) { |
|
171 | - $postId = intval(get_the_ID()); |
|
172 | - } |
|
173 | - return $postId; |
|
174 | - } |
|
162 | + /** |
|
163 | + * @param string $postId |
|
164 | + * @return int|string |
|
165 | + */ |
|
166 | + protected function normalizeAssignedTo($postId) |
|
167 | + { |
|
168 | + if ('parent_id' == $postId) { |
|
169 | + $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
170 | + } elseif ('post_id' == $postId) { |
|
171 | + $postId = intval(get_the_ID()); |
|
172 | + } |
|
173 | + return $postId; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @param string $postId |
|
178 | - * @return int|string |
|
179 | - */ |
|
180 | - protected function normalizeAssignTo($postId) |
|
181 | - { |
|
182 | - return $this->normalizeAssignedTo($postId); |
|
183 | - } |
|
176 | + /** |
|
177 | + * @param string $postId |
|
178 | + * @return int|string |
|
179 | + */ |
|
180 | + protected function normalizeAssignTo($postId) |
|
181 | + { |
|
182 | + return $this->normalizeAssignedTo($postId); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @param string|array $hide |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - protected function normalizeHide($hide) |
|
190 | - { |
|
191 | - if (is_string($hide)) { |
|
192 | - $hide = explode(',', $hide); |
|
193 | - } |
|
194 | - $hideKeys = array_keys($this->getHideOptions()); |
|
195 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
196 | - return in_array($value, $hideKeys); |
|
197 | - }); |
|
198 | - } |
|
185 | + /** |
|
186 | + * @param string|array $hide |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + protected function normalizeHide($hide) |
|
190 | + { |
|
191 | + if (is_string($hide)) { |
|
192 | + $hide = explode(',', $hide); |
|
193 | + } |
|
194 | + $hideKeys = array_keys($this->getHideOptions()); |
|
195 | + return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
196 | + return in_array($value, $hideKeys); |
|
197 | + }); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * @param string $id |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - protected function normalizeId($id) |
|
205 | - { |
|
206 | - return sanitize_title($id); |
|
207 | - } |
|
200 | + /** |
|
201 | + * @param string $id |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + protected function normalizeId($id) |
|
205 | + { |
|
206 | + return sanitize_title($id); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * @param string $labels |
|
211 | - * @return array |
|
212 | - */ |
|
213 | - protected function normalizeLabels($labels) |
|
214 | - { |
|
215 | - $defaults = [ |
|
216 | - __('Excellent', 'site-reviews'), |
|
217 | - __('Very good', 'site-reviews'), |
|
218 | - __('Average', 'site-reviews'), |
|
219 | - __('Poor', 'site-reviews'), |
|
220 | - __('Terrible', 'site-reviews'), |
|
221 | - ]; |
|
222 | - $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
223 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
224 | - $labels = array_map('trim', explode(',', $labels)); |
|
225 | - foreach ($defaults as $i => $label) { |
|
226 | - if (empty($labels[$i])) { |
|
227 | - continue; |
|
228 | - } |
|
229 | - $defaults[$i] = $labels[$i]; |
|
230 | - } |
|
231 | - return array_combine(range($maxRating, 1), $defaults); |
|
232 | - } |
|
209 | + /** |
|
210 | + * @param string $labels |
|
211 | + * @return array |
|
212 | + */ |
|
213 | + protected function normalizeLabels($labels) |
|
214 | + { |
|
215 | + $defaults = [ |
|
216 | + __('Excellent', 'site-reviews'), |
|
217 | + __('Very good', 'site-reviews'), |
|
218 | + __('Average', 'site-reviews'), |
|
219 | + __('Poor', 'site-reviews'), |
|
220 | + __('Terrible', 'site-reviews'), |
|
221 | + ]; |
|
222 | + $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
223 | + $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
224 | + $labels = array_map('trim', explode(',', $labels)); |
|
225 | + foreach ($defaults as $i => $label) { |
|
226 | + if (empty($labels[$i])) { |
|
227 | + continue; |
|
228 | + } |
|
229 | + $defaults[$i] = $labels[$i]; |
|
230 | + } |
|
231 | + return array_combine(range($maxRating, 1), $defaults); |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @param string $schema |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - protected function normalizeSchema($schema) |
|
239 | - { |
|
240 | - return wp_validate_boolean($schema); |
|
241 | - } |
|
234 | + /** |
|
235 | + * @param string $schema |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + protected function normalizeSchema($schema) |
|
239 | + { |
|
240 | + return wp_validate_boolean($schema); |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * @param string $text |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - protected function normalizeText($text) |
|
248 | - { |
|
249 | - return trim($text); |
|
250 | - } |
|
243 | + /** |
|
244 | + * @param string $text |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + protected function normalizeText($text) |
|
248 | + { |
|
249 | + return trim($text); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * @return void |
|
254 | - */ |
|
255 | - protected function setId(array &$atts) |
|
256 | - { |
|
257 | - if (empty($atts['id'])) { |
|
258 | - $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
259 | - } |
|
260 | - } |
|
252 | + /** |
|
253 | + * @return void |
|
254 | + */ |
|
255 | + protected function setId(array &$atts) |
|
256 | + { |
|
257 | + if (empty($atts['id'])) { |
|
258 | + $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
259 | + } |
|
260 | + } |
|
261 | 261 | } |
@@ -35,45 +35,45 @@ discard block |
||
35 | 35 | * @param string $type |
36 | 36 | * @return string |
37 | 37 | */ |
38 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
38 | + public function build( $atts, array $args = [], $type = 'shortcode' ) |
|
39 | 39 | { |
40 | - $args = $this->normalizeArgs($args, $type); |
|
41 | - $atts = $this->normalizeAtts($atts, $type); |
|
42 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
43 | - if (!empty($atts['title'])) { |
|
44 | - $atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']); |
|
40 | + $args = $this->normalizeArgs( $args, $type ); |
|
41 | + $atts = $this->normalizeAtts( $atts, $type ); |
|
42 | + $partial = glsr( Partial::class )->build( $this->partialName, $atts ); |
|
43 | + if( !empty($atts['title']) ) { |
|
44 | + $atts = Arr::set( $atts, 'title', $args['before_title'].$atts['title'].$args['after_title'] ); |
|
45 | 45 | } |
46 | - $html = glsr(Builder::class)->div((string) $partial, [ |
|
47 | - 'class' => 'glsr glsr-'.glsr(Style::class)->get(), |
|
48 | - 'data-shortcode' => Str::snakeCase($this->partialName), |
|
46 | + $html = glsr( Builder::class )->div( (string)$partial, [ |
|
47 | + 'class' => 'glsr glsr-'.glsr( Style::class )->get(), |
|
48 | + 'data-shortcode' => Str::snakeCase( $this->partialName ), |
|
49 | 49 | 'data-type' => $type, |
50 | 50 | 'data-atts' => $atts['json'], // I prefer to have this attribute displayed last |
51 | - ]); |
|
51 | + ] ); |
|
52 | 52 | return $args['before_widget'].$atts['title'].$html.$args['after_widget']; |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * {@inheritdoc} |
57 | 57 | */ |
58 | - public function buildBlock($atts = []) |
|
58 | + public function buildBlock( $atts = [] ) |
|
59 | 59 | { |
60 | - return $this->build($atts, [], 'block'); |
|
60 | + return $this->build( $atts, [], 'block' ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * {@inheritdoc} |
65 | 65 | */ |
66 | - public function buildShortcode($atts = []) |
|
66 | + public function buildShortcode( $atts = [] ) |
|
67 | 67 | { |
68 | - return $this->build($atts, [], 'shortcode'); |
|
68 | + return $this->build( $atts, [], 'shortcode' ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @return array |
73 | 73 | */ |
74 | - public function getDefaults($atts) |
|
74 | + public function getDefaults( $atts ) |
|
75 | 75 | { |
76 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
76 | + return glsr( $this->getShortcodeDefaultsClassName() )->restrict( wp_parse_args( $atts ) ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | public function getHideOptions() |
83 | 83 | { |
84 | 84 | $options = $this->hideOptions(); |
85 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
85 | + return apply_filters( 'site-reviews/shortcode/hide-options', $options, $this->shortcodeName ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - public function getShortClassName($replace = '', $search = 'Shortcode') |
|
91 | + public function getShortClassName( $replace = '', $search = 'Shortcode' ) |
|
92 | 92 | { |
93 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
93 | + return str_replace( $search, $replace, (new ReflectionClass( $this ))->getShortName() ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function getShortcodeDefaultsClassName() |
100 | 100 | { |
101 | - $className = Str::replaceLast('Shortcode', 'Defaults', get_class($this)); |
|
102 | - return str_replace('Shortcodes', 'Defaults', $className); |
|
101 | + $className = Str::replaceLast( 'Shortcode', 'Defaults', get_class( $this ) ); |
|
102 | + return str_replace( 'Shortcodes', 'Defaults', $className ); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function getShortcodeName() |
109 | 109 | { |
110 | - return Str::snakeCase($this->getShortClassName()); |
|
110 | + return Str::snakeCase( $this->getShortClassName() ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function getShortcodePartialName() |
117 | 117 | { |
118 | - return Str::dashCase($this->getShortClassName()); |
|
118 | + return Str::dashCase( $this->getShortClassName() ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @param string $type |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - public function normalizeArgs($args, $type = 'shortcode') |
|
126 | + public function normalizeArgs( $args, $type = 'shortcode' ) |
|
127 | 127 | { |
128 | - $args = wp_parse_args($args, [ |
|
128 | + $args = wp_parse_args( $args, [ |
|
129 | 129 | 'before_widget' => '', |
130 | 130 | 'after_widget' => '', |
131 | 131 | 'before_title' => '<h2 class="glsr-title">', |
132 | 132 | 'after_title' => '</h2>', |
133 | - ]); |
|
134 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
133 | + ] ); |
|
134 | + return apply_filters( 'site-reviews/shortcode/args', $args, $type, $this->partialName ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,18 +139,18 @@ discard block |
||
139 | 139 | * @param string $type |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
142 | + public function normalizeAtts( $atts, $type = 'shortcode' ) |
|
143 | 143 | { |
144 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
145 | - $atts = $this->getDefaults($atts); |
|
146 | - array_walk($atts, function (&$value, $key) { |
|
147 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
148 | - if (!method_exists($this, $methodName)) { |
|
144 | + $atts = apply_filters( 'site-reviews/shortcode/atts', $atts, $type, $this->partialName ); |
|
145 | + $atts = $this->getDefaults( $atts ); |
|
146 | + array_walk( $atts, function( &$value, $key ) { |
|
147 | + $methodName = Helper::buildMethodName( $key, 'normalize' ); |
|
148 | + if( !method_exists( $this, $methodName ) ) { |
|
149 | 149 | return; |
150 | 150 | } |
151 | - $value = $this->$methodName($value); |
|
151 | + $value = $this->$methodName( $value ); |
|
152 | 152 | }); |
153 | - $this->setId($atts); |
|
153 | + $this->setId( $atts ); |
|
154 | 154 | return $atts; |
155 | 155 | } |
156 | 156 | |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @param string $postId |
164 | 164 | * @return int|string |
165 | 165 | */ |
166 | - protected function normalizeAssignedTo($postId) |
|
166 | + protected function normalizeAssignedTo( $postId ) |
|
167 | 167 | { |
168 | - if ('parent_id' == $postId) { |
|
169 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
170 | - } elseif ('post_id' == $postId) { |
|
171 | - $postId = intval(get_the_ID()); |
|
168 | + if( 'parent_id' == $postId ) { |
|
169 | + $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ) ) ); |
|
170 | + } elseif( 'post_id' == $postId ) { |
|
171 | + $postId = intval( get_the_ID() ); |
|
172 | 172 | } |
173 | 173 | return $postId; |
174 | 174 | } |
@@ -177,23 +177,23 @@ discard block |
||
177 | 177 | * @param string $postId |
178 | 178 | * @return int|string |
179 | 179 | */ |
180 | - protected function normalizeAssignTo($postId) |
|
180 | + protected function normalizeAssignTo( $postId ) |
|
181 | 181 | { |
182 | - return $this->normalizeAssignedTo($postId); |
|
182 | + return $this->normalizeAssignedTo( $postId ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | 186 | * @param string|array $hide |
187 | 187 | * @return array |
188 | 188 | */ |
189 | - protected function normalizeHide($hide) |
|
189 | + protected function normalizeHide( $hide ) |
|
190 | 190 | { |
191 | - if (is_string($hide)) { |
|
192 | - $hide = explode(',', $hide); |
|
191 | + if( is_string( $hide ) ) { |
|
192 | + $hide = explode( ',', $hide ); |
|
193 | 193 | } |
194 | - $hideKeys = array_keys($this->getHideOptions()); |
|
195 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
196 | - return in_array($value, $hideKeys); |
|
194 | + $hideKeys = array_keys( $this->getHideOptions() ); |
|
195 | + return array_filter( array_map( 'trim', $hide ), function( $value ) use ($hideKeys) { |
|
196 | + return in_array( $value, $hideKeys ); |
|
197 | 197 | }); |
198 | 198 | } |
199 | 199 | |
@@ -201,61 +201,61 @@ discard block |
||
201 | 201 | * @param string $id |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - protected function normalizeId($id) |
|
204 | + protected function normalizeId( $id ) |
|
205 | 205 | { |
206 | - return sanitize_title($id); |
|
206 | + return sanitize_title( $id ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | 210 | * @param string $labels |
211 | 211 | * @return array |
212 | 212 | */ |
213 | - protected function normalizeLabels($labels) |
|
213 | + protected function normalizeLabels( $labels ) |
|
214 | 214 | { |
215 | 215 | $defaults = [ |
216 | - __('Excellent', 'site-reviews'), |
|
217 | - __('Very good', 'site-reviews'), |
|
218 | - __('Average', 'site-reviews'), |
|
219 | - __('Poor', 'site-reviews'), |
|
220 | - __('Terrible', 'site-reviews'), |
|
216 | + __( 'Excellent', 'site-reviews' ), |
|
217 | + __( 'Very good', 'site-reviews' ), |
|
218 | + __( 'Average', 'site-reviews' ), |
|
219 | + __( 'Poor', 'site-reviews' ), |
|
220 | + __( 'Terrible', 'site-reviews' ), |
|
221 | 221 | ]; |
222 | - $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
223 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
224 | - $labels = array_map('trim', explode(',', $labels)); |
|
225 | - foreach ($defaults as $i => $label) { |
|
226 | - if (empty($labels[$i])) { |
|
222 | + $maxRating = (int)glsr()->constant( 'MAX_RATING', Rating::class ); |
|
223 | + $defaults = array_pad( array_slice( $defaults, 0, $maxRating ), $maxRating, '' ); |
|
224 | + $labels = array_map( 'trim', explode( ',', $labels ) ); |
|
225 | + foreach( $defaults as $i => $label ) { |
|
226 | + if( empty($labels[$i]) ) { |
|
227 | 227 | continue; |
228 | 228 | } |
229 | 229 | $defaults[$i] = $labels[$i]; |
230 | 230 | } |
231 | - return array_combine(range($maxRating, 1), $defaults); |
|
231 | + return array_combine( range( $maxRating, 1 ), $defaults ); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @param string $schema |
236 | 236 | * @return bool |
237 | 237 | */ |
238 | - protected function normalizeSchema($schema) |
|
238 | + protected function normalizeSchema( $schema ) |
|
239 | 239 | { |
240 | - return wp_validate_boolean($schema); |
|
240 | + return wp_validate_boolean( $schema ); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
244 | 244 | * @param string $text |
245 | 245 | * @return string |
246 | 246 | */ |
247 | - protected function normalizeText($text) |
|
247 | + protected function normalizeText( $text ) |
|
248 | 248 | { |
249 | - return trim($text); |
|
249 | + return trim( $text ); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * @return void |
254 | 254 | */ |
255 | - protected function setId(array &$atts) |
|
255 | + protected function setId( array &$atts ) |
|
256 | 256 | { |
257 | - if (empty($atts['id'])) { |
|
258 | - $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
257 | + if( empty($atts['id']) ) { |
|
258 | + $atts['id'] = Application::PREFIX.substr( md5( serialize( $atts ) ), 0, 8 ); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
@@ -4,50 +4,50 @@ |
||
4 | 4 | |
5 | 5 | class SiteReviewsFormPopup extends TinymcePopupGenerator |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public function fields() |
|
11 | - { |
|
12 | - return [[ |
|
13 | - 'type' => 'container', |
|
14 | - 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
15 | - ], [ |
|
16 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
17 | - 'name' => 'title', |
|
18 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
19 | - 'type' => 'textbox', |
|
20 | - ], [ |
|
21 | - 'label' => esc_html__('Description', 'site-reviews'), |
|
22 | - 'minHeight' => 60, |
|
23 | - 'minWidth' => 240, |
|
24 | - 'multiline' => true, |
|
25 | - 'name' => 'description', |
|
26 | - 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
27 | - 'type' => 'textbox', |
|
28 | - ], |
|
29 | - $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
30 | - [ |
|
31 | - 'label' => esc_html__('Assign To', 'site-reviews'), |
|
32 | - 'name' => 'assign_to', |
|
33 | - 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
34 | - 'type' => 'textbox', |
|
35 | - ], [ |
|
36 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
37 | - 'name' => 'class', |
|
38 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
39 | - 'type' => 'textbox', |
|
40 | - ], [ |
|
41 | - 'columns' => 2, |
|
42 | - 'items' => $this->getHideOptions(), |
|
43 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
44 | - 'layout' => 'grid', |
|
45 | - 'spacing' => 5, |
|
46 | - 'type' => 'container', |
|
47 | - ], [ |
|
48 | - 'hidden' => true, |
|
49 | - 'name' => 'id', |
|
50 | - 'type' => 'textbox', |
|
51 | - ], ]; |
|
52 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public function fields() |
|
11 | + { |
|
12 | + return [[ |
|
13 | + 'type' => 'container', |
|
14 | + 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
15 | + ], [ |
|
16 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
17 | + 'name' => 'title', |
|
18 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
19 | + 'type' => 'textbox', |
|
20 | + ], [ |
|
21 | + 'label' => esc_html__('Description', 'site-reviews'), |
|
22 | + 'minHeight' => 60, |
|
23 | + 'minWidth' => 240, |
|
24 | + 'multiline' => true, |
|
25 | + 'name' => 'description', |
|
26 | + 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
27 | + 'type' => 'textbox', |
|
28 | + ], |
|
29 | + $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
30 | + [ |
|
31 | + 'label' => esc_html__('Assign To', 'site-reviews'), |
|
32 | + 'name' => 'assign_to', |
|
33 | + 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
34 | + 'type' => 'textbox', |
|
35 | + ], [ |
|
36 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
37 | + 'name' => 'class', |
|
38 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
39 | + 'type' => 'textbox', |
|
40 | + ], [ |
|
41 | + 'columns' => 2, |
|
42 | + 'items' => $this->getHideOptions(), |
|
43 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
44 | + 'layout' => 'grid', |
|
45 | + 'spacing' => 5, |
|
46 | + 'type' => 'container', |
|
47 | + ], [ |
|
48 | + 'hidden' => true, |
|
49 | + 'name' => 'id', |
|
50 | + 'type' => 'textbox', |
|
51 | + ], ]; |
|
52 | + } |
|
53 | 53 | } |
@@ -11,36 +11,36 @@ |
||
11 | 11 | { |
12 | 12 | return [[ |
13 | 13 | 'type' => 'container', |
14 | - 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
14 | + 'html' => '<p class="strong">'.esc_html__( 'All settings are optional.', 'site-reviews' ).'</p>', |
|
15 | 15 | ], [ |
16 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
16 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
17 | 17 | 'name' => 'title', |
18 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
18 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
19 | 19 | 'type' => 'textbox', |
20 | 20 | ], [ |
21 | - 'label' => esc_html__('Description', 'site-reviews'), |
|
21 | + 'label' => esc_html__( 'Description', 'site-reviews' ), |
|
22 | 22 | 'minHeight' => 60, |
23 | 23 | 'minWidth' => 240, |
24 | 24 | 'multiline' => true, |
25 | 25 | 'name' => 'description', |
26 | - 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
26 | + 'tooltip' => __( 'Enter a custom shortcode description.', 'site-reviews' ), |
|
27 | 27 | 'type' => 'textbox', |
28 | 28 | ], |
29 | - $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
29 | + $this->getCategories( __( 'Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews' ) ), |
|
30 | 30 | [ |
31 | - 'label' => esc_html__('Assign To', 'site-reviews'), |
|
31 | + 'label' => esc_html__( 'Assign To', 'site-reviews' ), |
|
32 | 32 | 'name' => 'assign_to', |
33 | - 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
33 | + 'tooltip' => __( 'Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews' ), |
|
34 | 34 | 'type' => 'textbox', |
35 | 35 | ], [ |
36 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
36 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
37 | 37 | 'name' => 'class', |
38 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
38 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
39 | 39 | 'type' => 'textbox', |
40 | 40 | ], [ |
41 | 41 | 'columns' => 2, |
42 | 42 | 'items' => $this->getHideOptions(), |
43 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
43 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
44 | 44 | 'layout' => 'grid', |
45 | 45 | 'spacing' => 5, |
46 | 46 | 'type' => 'container', |
@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | class SiteReviewsSummaryPopup extends SiteReviewsPopup |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public function fields() |
|
11 | - { |
|
12 | - return [[ |
|
13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
14 | - 'minWidth' => 320, |
|
15 | - 'type' => 'container', |
|
16 | - ], [ |
|
17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
18 | - 'name' => 'title', |
|
19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
20 | - 'type' => 'textbox', |
|
21 | - ], |
|
22 | - $this->getTypes(__('Which type of review would you like to use?', 'site-reviews')), |
|
23 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
24 | - [ |
|
25 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
26 | - 'name' => 'assigned_to', |
|
27 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
28 | - 'type' => 'textbox', |
|
29 | - ], [ |
|
30 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
31 | - 'name' => 'schema', |
|
32 | - 'options' => [ |
|
33 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
34 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
35 | - ], |
|
36 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
37 | - 'type' => 'listbox', |
|
38 | - ], [ |
|
39 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
40 | - 'name' => 'class', |
|
41 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
42 | - 'type' => 'textbox', |
|
43 | - ], [ |
|
44 | - 'columns' => 2, |
|
45 | - 'items' => $this->getHideOptions(), |
|
46 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
47 | - 'layout' => 'grid', |
|
48 | - 'spacing' => 5, |
|
49 | - 'type' => 'container', |
|
50 | - ], ]; |
|
51 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public function fields() |
|
11 | + { |
|
12 | + return [[ |
|
13 | + 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
14 | + 'minWidth' => 320, |
|
15 | + 'type' => 'container', |
|
16 | + ], [ |
|
17 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
18 | + 'name' => 'title', |
|
19 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
20 | + 'type' => 'textbox', |
|
21 | + ], |
|
22 | + $this->getTypes(__('Which type of review would you like to use?', 'site-reviews')), |
|
23 | + $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
24 | + [ |
|
25 | + 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
26 | + 'name' => 'assigned_to', |
|
27 | + 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
28 | + 'type' => 'textbox', |
|
29 | + ], [ |
|
30 | + 'label' => esc_html__('Schema', 'site-reviews'), |
|
31 | + 'name' => 'schema', |
|
32 | + 'options' => [ |
|
33 | + 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
34 | + 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
35 | + ], |
|
36 | + 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
37 | + 'type' => 'listbox', |
|
38 | + ], [ |
|
39 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
40 | + 'name' => 'class', |
|
41 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
42 | + 'type' => 'textbox', |
|
43 | + ], [ |
|
44 | + 'columns' => 2, |
|
45 | + 'items' => $this->getHideOptions(), |
|
46 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
47 | + 'layout' => 'grid', |
|
48 | + 'spacing' => 5, |
|
49 | + 'type' => 'container', |
|
50 | + ], ]; |
|
51 | + } |
|
52 | 52 | } |
@@ -10,40 +10,40 @@ |
||
10 | 10 | public function fields() |
11 | 11 | { |
12 | 12 | return [[ |
13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
13 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
14 | 14 | 'minWidth' => 320, |
15 | 15 | 'type' => 'container', |
16 | 16 | ], [ |
17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
17 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
18 | 18 | 'name' => 'title', |
19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
19 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
20 | 20 | 'type' => 'textbox', |
21 | 21 | ], |
22 | - $this->getTypes(__('Which type of review would you like to use?', 'site-reviews')), |
|
23 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
22 | + $this->getTypes( __( 'Which type of review would you like to use?', 'site-reviews' ) ), |
|
23 | + $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' ) ), |
|
24 | 24 | [ |
25 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
25 | + 'label' => esc_html__( 'Assigned To', 'site-reviews' ), |
|
26 | 26 | 'name' => 'assigned_to', |
27 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
27 | + 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews' ), |
|
28 | 28 | 'type' => 'textbox', |
29 | 29 | ], [ |
30 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
30 | + 'label' => esc_html__( 'Schema', 'site-reviews' ), |
|
31 | 31 | 'name' => 'schema', |
32 | 32 | 'options' => [ |
33 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
34 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
33 | + 'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ), |
|
34 | + 'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ), |
|
35 | 35 | ], |
36 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
36 | + 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
|
37 | 37 | 'type' => 'listbox', |
38 | 38 | ], [ |
39 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
39 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
40 | 40 | 'name' => 'class', |
41 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
41 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
42 | 42 | 'type' => 'textbox', |
43 | 43 | ], [ |
44 | 44 | 'columns' => 2, |
45 | 45 | 'items' => $this->getHideOptions(), |
46 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
46 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
47 | 47 | 'layout' => 'grid', |
48 | 48 | 'spacing' => 5, |
49 | 49 | 'type' => 'container', |
@@ -4,17 +4,17 @@ |
||
4 | 4 | |
5 | 5 | class SiteReviewsShortcode extends Shortcode |
6 | 6 | { |
7 | - protected function hideOptions() |
|
8 | - { |
|
9 | - return [ |
|
10 | - 'title' => __('Hide the title', 'site-reviews'), |
|
11 | - 'rating' => __('Hide the rating', 'site-reviews'), |
|
12 | - 'date' => __('Hide the date', 'site-reviews'), |
|
13 | - 'assigned_to' => __('Hide the assigned to link (if shown)', 'site-reviews'), |
|
14 | - 'content' => __('Hide the content', 'site-reviews'), |
|
15 | - 'avatar' => __('Hide the avatar (if shown)', 'site-reviews'), |
|
16 | - 'author' => __('Hide the author', 'site-reviews'), |
|
17 | - 'response' => __('Hide the response', 'site-reviews'), |
|
18 | - ]; |
|
19 | - } |
|
7 | + protected function hideOptions() |
|
8 | + { |
|
9 | + return [ |
|
10 | + 'title' => __('Hide the title', 'site-reviews'), |
|
11 | + 'rating' => __('Hide the rating', 'site-reviews'), |
|
12 | + 'date' => __('Hide the date', 'site-reviews'), |
|
13 | + 'assigned_to' => __('Hide the assigned to link (if shown)', 'site-reviews'), |
|
14 | + 'content' => __('Hide the content', 'site-reviews'), |
|
15 | + 'avatar' => __('Hide the avatar (if shown)', 'site-reviews'), |
|
16 | + 'author' => __('Hide the author', 'site-reviews'), |
|
17 | + 'response' => __('Hide the response', 'site-reviews'), |
|
18 | + ]; |
|
19 | + } |
|
20 | 20 | } |
@@ -7,14 +7,14 @@ |
||
7 | 7 | protected function hideOptions() |
8 | 8 | { |
9 | 9 | return [ |
10 | - 'title' => __('Hide the title', 'site-reviews'), |
|
11 | - 'rating' => __('Hide the rating', 'site-reviews'), |
|
12 | - 'date' => __('Hide the date', 'site-reviews'), |
|
13 | - 'assigned_to' => __('Hide the assigned to link (if shown)', 'site-reviews'), |
|
14 | - 'content' => __('Hide the content', 'site-reviews'), |
|
15 | - 'avatar' => __('Hide the avatar (if shown)', 'site-reviews'), |
|
16 | - 'author' => __('Hide the author', 'site-reviews'), |
|
17 | - 'response' => __('Hide the response', 'site-reviews'), |
|
10 | + 'title' => __( 'Hide the title', 'site-reviews' ), |
|
11 | + 'rating' => __( 'Hide the rating', 'site-reviews' ), |
|
12 | + 'date' => __( 'Hide the date', 'site-reviews' ), |
|
13 | + 'assigned_to' => __( 'Hide the assigned to link (if shown)', 'site-reviews' ), |
|
14 | + 'content' => __( 'Hide the content', 'site-reviews' ), |
|
15 | + 'avatar' => __( 'Hide the avatar (if shown)', 'site-reviews' ), |
|
16 | + 'author' => __( 'Hide the author', 'site-reviews' ), |
|
17 | + 'response' => __( 'Hide the response', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | 19 | } |
20 | 20 | } |