diff options
author | Arnold Daniels <arnold@jasny.net> | 2016-11-03 23:12:33 +0100 |
---|---|---|
committer | Arnold Daniels <arnold@jasny.net> | 2016-11-03 23:12:33 +0100 |
commit | bd4cb77fbf04923fa31a08fdd1f33f2c0db87864 (patch) | |
tree | 846c5e559360e530d200d897f67b5af02f8795e5 /src/Router/Route.php | |
parent | c6bb6b4495804d0f546b5298ad1ac4d66898b351 (diff) | |
download | router-origin/fix-tests.zip router-origin/fix-tests.tar.gz router-origin/fix-tests.tar.bz2 |
Move route binding (used in Glob) to a traitorigin/fix-tests
Added tests for Route
Added missing @covers
Diffstat (limited to 'src/Router/Route.php')
-rw-r--r-- | src/Router/Route.php | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/Router/Route.php b/src/Router/Route.php index be5a052..d2158ea 100644 --- a/src/Router/Route.php +++ b/src/Router/Route.php @@ -10,27 +10,21 @@ class Route extends \stdClass /** * Class constructor * - * @param array $values + * @param array|stdClass $values */ - public function __construct(array $values) - { - foreach ($values as $key => $value) { - $this->$key = $value; - } - } - - /** - * Factory method - * - * @param array|\stdClass $values - * @return Route - */ - public static function create($values) + public function __construct($values) { if ($values instanceof \stdClass) { $values = get_object_vars($values); } - return new static($values); + if (!is_array($values)) { + $type = (is_object($values) ? get_class($values) . ' ' : '') . gettype($values); + throw new \InvalidArgumentException("Route values should be an array, not a $type"); + } + + foreach ($values as $key => $value) { + $this->$key = $value; + } } } |