@@ -68,7 +68,7 @@ |
||
68 | 68 | */ |
69 | 69 | public function register(): void |
70 | 70 | { |
71 | - $this->app->bind(Configuration::class, function (ContainerInterface $app) { |
|
71 | + $this->app->bind(Configuration::class, function(ContainerInterface $app) { |
|
72 | 72 | return new Configuration($app->get(Config::class)->get('lang', [])); |
73 | 73 | }); |
74 | 74 | $this->app->share(StorageInterface::class, MemoryStorage::class); |
@@ -61,14 +61,13 @@ |
||
61 | 61 | * @class LangServiceProvider |
62 | 62 | * @package Platine\Framework\Service\Provider |
63 | 63 | */ |
64 | -class LangServiceProvider extends ServiceProvider |
|
65 | -{ |
|
64 | +class LangServiceProvider extends ServiceProvider { |
|
66 | 65 | /** |
67 | 66 | * {@inheritdoc} |
68 | 67 | */ |
69 | 68 | public function register(): void |
70 | 69 | { |
71 | - $this->app->bind(Configuration::class, function (ContainerInterface $app) { |
|
70 | + $this->app->bind(Configuration::class, function (ContainerInterface $app) { |
|
72 | 71 | return new Configuration($app->get(Config::class)->get('lang', [])); |
73 | 72 | }); |
74 | 73 | $this->app->share(StorageInterface::class, MemoryStorage::class); |
@@ -57,8 +57,7 @@ discard block |
||
57 | 57 | * @class ServiceProvider |
58 | 58 | * @package Platine\Framework\Service |
59 | 59 | */ |
60 | -class ServiceProvider |
|
61 | -{ |
|
60 | +class ServiceProvider { |
|
62 | 61 | /** |
63 | 62 | * The Application instance |
64 | 63 | * @var Application |
@@ -81,8 +80,7 @@ discard block |
||
81 | 80 | * Create new instance |
82 | 81 | * @param Application $app |
83 | 82 | */ |
84 | - public function __construct(Application $app) |
|
85 | - { |
|
83 | + public function __construct(Application $app) { |
|
86 | 84 | $this->app = $app; |
87 | 85 | } |
88 | 86 |
@@ -128,10 +128,10 @@ |
||
128 | 128 | $name = $results['key']; |
129 | 129 | |
130 | 130 | $config = $this->loader->loadConfig([ |
131 | - 'name' => $name, |
|
132 | - 'module' => $module, |
|
133 | - 'env' => $this->env |
|
134 | - ]); |
|
131 | + 'name' => $name, |
|
132 | + 'module' => $module, |
|
133 | + 'env' => $this->env |
|
134 | + ]); |
|
135 | 135 | |
136 | 136 | if ($config === null) { |
137 | 137 | $this->loader->insertConfig([ |
@@ -57,8 +57,7 @@ discard block |
||
57 | 57 | * @template TDbConfigurationEntity as \Platine\Framework\Config\Model\Configuration |
58 | 58 | * @implements ArrayAccess<string, mixed> |
59 | 59 | */ |
60 | -class AppDatabaseConfig implements ArrayAccess |
|
61 | -{ |
|
60 | +class AppDatabaseConfig implements ArrayAccess { |
|
62 | 61 | /** |
63 | 62 | * The configuration loader to use |
64 | 63 | * @var DatabaseConfigLoaderInterface<TDbConfigurationEntity> |
@@ -82,8 +81,7 @@ discard block |
||
82 | 81 | * @param DatabaseConfigLoaderInterface<TDbConfigurationEntity> $loader the loader to use |
83 | 82 | * @param string $env the name of the environment |
84 | 83 | */ |
85 | - public function __construct(DatabaseConfigLoaderInterface $loader, string $env = '') |
|
86 | - { |
|
84 | + public function __construct(DatabaseConfigLoaderInterface $loader, string $env = '') { |
|
87 | 85 | $this->loader = $loader; |
88 | 86 | $this->env = $env; |
89 | 87 | } |
@@ -105,8 +103,7 @@ discard block |
||
105 | 103 | * not find the configuration item |
106 | 104 | * @return mixed |
107 | 105 | */ |
108 | - public function get(string $key, $default = null) |
|
109 | - { |
|
106 | + public function get(string $key, $default = null) { |
|
110 | 107 | $results = $this->parseKey($key); |
111 | 108 | $group = $results['group']; |
112 | 109 | |
@@ -133,7 +130,7 @@ discard block |
||
133 | 130 | 'env' => $this->env |
134 | 131 | ]); |
135 | 132 | |
136 | - if ($config === null) { |
|
133 | + if ($config === null) { |
|
137 | 134 | $this->loader->insertConfig([ |
138 | 135 | 'env' => $this->env, |
139 | 136 | 'module' => $module, |
@@ -142,7 +139,7 @@ discard block |
||
142 | 139 | 'value' => $this->getFormattedConfigValue($value), |
143 | 140 | 'type' => gettype($value) |
144 | 141 | ]); |
145 | - } else { |
|
142 | + } else { |
|
146 | 143 | $config->value = $this->getFormattedConfigValue($value); |
147 | 144 | $config->type = gettype($value); |
148 | 145 | |
@@ -215,16 +212,14 @@ discard block |
||
215 | 212 | /** |
216 | 213 | * {@inheritdoc} |
217 | 214 | */ |
218 | - public function offsetExists($key) |
|
219 | - { |
|
215 | + public function offsetExists($key) { |
|
220 | 216 | return $this->has($key); |
221 | 217 | } |
222 | 218 | |
223 | 219 | /** |
224 | 220 | * {@inheritdoc} |
225 | 221 | */ |
226 | - public function offsetGet($key) |
|
227 | - { |
|
222 | + public function offsetGet($key) { |
|
228 | 223 | return $this->get($key); |
229 | 224 | } |
230 | 225 | |
@@ -234,16 +229,14 @@ discard block |
||
234 | 229 | * @param mixed $value |
235 | 230 | * @return void |
236 | 231 | */ |
237 | - public function offsetSet($key, $value) |
|
238 | - { |
|
232 | + public function offsetSet($key, $value) { |
|
239 | 233 | $this->set($key, $value); |
240 | 234 | } |
241 | 235 | |
242 | 236 | /** |
243 | 237 | * {@inheritdoc} |
244 | 238 | */ |
245 | - public function offsetUnset($key) |
|
246 | - { |
|
239 | + public function offsetUnset($key) { |
|
247 | 240 | $this->set($key, null); |
248 | 241 | } |
249 | 242 | |
@@ -257,7 +250,7 @@ discard block |
||
257 | 250 | // If we've already loaded this collection, we will just bail out since we do |
258 | 251 | // not want to load it again. Once items are loaded a first time they will |
259 | 252 | // stay kept in memory within this class and not loaded from disk again. |
260 | - if (isset($this->items[$group])) { |
|
253 | + if (isset($this->items[$group])) { |
|
261 | 254 | return; |
262 | 255 | } |
263 | 256 | |
@@ -272,7 +265,7 @@ discard block |
||
272 | 265 | */ |
273 | 266 | protected function parseKey(string $key): array |
274 | 267 | { |
275 | - if (strpos($key, '.') === false) { |
|
268 | + if (strpos($key, '.') === false) { |
|
276 | 269 | throw new InvalidArgumentException(sprintf( |
277 | 270 | 'Invalid configuration key [%s] must have format module.name', |
278 | 271 | $key |
@@ -292,9 +285,8 @@ discard block |
||
292 | 285 | * @param mixed $value |
293 | 286 | * @return mixed |
294 | 287 | */ |
295 | - protected function getFormattedConfigValue($value) |
|
296 | - { |
|
297 | - if (is_array($value) || is_object($value)) { |
|
288 | + protected function getFormattedConfigValue($value) { |
|
289 | + if (is_array($value) || is_object($value)) { |
|
298 | 290 | return serialize($value); |
299 | 291 | } |
300 | 292 |
@@ -128,7 +128,7 @@ |
||
128 | 128 | ->query() |
129 | 129 | ->where('module')->is($group) |
130 | 130 | ->where('status')->is('Y') |
131 | - ->where(function (WhereStatement $where) use ($env) { |
|
131 | + ->where(function(WhereStatement $where) use ($env) { |
|
132 | 132 | $where->where('env')->is($env) |
133 | 133 | ->orWhere('env')->isNull(); |
134 | 134 | }); |
@@ -56,8 +56,7 @@ discard block |
||
56 | 56 | * @package Platine\Framework\Config |
57 | 57 | * @implements DatabaseConfigLoaderInterface<Configuration> |
58 | 58 | */ |
59 | -class DatabaseConfigLoader implements DatabaseConfigLoaderInterface |
|
60 | -{ |
|
59 | +class DatabaseConfigLoader implements DatabaseConfigLoaderInterface { |
|
61 | 60 | /** |
62 | 61 | * The Repository instance |
63 | 62 | * @var ConfigurationRepositoryInterface<Configuration> |
@@ -69,8 +68,7 @@ discard block |
||
69 | 68 | * Create new instance |
70 | 69 | * @param ConfigurationRepositoryInterface<Configuration> $repository |
71 | 70 | */ |
72 | - public function __construct(ConfigurationRepositoryInterface $repository) |
|
73 | - { |
|
71 | + public function __construct(ConfigurationRepositoryInterface $repository) { |
|
74 | 72 | $this->repository = $repository; |
75 | 73 | } |
76 | 74 | |
@@ -93,8 +91,7 @@ discard block |
||
93 | 91 | /** |
94 | 92 | * {@inheritdoc} |
95 | 93 | */ |
96 | - public function insertConfig(array $data) |
|
97 | - { |
|
94 | + public function insertConfig(array $data) { |
|
98 | 95 | $entity = $this->repository->create($data); |
99 | 96 | return $this->repository->insert($entity); |
100 | 97 | } |
@@ -128,7 +125,7 @@ discard block |
||
128 | 125 | ->query() |
129 | 126 | ->where('module')->is($group) |
130 | 127 | ->where('status')->is('Y') |
131 | - ->where(function (WhereStatement $where) use ($env) { |
|
128 | + ->where(function (WhereStatement $where) use ($env) { |
|
132 | 129 | $where->where('env')->is($env) |
133 | 130 | ->orWhere('env')->isNull(); |
134 | 131 | }); |
@@ -138,10 +135,10 @@ discard block |
||
138 | 135 | $results = $query->all(); |
139 | 136 | |
140 | 137 | $items = []; |
141 | - foreach ($results as $result) { |
|
138 | + foreach ($results as $result) { |
|
142 | 139 | /** @var string $name */ |
143 | 140 | $name = $result->name; |
144 | - if (!empty($name)) { |
|
141 | + if (!empty($name)) { |
|
145 | 142 | $items[$name] = ConfigUtil::convertToDataType( |
146 | 143 | $result->value, |
147 | 144 | (string) $result->type |
@@ -71,19 +71,19 @@ |
||
71 | 71 | 'updated_at' => '?date', |
72 | 72 | ]); |
73 | 73 | |
74 | - $mapper->filter('status', function (Query $q, $value) { |
|
74 | + $mapper->filter('status', function(Query $q, $value) { |
|
75 | 75 | $q->where('status')->is($value); |
76 | 76 | }); |
77 | 77 | |
78 | - $mapper->filter('env', function (Query $q, $value) { |
|
78 | + $mapper->filter('env', function(Query $q, $value) { |
|
79 | 79 | $q->where('env')->is($value); |
80 | 80 | }); |
81 | 81 | |
82 | - $mapper->filter('module', function (Query $q, $value) { |
|
82 | + $mapper->filter('module', function(Query $q, $value) { |
|
83 | 83 | $q->where('module')->is($value); |
84 | 84 | }); |
85 | 85 | |
86 | - $mapper->filter('type', function (Query $q, $value) { |
|
86 | + $mapper->filter('type', function(Query $q, $value) { |
|
87 | 87 | $q->where('type')->is($value); |
88 | 88 | }); |
89 | 89 | } |
@@ -56,8 +56,7 @@ discard block |
||
56 | 56 | * @package Platine\Framework\Config\Model |
57 | 57 | * @extends Entity<Configuration> |
58 | 58 | */ |
59 | -class Configuration extends Entity |
|
60 | -{ |
|
59 | +class Configuration extends Entity { |
|
61 | 60 | /** |
62 | 61 | * |
63 | 62 | * @param EntityMapperInterface<Configuration> $mapper |
@@ -71,19 +70,19 @@ discard block |
||
71 | 70 | 'updated_at' => '?date', |
72 | 71 | ]); |
73 | 72 | |
74 | - $mapper->filter('status', function (Query $q, $value) { |
|
73 | + $mapper->filter('status', function (Query $q, $value) { |
|
75 | 74 | $q->where('status')->is($value); |
76 | 75 | }); |
77 | 76 | |
78 | - $mapper->filter('env', function (Query $q, $value) { |
|
77 | + $mapper->filter('env', function (Query $q, $value) { |
|
79 | 78 | $q->where('env')->is($value); |
80 | 79 | }); |
81 | 80 | |
82 | - $mapper->filter('module', function (Query $q, $value) { |
|
81 | + $mapper->filter('module', function (Query $q, $value) { |
|
83 | 82 | $q->where('module')->is($value); |
84 | 83 | }); |
85 | 84 | |
86 | - $mapper->filter('type', function (Query $q, $value) { |
|
85 | + $mapper->filter('type', function (Query $q, $value) { |
|
87 | 86 | $q->where('type')->is($value); |
88 | 87 | }); |
89 | 88 | } |
@@ -57,14 +57,12 @@ |
||
57 | 57 | * @extends Repository<Configuration> |
58 | 58 | * @implements ConfigurationRepositoryInterface<Configuration> |
59 | 59 | */ |
60 | -class ConfigurationRepository extends Repository implements ConfigurationRepositoryInterface |
|
61 | -{ |
|
60 | +class ConfigurationRepository extends Repository implements ConfigurationRepositoryInterface { |
|
62 | 61 | /** |
63 | 62 | * Create new instance |
64 | 63 | * @param EntityManager<Configuration> $manager |
65 | 64 | */ |
66 | - public function __construct(EntityManager $manager) |
|
67 | - { |
|
65 | + public function __construct(EntityManager $manager) { |
|
68 | 66 | parent::__construct($manager, Configuration::class); |
69 | 67 | } |
70 | 68 | } |
@@ -51,17 +51,15 @@ discard block |
||
51 | 51 | * @class ConfigUtil |
52 | 52 | * @package Platine\Framework\Config |
53 | 53 | */ |
54 | -class ConfigUtil |
|
55 | -{ |
|
54 | +class ConfigUtil { |
|
56 | 55 | /** |
57 | 56 | * Convert the returned configuration to given type |
58 | 57 | * @param mixed $value |
59 | 58 | * @param string $type |
60 | 59 | * @return mixed |
61 | 60 | */ |
62 | - public static function convertToDataType($value, string $type) |
|
63 | - { |
|
64 | - switch ($type) { |
|
61 | + public static function convertToDataType($value, string $type) { |
|
62 | + switch ($type) { |
|
65 | 63 | case 'integer': |
66 | 64 | $value = intval($value); |
67 | 65 | break; |
@@ -91,15 +89,15 @@ discard block |
||
91 | 89 | */ |
92 | 90 | public static function isValueValideForDataType($value, string $type): bool |
93 | 91 | { |
94 | - if ($type === 'float' || $type === 'double') { |
|
92 | + if ($type === 'float' || $type === 'double') { |
|
95 | 93 | return (bool) filter_var($value, FILTER_VALIDATE_FLOAT); |
96 | 94 | } |
97 | 95 | |
98 | - if ($type === 'integer') { |
|
96 | + if ($type === 'integer') { |
|
99 | 97 | return (bool) filter_var($value, FILTER_VALIDATE_INT); |
100 | 98 | } |
101 | 99 | |
102 | - if ($type === 'boolean') { |
|
100 | + if ($type === 'boolean') { |
|
103 | 101 | return (bool) filter_var($value, FILTER_VALIDATE_BOOLEAN); |
104 | 102 | } |
105 | 103 |
@@ -55,6 +55,5 @@ |
||
55 | 55 | * @template TDbConfigurationEntity as \Platine\Orm\Entity |
56 | 56 | * @extends RepositoryInterface<TDbConfigurationEntity> |
57 | 57 | */ |
58 | -interface ConfigurationRepositoryInterface extends RepositoryInterface |
|
59 | -{ |
|
58 | +interface ConfigurationRepositoryInterface extends RepositoryInterface { |
|
60 | 59 | } |
@@ -55,8 +55,7 @@ |
||
55 | 55 | * @package Platine\Framework\Config |
56 | 56 | * @template TDbConfigurationEntity as Entity |
57 | 57 | */ |
58 | -interface DatabaseConfigLoaderInterface extends LoaderInterface |
|
59 | -{ |
|
58 | +interface DatabaseConfigLoaderInterface extends LoaderInterface { |
|
60 | 59 | /** |
61 | 60 | * Load the configuration from database |
62 | 61 | * @param array<string, mixed> $where |