Skip to content

Commit 018d3e7

Browse files
author
Dome
committed
[TASK] Adjusted routing and added custom config
1 parent cba6b2d commit 018d3e7

33 files changed

+157
-297
lines changed

src/Config.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework;
94

@@ -35,8 +30,7 @@ class Config implements ConfigInterface, ArrayAccess, IteratorAggregate
3530
* @param mixed $context Raw array of configuration options or path to a
3631
* configuration file or directory containing one or
3732
* more configuration files
38-
* @param string|null $prefix A key under which the loaded config will be nested
39-
* @throws InvalidContextException
33+
* @param string $prefix A key under which the loaded config will be nested
4034
*/
4135
public function __construct($context = null, string $prefix = null)
4236
{
@@ -61,7 +55,7 @@ public function __construct($context = null, string $prefix = null)
6155
*
6256
* @param string $path A path to a directory of configuration files
6357
*
64-
* @return ConfigInterface A new ConfigInterface object
58+
* @return \Ares\Framework\Interfaces\ConfigInterface A new ConfigInterface object
6559
*/
6660
public static function fromDirectory(string $path): ConfigInterface
6761
{
@@ -87,7 +81,7 @@ public static function fromDirectory(string $path): ConfigInterface
8781
*
8882
* @return bool True on success, otherwise false
8983
*/
90-
public function set(string $key, mixed $value): bool
84+
public function set(string $key, $value): bool
9185
{
9286
$config = &$this->config;
9387

@@ -104,11 +98,11 @@ public function set(string $key, mixed $value): bool
10498
* Retrieve a configuration option via a provided key.
10599
*
106100
* @param string $key Unique configuration option key
107-
* @param mixed|null $default Default value to return if option does not exist
101+
* @param mixed $default Default value to return if option does not exist
108102
*
109103
* @return mixed Stored config item or $default value
110104
*/
111-
public function get(string $key, mixed $default = null): mixed
105+
public function get(string $key, $default = null)
112106
{
113107
$config = $this->config;
114108

@@ -149,11 +143,11 @@ public function has(string $key): bool
149143
* @param string $key Unique configuration option key
150144
* @param mixed $value Config item value
151145
*
152-
* @return true
153-
*@throws RuntimeException
146+
* @throws RuntimeException
154147
*
148+
* @return true
155149
*/
156-
public function append(string $key, mixed $value): bool
150+
public function append(string $key, $value): bool
157151
{
158152
$config = &$this->config;
159153

@@ -176,11 +170,11 @@ public function append(string $key, mixed $value): bool
176170
* @param string $key Unique configuration option key
177171
* @param mixed $value Config item value
178172
*
179-
* @return true
180-
*@throws RuntimeException
173+
* @throws RuntimeException
181174
*
175+
* @return true
182176
*/
183-
public function prepend(string $key, mixed $value): bool
177+
public function prepend(string $key, $value): bool
184178
{
185179
$config = &$this->config;
186180

@@ -217,11 +211,11 @@ public function unset(string $key): bool
217211
* Load configuration options from a file or directory.
218212
*
219213
* @param string $path Path to configuration file or directory
220-
* @param string|null $prefix A key under which the loaded config will be nested
214+
* @param string $prefix A key under which the loaded config will be nested
221215
* @param bool $override Whether or not to override existing options with
222216
* values from the loaded file
223217
*
224-
* @return ConfigInterface This Config object
218+
* @return \Ares\Framework\Interfaces\ConfigInterface This Config object
225219
*/
226220
public function load(string $path, string $prefix = null, bool $override = true): ConfigInterface
227221
{
@@ -246,11 +240,11 @@ public function load(string $path, string $prefix = null, bool $override = true)
246240
/**
247241
* Merge another Config object into this one.
248242
*
249-
* @param ConfigInterface $config Instance of Config
243+
* @param \Ares\Framework\Interfaces\ConfigInterface $config Instance of Config
250244
* @param bool $override Whether or not to override existing options with
251245
* values from the merged config object
252246
*
253-
* @return ConfigInterface This Config object
247+
* @return \Ares\Framework\Interfaces\ConfigInterface This Config object
254248
*/
255249
public function merge(ConfigInterface $config, bool $override = true): ConfigInterface
256250
{
@@ -268,8 +262,7 @@ public function merge(ConfigInterface $config, bool $override = true): ConfigInt
268262
*
269263
* @param string $key Unique configuration option key
270264
*
271-
* @return ConfigInterface A new ConfigInterface object
272-
* @throws InvalidContextException
265+
* @return \Ares\Framework\Interfaces\ConfigInterface A new ConfigInterface object
273266
*/
274267
public function split(string $key): ConfigInterface
275268
{

src/Configuration.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php declare(strict_types=1);
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework;
94

@@ -22,23 +17,23 @@ class Configuration
2217
/**
2318
* Routing sources.
2419
*
25-
* @var array
20+
* @var mixed[]
2621
*/
27-
protected array $sources = [];
22+
protected $sources = [];
2823

2924
/**
3025
* Routes with trailing slash.
3126
*
3227
* @var bool
3328
*/
34-
protected bool $trailingSlash = false;
29+
protected $trailingSlash = false;
3530

3631
/**
3732
* Placeholder aliases.
3833
*
3934
* @var array<string, string>
4035
*/
41-
protected array $placeholderAliases = [
36+
protected $placeholderAliases = [
4237
'any' => '[^}]+',
4338
'numeric' => '[0-9]+',
4439
'number' => '[0-9]+',
@@ -55,21 +50,21 @@ class Configuration
5550
*
5651
* @var MetadataResolver
5752
*/
58-
protected MetadataResolver $metadataResolver;
53+
protected $metadataResolver;
5954

6055
/**
6156
* Route resolver.
6257
*
6358
* @var RouteResolver
6459
*/
65-
protected RouteResolver $routeResolver;
60+
protected $routeResolver;
6661

6762
/**
6863
* Naming strategy.
6964
*
7065
* @var Strategy
7166
*/
72-
protected Strategy $namingStrategy;
67+
protected $namingStrategy;
7368

7469
/**
7570
* Configuration constructor.
@@ -78,7 +73,7 @@ class Configuration
7873
*
7974
* @throws \InvalidArgumentException
8075
*/
81-
public function __construct(mixed $configurations = [])
76+
public function __construct($configurations = [])
8277
{
8378
if (!\is_array($configurations) && !$configurations instanceof \Traversable) {
8479
throw new \InvalidArgumentException('Configurations must be an iterable');
@@ -116,7 +111,7 @@ public function __construct(mixed $configurations = [])
116111
/**
117112
* Get routing paths.
118113
*
119-
* @return array
114+
* @return mixed[]
120115
*/
121116
public function getSources(): array
122117
{
@@ -126,7 +121,7 @@ public function getSources(): array
126121
/**
127122
* Set routing paths.
128123
*
129-
* @param array $sources
124+
* @param mixed[] $sources
130125
*
131126
* @return self
132127
*/
@@ -150,7 +145,7 @@ public function setSources(array $sources): self
150145
*
151146
* @return self
152147
*/
153-
public function addSource(mixed $source): self
148+
public function addSource($source): self
154149
{
155150
if (!\is_string($source) && !\is_array($source) && !$source instanceof DriverInterface) {
156151
throw new \InvalidArgumentException(\sprintf(

src/Loader/Directory.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework\Loader;
94

@@ -17,7 +12,7 @@ class Directory extends Loader
1712
* and convert them to an array of configuration options. Any invalid files
1813
* will be silently ignored.
1914
*
20-
* @throws InvalidFileException
15+
* @throws \Ares\Framework\Exception\InvalidFileException
2116
*
2217
* @return array Array of configuration options
2318
*/
@@ -37,8 +32,8 @@ public function getArray(): array
3732

3833
try {
3934
$contents = array_merge($contents, $loader->getArray());
40-
} catch (InvalidFileException) {
41-
continue;
35+
} catch (InvalidFileException $e) {
36+
// Ignore it and continue
4237
}
4338
}
4439

src/Loader/Ini.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework\Loader;
94

@@ -15,15 +10,15 @@ class Ini extends Loader
1510
* Retrieve the contents of a .ini file and convert it to an array of
1611
* configuration options.
1712
*
18-
* @throws InvalidFileException
13+
* @throws \Ares\Framework\Exception\InvalidFileException
1914
*
2015
* @return array Array of configuration options
2116
*/
2217
public function getArray(): array
2318
{
2419
$parsed = @parse_ini_file($this->context, true);
2520

26-
if (!$parsed) {
21+
if (! $parsed) {
2722
throw new InvalidFileException('Unable to parse invalid INI file at ' . $this->context);
2823
}
2924

src/Loader/Json.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework\Loader;
94

@@ -15,7 +10,7 @@ class Json extends Loader
1510
* Retrieve the contents of a .json file and convert it to an array of
1611
* configuration options.
1712
*
18-
* @throws InvalidFileException
13+
* @throws \Ares\Framework\Exception\InvalidFileException
1914
*
2015
* @return array Array of configuration options
2116
*/

src/Loader/Loader.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework\Loader;
94

105
use Ares\Framework\Interfaces\Loadable;
116

127
abstract class Loader implements Loadable
138
{
9+
/** @var string Path to a configuration file or directory */
10+
protected $context;
11+
1412
/**
1513
* Create a new Loader object.
1614
*
1715
* @param string $context Path to configuration file or directory
1816
*/
19-
public function __construct(
20-
protected string $context
21-
) {}
17+
public function __construct(string $context)
18+
{
19+
$this->context = $context;
20+
}
2221

2322
/**
2423
* Retrieve the context as an array of configuration options.

src/Loader/Php.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework\Loader;
94

@@ -15,7 +10,7 @@ class Php extends Loader
1510
* Retrieve the contents of a .php configuration file and convert it to an
1611
* array of configuration options.
1712
*
18-
* @throws InvalidFileException
13+
* @throws \Ares\Framework\Exception\InvalidFileException
1914
*
2015
* @return array Array of configuration options
2116
*/

src/Loader/Toml.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework\Loader;
94

@@ -17,7 +12,7 @@ class Toml extends Loader
1712
* Retrieve the contents of a .toml file and convert it to an array of
1813
* configuration options.
1914
*
20-
* @throws InvalidFileException
15+
* @throws \Ares\Framework\Exception\InvalidFileException
2116
*
2217
* @return array Array of configuration options
2318
*/

src/Loader/Xml.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* @copyright Copyright (c) Ares (https://www.ares.to)
4-
*
5-
* @see LICENSE (MIT)
6-
*/
72

83
namespace Ares\Framework\Loader;
94

@@ -15,7 +10,7 @@ class Xml extends Loader
1510
* Retrieve the contents of a .json file and convert it to an array of
1611
* configuration options.
1712
*
18-
* @throws InvalidFileException
13+
* @throws \Ares\Framework\Exception\InvalidFileException
1914
*
2015
* @return array Array of configuration options
2116
*/

0 commit comments

Comments
 (0)