-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0e60525
Showing
16 changed files
with
580 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/.github export-ignore | ||
/tests export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.php-cs-fixer.dist.php export-ignore | ||
/psalm.xml export-ignore | ||
|
||
*.php diff=php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[{*.yaml,*.yml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Plugin CI | ||
on: | ||
push: | ||
branches: [ 'master' ] | ||
pull_request: | ||
|
||
env: | ||
PHP_CS_FIXER_IGNORE_ENV: 1 | ||
XDEBUG_MODE: coverage | ||
|
||
jobs: | ||
tests: | ||
name: "Tests ${{ matrix.php-version }} deps ${{ matrix.dependency-versions }}" | ||
runs-on: ubuntu-22.04 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
# normal, highest, non-dev installs | ||
php-version: [ '8.2' ] | ||
dependency-versions: [ 'highest' ] | ||
include: | ||
# testing lowest PHP version with the lowest dependencies | ||
# - php-version: '8.2' | ||
# dependency-versions: 'lowest' | ||
|
||
# testing dev versions with the highest PHP | ||
- php-version: '8.2' | ||
dependency-versions: 'highest' | ||
|
||
steps: | ||
- name: "Checkout code" | ||
uses: "actions/checkout@v2" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
php-version: "${{ matrix.php-version }}" | ||
|
||
- name: "Composer install" | ||
uses: "ramsey/composer-install@v2" | ||
with: | ||
dependency-versions: "${{ matrix.dependency-versions }}" | ||
composer-options: "--prefer-dist --no-progress" | ||
|
||
- name: Run tests | ||
run: composer run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
vendor | ||
composer.lock | ||
.phpunit.result.cache | ||
.php-cs-fixer.cache | ||
test-coverage-report | ||
phpunit.xml | ||
.php-cs-fixer.php | ||
phpstan.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
if (!file_exists(__DIR__.'/src')) { | ||
exit(0); | ||
} | ||
|
||
$finder = (new PhpCsFixer\Finder()) | ||
->in(__DIR__.'/src') | ||
->in(__DIR__.'/tests') | ||
; | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRules(array( | ||
'@Symfony' => true, | ||
'@Symfony:risky' => true, | ||
'protected_to_private' => false, | ||
'semicolon_after_instruction' => false, | ||
'header_comment' => [ | ||
'header' => <<<EOF | ||
This file is part of the Micro framework package. | ||
(c) Stanislau Komar <[email protected]> | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
EOF | ||
] | ||
)) | ||
->setRiskyAllowed(true) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "micro/plugin-http-router-code", | ||
"description": "Micro Framework: Http route locator from other plugins by plugin interface", | ||
"license": "MIT", | ||
"type": "micro-plugin", | ||
"authors": [ | ||
{ | ||
"name": "Stanislau Komar", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"micro/http-core": "dev-master" | ||
}, | ||
"require-dev": { | ||
"ergebnis/composer-normalize": "^2.29", | ||
"friendsofphp/php-cs-fixer": "^3.13", | ||
"phpstan/phpstan": "^1.9", | ||
"phpunit/php-code-coverage": "^9.2", | ||
"phpunit/phpunit": "^9.5", | ||
"vimeo/psalm": "^5.2" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Micro\\Plugin\\Http\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Micro\\Plugin\\Http\\Test\\": "test/" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"ergebnis/composer-normalize": true | ||
} | ||
}, | ||
"scripts": { | ||
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text", | ||
"php-cs-fix": "./vendor/bin/php-cs-fixer fix --verbose --using-cache=no", | ||
"php-cs-try": "./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no", | ||
"phpstan": "./vendor/bin/phpstan analyze --no-progress", | ||
"phpunit": "./vendor/bin/phpunit", | ||
"psalm": "./vendor/bin/psalm --no-progress --show-info=true", | ||
"statics": [ | ||
"@phpstan", | ||
"@psalm" | ||
], | ||
"test": [ | ||
"@statics", | ||
"composer validate --strict", | ||
"composer normalize", | ||
"@coverage" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
parameters: | ||
level: 7 | ||
paths: | ||
- src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- https://phpunit.readthedocs.io/en/9.5/configuration.html#the-phpunit-element --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
backupGlobals="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1" force="true"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Unit tests"> | ||
<directory>test/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
<report> | ||
<html outputDirectory="test-coverage-report/" /> | ||
</report> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
errorLevel="2" | ||
resolveFromConfigFile="true" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" | ||
> | ||
<projectFiles> | ||
<directory name="src" /> | ||
<ignoreFiles> | ||
<directory name="vendor" /> | ||
</ignoreFiles> | ||
|
||
</projectFiles> | ||
|
||
<issueHandlers> | ||
|
||
<UnnecessaryVarAnnotation> | ||
<errorLevel type="suppress"> | ||
<file name="src/HttpRouterCodePlugin.php"/> | ||
</errorLevel> | ||
</UnnecessaryVarAnnotation> | ||
|
||
<MissingConstructor> | ||
<errorLevel type="suppress"> | ||
<file name="src/HttpRouterCodePlugin.php"/> | ||
</errorLevel> | ||
</MissingConstructor> | ||
|
||
<ImplementedReturnTypeMismatch> | ||
<errorLevel type="suppress"> | ||
<file name="src/HttpRouterCodePlugin.php"/> | ||
</errorLevel> | ||
</ImplementedReturnTypeMismatch> | ||
</issueHandlers> | ||
|
||
</psalm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Micro framework package. | ||
* | ||
* (c) Stanislau Komar <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Micro\Plugin\Http\Business\Locator; | ||
|
||
use Micro\Framework\Kernel\KernelInterface; | ||
use Micro\Plugin\Http\Facade\HttpFacadeInterface; | ||
use Micro\Plugin\Http\Plugin\RouteProviderPluginInterface; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
*/ | ||
readonly class RouteCodeLocator implements RouteLocatorInterface | ||
{ | ||
/** | ||
* @param KernelInterface $kernel | ||
*/ | ||
public function __construct( | ||
private KernelInterface $kernel | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function locate(): iterable | ||
{ | ||
$iterator = $this->kernel->plugins(RouteProviderPluginInterface::class); | ||
/** @var RouteProviderPluginInterface $plugin */ | ||
foreach ($iterator as $plugin) { | ||
foreach ($plugin->provideRoutes() as $route) { | ||
yield $route; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Micro framework package. | ||
* | ||
* (c) Stanislau Komar <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Micro\Plugin\Http; | ||
|
||
use Micro\Component\DependencyInjection\Container; | ||
use Micro\Framework\Kernel\KernelInterface; | ||
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface; | ||
use Micro\Framework\Kernel\Plugin\PluginDependedInterface; | ||
use Micro\Plugin\Http\Business\Locator\RouteCodeLocator; | ||
use Micro\Plugin\Http\Business\Locator\RouteLocatorInterface; | ||
use Micro\Plugin\Http\Plugin\HttpRouteLocatorPluginInterface; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
*/ | ||
readonly class HttpRouterCodePlugin implements HttpRouteLocatorPluginInterface, DependencyProviderInterface, PluginDependedInterface | ||
{ | ||
/** | ||
* @var Container | ||
* @phpstan-ignore-next-line | ||
*/ | ||
private Container $container; | ||
|
||
public function provideDependencies(Container $container): void | ||
{ | ||
// @phpstan-ignore-next-line | ||
$this->container = $container; | ||
} | ||
|
||
public function getLocatorType(): string | ||
{ | ||
return 'code'; | ||
} | ||
|
||
public function createLocator(): RouteLocatorInterface | ||
{ | ||
$kernel = $this->container->get(KernelInterface::class); | ||
// @phpstan-ignore-next-line | ||
return new RouteCodeLocator($kernel); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getDependedPlugins(): iterable | ||
{ | ||
return [ | ||
HttpCorePlugin::class, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Micro framework package. | ||
* | ||
* (c) Stanislau Komar <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Micro\Plugin\Http\Plugin; | ||
|
||
use Micro\Plugin\Http\Business\Route\RouteInterface; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
*/ | ||
interface RouteProviderPluginInterface | ||
{ | ||
/** | ||
* @return iterable<RouteInterface> | ||
*/ | ||
public function provideRoutes(): iterable; | ||
} |
Oops, something went wrong.