Skip to content

Commit

Permalink
Merge pull request #13 from koriym/refactor
Browse files Browse the repository at this point in the history
Refactor to be enable to get RouterContainer
  • Loading branch information
koriym committed Sep 10, 2018
2 parents c4d22b4 + 001fa5b commit 1825c45
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 123 deletions.
4 changes: 2 additions & 2 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ return \PhpCsFixer\Config::create()
'header_comment' => ['header' => $header, 'commentType' => 'PHPDoc', 'separate' => 'none'],
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => false],
'blank_line_after_opening_tag' => true,
'blank_line_after_opening_tag' => false,
'blank_line_after_namespace' => false,
'blank_line_before_return' => true,
'cast_spaces' => true,
Expand All @@ -31,7 +31,7 @@ return \PhpCsFixer\Config::create()
'include' => true,
'indentation_type' => true,
'is_null' => ['use_yoda_style' => false],
'linebreak_after_opening_tag' => true,
'linebreak_after_opening_tag' => false,
'lowercase_cast' => true,
// 'mb_str_functions' => true,
'method_separation' => true,
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ before_script:
- composer self-update
- composer update $DEPENDENCIES
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then COVERAGE="--coverage-clover=coverage.clover"; else phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then composer require --dev phpstan/phpstan-shim friendsofphp/php-cs-fixer; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then composer require --dev phpstan/phpstan-shim ^0.9 friendsofphp/php-cs-fixer; fi
script:
- ./vendor/bin/phpunit $COVERAGE;
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then vendor/bin/php-cs-fixer fix --verbose --diff --dry-run --config=.php_cs; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then vendor/bin/phpstan analyse -l 2 -c phpstan.neon src tests --no-progress --no-interaction; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction; fi
after_script:
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"require-dev": {
"phpunit/phpunit": "^6.5",
"bear/package": "^1.5"
"bear/package": "^1.8"
},
"autoload": {
"psr-4": {
Expand All @@ -34,7 +34,7 @@
},
"scripts": {
"test": ["phpunit"],
"tests": ["@cs", "phpmd src,tests text ./phpmd.xml", "phpstan analyse -l 4 src tests -c phpstan.neon --no-progress", "@test"],
"tests": ["@cs", "phpmd src,tests text ./phpmd.xml", "phpstan analyse -l max src tests -c phpstan.neon --no-progress", "@test"],
"coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=phpcs.xml src;"],
"cs-fix": ["php-cs-fixer fix -v", "phpcbf src tests"]
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
parameters:
ignoreErrors:
- '#Undefined variable#'
- '#Method BEAR\\Package\\Provide\\Router\\AuraRouter::match\(\) should return BEAR\\Sunday\\Extension\\Router\\RouterMatch but returns false.#'
- '#expects bool, BEAR\\Sunday\\Extension\\Router\\RouterMatch#'
- '#Parameter \#1 \$condition of method PHPUnit\\Framework\\Assert::assertFalse\(\)#'
24 changes: 7 additions & 17 deletions src/Provide/Router/AuraRouter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the BEAR.AuraRouterModule package.
*
Expand All @@ -7,7 +7,6 @@
namespace BEAR\Package\Provide\Router;

use Aura\Router\Exception\RouteNotFound;
use Aura\Router\Map;
use Aura\Router\Route;
use Aura\Router\RouterContainer;
use BEAR\Sunday\Annotation\DefaultSchemeHost;
Expand Down Expand Up @@ -49,30 +48,21 @@ class AuraRouter implements RouterInterface
private $routerContainer;

/**
* @var string
*/
private $routerFile;

/**
* @DefaultSchemeHost("schemeHost")
* @Named("routerFile=aura_router_file")
*/
public function __construct(RouterContainer $routerContainer, string $schemeHost, HttpMethodParamsInterface $httpMethodParams, string $routerFile)
public function __construct(RouterContainer $routerContainer, HttpMethodParamsInterface $httpMethodParams)
{
$this->routerContainer = $routerContainer;
$this->matcher = $routerContainer->getMatcher();
$this->schemeHost = $schemeHost;
$this->httpMethodParams = $httpMethodParams;
$this->routerFile = $routerFile;
}

public function __wakeup()
/**
* @DefaultSchemeHost("schemeHost")
*/
public function setSchemaHost(string $schemeHost)
{
$this->routerContainer = new RouterContainer;
/* @global Map $map */
$map = $this->routerContainer->getMap();

require $this->routerFile;
$this->schemeHost = $schemeHost;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/Provide/Router/AuraRouterModule.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the BEAR.AuraRouterModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace BEAR\Package\Provide\Router;

use Aura\Router\Map;
use Aura\Router\RouterContainer;
use BEAR\Sunday\Extension\Router\RouterInterface;
use Ray\Di\AbstractModule;
Expand All @@ -19,19 +18,21 @@ class AuraRouterModule extends AbstractModule
*/
private $routerFile;

public function __construct($routerFile = null, AbstractModule $module = null)
/**
* @param string $routerFile Router file path
* @param AbstractModule|null $module
*/
public function __construct(string $routerFile = '', AbstractModule $module = null)
{
$this->routerFile = $routerFile;
parent::__construct($module);
}

protected function configure()
{
$this->bind(RouterContainer::class)->in(Scope::SINGLETON);
$this->bind()->annotatedWith('aura_router_file')->toInstance($this->routerFile);
$this->bind(Map::class)->annotatedWith('aura_map')->to(Map::class);
$this->bind(Map::class)->in(Scope::SINGLETON);
$this->bind(RouterInterface::class)->annotatedWith('primary_router')->toProvider(AuraRouterProvider::class);
$this->bind(RouterInterface::class)->toProvider(RouterCollectionProvider::class)->in(Scope::SINGLETON);
$this->bind(RouterContainer::class)->toProvider(RouterContainerProvider::class)->in(Scope::SINGLETON);
$this->bind(RouterInterface::class)->annotatedWith('primary_router')->to(AuraRouter::class);
}
}
74 changes: 0 additions & 74 deletions src/Provide/Router/AuraRouterProvider.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the BEAR.AuraRouterModule package.
*
Expand Down
59 changes: 59 additions & 0 deletions src/Provide/Router/RouterContainerProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types=1);
/**
* This file is part of the BEAR.AuraRouterModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace BEAR\Package\Provide\Router;

use Aura\Router\RouterContainer;
use BEAR\AppMeta\AbstractAppMeta;
use BEAR\Package\Provide\Router\Exception\InvalidRouterFilePathException;
use BEAR\Sunday\Annotation\DefaultSchemeHost;
use Ray\Di\Di\Inject;
use Ray\Di\Di\Named;
use Ray\Di\ProviderInterface;

class RouterContainerProvider implements ProviderInterface
{
/**
* @var string
*/
private $schemeHost;

