Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 41 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,44 @@ name: CI
on: [push, pull_request]

jobs:
build-test:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.1, 8.2, 8.3]
composer_flags: ['', '--prefer-lowest']

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: xdebug

- name: Install dependencies
uses: php-actions/composer@v5
with:
php_version: ${{ matrix.php_version }}
args: ${{ matrix.composer_flags }}
command: update

- name: Run tests
run: ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml
env:
XDEBUG_MODE: coverage

- name: Run Codesniffer
run: vendor/bin/phpcs --standard=PSR2 ./src

# - name: Submit coverage to Coveralls
# # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports:
# # https://github.com/coverallsapp/github-action/issues/15
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# COVERALLS_PARALLEL: true
# COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }}
# run: |
# composer global require php-coveralls/php-coveralls
# ~/.composer/vendor/bin/php-coveralls -v

build-test:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.1, 8.2, 8.3, 8.4]
composer_flags: ["", "--prefer-lowest"]

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: xdebug

- name: Install dependencies
uses: php-actions/composer@v5
with:
php_version: ${{ matrix.php_version }}
args: ${{ matrix.composer_flags }}
command: update

- name: Run tests
run: ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml
env:
XDEBUG_MODE: coverage

- name: Run Codesniffer
run: vendor/bin/phpcs --standard=PSR2 ./src

# - name: Submit coverage to Coveralls
# # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports:
# # https://github.com/coverallsapp/github-action/issues/15
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# COVERALLS_PARALLEL: true
# COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }}
# run: |
# composer global require php-coveralls/php-coveralls
# ~/.composer/vendor/bin/php-coveralls -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
composer.lock
/tests/Unit/logs
.phpunit.result.cache
52 changes: 31 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@
"license": "MIT",
"require": {
"php": ">=8.1",
"php-di/php-di": "^6.4.0",
"rareloop/router": "^6.0.2",
"psr/container": "^1.1.2",
"psr/http-message": "^1.1",
"php-di/php-di": "^7",
"rareloop/router": "dev-feature/upgrade-dependencies as 6.0.2",
"psr/container": "^2",
"psr/http-message": "^2",
"psr/http-server-middleware": "^1.0.2",
"blast/facades": "^1.0",
"timber/timber": "^2.3.0",
"monolog/monolog": "^2.9.1",
"http-interop/response-sender": "^1.0",
"symfony/debug": "^4.4.44",
"illuminate/collections": "^8.53.1||^9.52.16",
"monolog/monolog": "^3.9",
"illuminate/collections": "^12",
"statamic/stringy": "^3.1.3",
"laminas/laminas-diactoros": "^2.25.2",
"rareloop/psr7-server-request-extension": "^2.1.0",
"mmeyer2k/dcrypt": "^8.3.1",
"laminas/laminas-diactoros": "^3.6.0",
"rareloop/psr7-server-request-extension": "dev-master as 3.0",
"spatie/macroable": "^1.0.1",
"mindplay/middleman": "^3.1.0",
"psr/log": "^1.1.4",
"laminas/laminas-zendframework-bridge": "^1.7",
"symfony/var-dumper": "^5.0||^6.3.6"
"mindplay/middleman": "^4.0.4",
"psr/log": "^2.0.0",
"symfony/var-dumper": "^5.0||^6.3.6",
"illuminate/encryption": "^12.32",
"spatie/ignition": "^1.15",
"laminas/laminas-httphandlerrunner": "^2.12",
"symfony/error-handler": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.6.13",
"php-coveralls/php-coveralls": "^2.6",
"mockery/mockery": "^1.6.6",
"brain/monkey": "^2.6.1",
"squizlabs/php_codesniffer": "^3.7.2",
"php-mock/php-mock": "^2.4.1",
"mikey179/vfsstream": "1.6.11",
"dms/phpunit-arraysubset-asserts": "^0.3.1"
"php-mock/php-mock": "^2.6.2",
"mikey179/vfsstream": "^1.6.12",
"dms/phpunit-arraysubset-asserts": "^0.3.1",
"rector/rector": "^2.1"
},
"autoload": {
"psr-4": {
Expand All @@ -49,5 +49,15 @@
"allow-plugins": {
"composer/installers": true
}
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/rareloop/router"
},
{
"type": "vcs",
"url": "https://github.com/tommitchelmore/psr7-server-request-extension"
}
]
}
31 changes: 11 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Rareloop Router Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Rareloop Router Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
->withPhpSets(php84: true);
// ->withTypeCoverageLevel(0)
// ->withDeadCodeLevel(0)
// ->withCodeQualityLevel(0);
41 changes: 17 additions & 24 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace Rareloop\Lumberjack;

