Skip to content

Commit

Permalink
Updated copyrights to 2019, fixed a few bugs, re-added the router cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc André Audet committed Jun 6, 2019
1 parent c16c044 commit 6887da9
Show file tree
Hide file tree
Showing 35 changed files with 321 additions and 250 deletions.
36 changes: 17 additions & 19 deletions LICENSE.md
@@ -1,23 +1,21 @@
Copyright (c) 2010-2018 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
All rights reserved.
MIT License

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
Copyright (c) 2010-2019 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.

1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -8,7 +8,7 @@
"Cervo"
],
"homepage": "https://github.com/Nevraxe/Cervo",
"license": "BSD-2-Clause",
"license": "MIT",
"authors": [
{
"name": "Nevraxe inc.",
Expand All @@ -18,19 +18,19 @@
{
"name": "Marc André Audet",
"email": "maudet@nevraxe.com",
"homepage": "https://blog.manhim.net"
"homepage": "https://blog.maaudet.ca"
}
],
"support": {
"issues": "https://github.com/Nevraxe/Cervo/issues"
},
"require": {
"php": "^7.1",
"nikic/fast-route": "^1.2"
"nikic/fast-route": "^1.3",
"ext-json": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "@stable",
"phpmd/phpmd": "@stable"
"squizlabs/php_codesniffer": "@stable"
},
"autoload": {
"psr-4": {
Expand Down
62 changes: 0 additions & 62 deletions src/Autoloader.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Config/ArrayConfig.php
Expand Up @@ -3,12 +3,12 @@
/**
* This file is part of the Cervo package.
*
* Copyright (c) 2010-2018 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
* Copyright (c) 2010-2019 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
*
* @package Cervo
* @author Marc André Audet <maaudet@nevraxe.com>
* @copyright 2010 - 2018 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md BSD-2-Clauses
* @copyright 2010 - 2019 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md MIT
* @link https://github.com/Nevraxe/Cervo
* @since 5.0.0
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Config/BaseConfig.php
Expand Up @@ -3,12 +3,12 @@
/**
* This file is part of the Cervo package.
*
* Copyright (c) 2010-2018 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
* Copyright (c) 2010-2019 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
*
* @package Cervo
* @author Marc André Audet <maaudet@nevraxe.com>
* @copyright 2010 - 2018 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md BSD-2-Clauses
* @copyright 2010 - 2019 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md MIT
* @link https://github.com/Nevraxe/Cervo
* @since 5.0.0
*/
Expand Down Expand Up @@ -70,7 +70,7 @@ public function get(string $name)

foreach (explode('/', $name) as $key) {

if ($current[$key]) {
if (isset($current[$key])) {
$current = &$current[$key];
} else {
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/Config/JsonConfig.php
Expand Up @@ -3,12 +3,12 @@
/**
* This file is part of the Cervo package.
*
* Copyright (c) 2010-2018 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
* Copyright (c) 2010-2019 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
*
* @package Cervo
* @author Marc André Audet <maaudet@nevraxe.com>
* @copyright 2010 - 2018 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md BSD-2-Clauses
* @copyright 2010 - 2019 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md MIT
* @link https://github.com/Nevraxe/Cervo
* @since 5.0.0
*/
Expand Down
45 changes: 6 additions & 39 deletions src/Context.php
Expand Up @@ -3,12 +3,12 @@
/**
* This file is part of the Cervo package.
*
* Copyright (c) 2010-2018 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
* Copyright (c) 2010-2019 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
*
* @package Cervo
* @author Marc André Audet <maaudet@nevraxe.com>
* @copyright 2010 - 2018 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md BSD-2-Clauses
* @copyright 2010 - 2019 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md MIT
* @link https://github.com/Nevraxe/Cervo
* @since 5.0.0
*/
Expand All @@ -30,7 +30,6 @@
final class Context
{
private $config;
private $autoloader;
private $modulesManager;
private $singletons;

Expand All @@ -39,14 +38,13 @@ final class Context
*
* @param BaseConfig|null $config
*/
public function __construct(
?BaseConfig $config = null
) {
public function __construct(?BaseConfig $config = null) {

$this->config = $config ?? new BaseConfig();

$this->modulesManager = new ModulesManager();
$this->autoloader = new Autoloader($this);
$this->singletons = new Singletons($this);

}

/**
Expand All @@ -67,32 +65,6 @@ public function register(string $providerClass): self
return $this;
}

public function route(): self
{
/** @var Events $events */
$events = $this->getSingletons()->get(Events::class);

/** @var Router $router */
$router = $this->getSingletons()->get(Router::class);

foreach ($this->getModulesManager()->getAllModules() as [$vendor_name, $module_name, $path]) {
$events->loadPath($path);
$router->loadPath($path);
}

$events->fire('Cervo/System/Before');

$route = $router->dispatch();

$events->fire('Cervo/Route/Before');
(new ControllerReflection($this, $route))();
$events->fire('Cervo/Route/After');

$events->fire('Cervo/System/After');

return $this;
}

public function getConfig(): BaseConfig
{
return $this->config;
Expand All @@ -103,11 +75,6 @@ public function getModulesManager(): ModulesManager
return $this->modulesManager;
}

public function getAutoloader(): Autoloader
{
return $this->autoloader;
}

public function getSingletons(): Singletons
{
return $this->singletons;
Expand Down
47 changes: 35 additions & 12 deletions src/ControllerReflection.php
Expand Up @@ -3,12 +3,12 @@
/**
* This file is part of the Cervo package.
*
* Copyright (c) 2010-2018 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
* Copyright (c) 2010-2019 Nevraxe inc. & Marc André Audet <maudet@nevraxe.com>.
*
* @package Cervo
* @author Marc André Audet <maaudet@nevraxe.com>
* @copyright 2010 - 2018 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md BSD-2-Clauses
* @copyright 2010 - 2019 Nevraxe inc. & Marc André Audet
* @license See LICENSE.md MIT
* @link https://github.com/Nevraxe/Cervo
* @since 5.0.0
*/
Expand Down Expand Up @@ -52,15 +52,15 @@ public function __construct(Context $context, Route $route)
$this->route = $route;

try {

$reflection = new \ReflectionClass($this->route->getControllerClass());

foreach ($reflection->getConstructor()->getParameters() as $parameter) {
$this->parameters[] = $this->getParameterValue($parameter);
}

} catch (\ReflectionException $e) {
// TODO: Log
// The contructor isn't defined, so we ignore the exception and move on
return;
}

foreach ($reflection->getConstructor()->getParameters() as $parameter) {
$this->parameters[] = $this->getParameterValue($parameter);
}
}

Expand All @@ -72,7 +72,14 @@ public function __invoke(): void

private function getParameterValue(\ReflectionParameter $parameter)
{
if ($parameter->getClass() === null) {
try {
$class = $parameter->getClass();
} catch (\ReflectionException $e) {
// TODO: Log
return null;
}

if ($class === null) {

if ($parameter->isArray()) {

Expand All @@ -81,13 +88,29 @@ private function getParameterValue(\ReflectionParameter $parameter)
} elseif ($parameter->name == 'arguments') {
return $this->route->getArguments();
} else {
return $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : [];

try {
return $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : [];
} catch (\ReflectionException $e) {
// TODO: Log
return [];
}

}

} else {
return $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null;

try {
return $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null;
} catch (\ReflectionException $e) {
// TODO: Log
return null;
}

}

} elseif ($parameter->getClass()->name == Context::class) {
return $this->context;
} else {
return $this->context->getSingletons()->get($parameter->getClass()->name);
}
Expand Down

0 comments on commit 6887da9

Please sign in to comment.