/**
* @var RouterContainer
*/
private $routerContainer;

/**
* @DefaultSchemeHost("schemeHost")
*/
public function __construct(string $schemeHost)
{
$this->schemeHost = $schemeHost;
}

/**
* @Inject
* @Named("routerFile=aura_router_file")
*/
public function setRouterContainer(AbstractAppMeta $appMeta, string $routerFile = '')
{
$this->routerContainer = new RouterContainer;
$routerFile = ($routerFile === '') ? $appMeta->appDir . '/var/conf/aura.route.php' : $routerFile;
$map = $this->routerContainer->getMap();
if (! \file_exists($routerFile)) {
throw new InvalidRouterFilePathException($routerFile);
}
include_once $routerFile;
}

/**
* {@inheritdoc}
*/
public function get()
{
return $this->routerContainer;
}
}
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Module/App.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Module;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Module/AppModule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Module;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Module/ProdModule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Module;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/App/One.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\App;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/App/Scalar.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\App;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/App/Sub/Sub/Four.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\App\Sub\Sub;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/App/Sub/Three.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\App\Sub;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/App/Two.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\App;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/App/User.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\App;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/Page/Emb.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\Page;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/src/Resource/Page/Index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace FakeVendor\HelloWorld\Resource\Page;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/fake-app/var/conf/aura.route.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

/* @var $map \Aura\Router\Map */

Expand Down
4 changes: 2 additions & 2 deletions tests/Provide/Router/AuraRouterModuleTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the BEAR.AuraRouterModule package.
*
Expand All @@ -20,7 +20,7 @@ class AuraRouterModuleTest extends TestCase

public function testGetInstance()
{
$module = (new AuraRouterModule(null, new AppModule));
$module = (new AuraRouterModule('', new AppModule));
$module->install(new AppMetaModule(new AppMeta('FakeVendor\HelloWorld')));
$injector = new Injector($module);
$auraRouter = $injector->getInstance(RouterInterface::class, 'primary_router');
Expand Down
4 changes: 2 additions & 2 deletions tests/Provide/Router/AuraRouterTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the BEAR.AuraRouterModule package.
*
Expand Down Expand Up @@ -30,7 +30,7 @@ public function setUp()
$this->map = $map;
$routerFile = \dirname(__DIR__, 2) . '/Fake/fake-app/var/conf/aura.route.php';
require $routerFile;
$this->auraRouter = new AuraRouter($routerContainer, 'page://self', new HttpMethodParams, $routerFile);
$this->auraRouter = new AuraRouter($routerContainer, new HttpMethodParams);
}

public function testMatch()
Expand Down
2 changes: 1 addition & 1 deletion tests/Provide/Router/aura.route.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* This file is part of the BEAR.AuraRouterModule package.
*
Expand Down
Loading

0 comments on commit 1825c45

Please sign in to comment.