use Closure;
use DI\ContainerBuilder;
use DI\Container;
use Illuminate\Support\Collection;
use Interop\Container\ContainerInterface as InteropContainerInterface;
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Rareloop\Router\Invoker;
use function Http\Response\send;

class Application implements ContainerInterface, InteropContainerInterface
class Application implements ContainerInterface
{
private $container;
private $loadedProviders = [];
Expand All @@ -24,7 +23,7 @@ class Application implements ContainerInterface, InteropContainerInterface

public function __construct($basePath = false)
{
$this->container = ContainerBuilder::buildDevContainer();
$this->container = new Container();

$this->bind(Application::class, $this);

Expand Down Expand Up @@ -152,7 +151,7 @@ private function isSingletonClassBind($id)
*
* @return bool
*/
public function has($id)
public function has(string $id): bool
{
return $this->container->has($id);
}
Expand Down Expand Up @@ -182,11 +181,9 @@ public function register($provider)

public function getProvider($provider)
{
$providerClass = is_string($provider) ? $provider : get_class($provider);
$providerClass = is_string($provider) ? $provider : $provider::class;

return (new Collection($this->loadedProviders))->first(function ($provider) use ($providerClass) {
return get_class($provider) === $providerClass;
});
return (new Collection($this->loadedProviders))->first(fn($provider) => $provider::class === $providerClass);
}

public function getLoadedProviders()
Expand Down Expand Up @@ -234,7 +231,7 @@ public function bootstrapWith(array $bootstrappers)
*
* @return boolean
*/
public function hasRequestBeenHandled() : bool
public function hasRequestBeenHandled(): bool
{
return $this->requestHandled;
}
Expand Down Expand Up @@ -265,17 +262,17 @@ public function detectWhenRequestHasNotBeenHandled()
if ($this->has('__wp-controller-miss-template') && $this->has('__wp-controller-miss-controller')) {
wp_die(
'Loaded template <code>' .
$this->get('__wp-controller-miss-template') .
'</code> but couldn\'t find class <code>' .
$this->get('__wp-controller-miss-controller') .
'</code>'
$this->get('__wp-controller-miss-template') .
'</code> but couldn\'t find class <code>' .
$this->get('__wp-controller-miss-controller') .
'</code>'
);
}
}
});
}

public function shutdown(ResponseInterface $response = null)
public function shutdown(?ResponseInterface $response = null)
{
if ($response) {
global $wp;
Expand All @@ -284,13 +281,13 @@ public function shutdown(ResponseInterface $response = null)
// If we're handling a WordPressController response at this point then WordPress will already have
// sent headers as it happens earlier in the lifecycle. For this scenario we need to do a bit more
// work to make sure that duplicate headers are not sent back.
send($this->removeSentHeadersAndMoveIntoResponse($response));
(new SapiEmitter())->emit($this->removeSentHeadersAndMoveIntoResponse($response));
}

die();
}

protected function removeSentHeadersAndMoveIntoResponse(ResponseInterface $response) : ResponseInterface
protected function removeSentHeadersAndMoveIntoResponse(ResponseInterface $response): ResponseInterface
{
// 1. Format the previously sent headers into an array of [key, value]
// 2. Remove all headers from the output that we find
Expand All @@ -300,16 +297,12 @@ protected function removeSentHeadersAndMoveIntoResponse(ResponseInterface $respo
header_remove($parts[0]);

return $parts;
})->filter(function ($header) {
return !in_array(strtolower($header[0]), ['content-type']);
});
})->filter(fn($header) => !in_array(strtolower((string) $header[0]), ['content-type']));

// Add the previously sent headers into the response
// Note: You can't mutate a response so we need to use the reduce to end up with a response
// object with all the correct headers
$responseToSend = collect($headersToAdd)->reduce(function ($newResponse, $header) {
return $newResponse->withAddedHeader($header[0], $header[1]);
}, $response);
$responseToSend = collect($headersToAdd)->reduce(fn($newResponse, $header) => $newResponse->withAddedHeader($header[0], $header[1]), $response);

return $responseToSend;
}
Expand Down
Loading
Loading