Skip to content

Commit

Permalink
Adding php 7.4 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
incraigulous committed May 15, 2024
1 parent 35d019a commit 1b4a5ce
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 225 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"platform": {
"php": "7.4"
},
"platform-check": false
}
}
288 changes: 151 additions & 137 deletions composer.lock

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true">
<testsuites>
<testsuite name="Unit">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="tests/bootstrap.php" colors="true">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Factories/ConditionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(Container $container)
* @return Condition The newly created condition object or collection of condition objects.
* @throws BindingResolutionException
*/
public function make(mixed $value = null, iterable $options = []): Condition
public function make($value = null, iterable $options = []): Condition
{
if (! $value) {
return new CallbackCondition(function () {
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/Conditions/HasCapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(Container $container)
*
* @return Condition
*/
public function make(mixed $value = null, iterable $options = []): Condition
public function make($value = null, iterable $options = []): Condition
{
if ($value instanceof Condition) {
return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/DispatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DispatcherFactory implements Factory
*
* @return BaseDispatcher An instance of the base dispatcher.
*/
public function make(mixed $value = null, $options = []): BaseDispatcher
public function make($value = null, $options = []): BaseDispatcher
{
return simpleDispatcher($value, array_merge($options, [
'routeCollector' => Routes::class,
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface Factory
{
public function make(mixed $value = null, iterable $options = []);
public function make($value = null, iterable $options = []);
}
2 changes: 1 addition & 1 deletion src/Factories/Middleware/UserHasCapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(Container $container)
*
* @return Middleware
*/
public function make(mixed $value = null, iterable $options = [])
public function make($value = null, iterable $options = [])
{
if ($value instanceof Middleware) {
return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/RedirectResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(Container $container)
$this->container = $container;
}

public function make(mixed $value = null, iterable $options = []): RedirectResponse
public function make($value = null, iterable $options = []): RedirectResponse
{
$status = $options['status'] ?? 302;
$headers = $options['headers'] ?? [];
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Container $container)
* @return Response
* @throws BindingResolutionException
*/
public function make(mixed $value = null, iterable $options = []): BaseResponse
public function make($value = null, iterable $options = []): BaseResponse
{
$response = $options['response'] ?? null;

Expand Down
3 changes: 2 additions & 1 deletion src/FastRoute/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CodeZone\Router\FastRoute;

use Closure;
use CodeZone\Router\Controllers\CallbackController;
use CodeZone\Router\Factories\ConditionFactory;
use FastRoute\RouteCollector;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected function normalizeHandler( $httpMethod, $route, $handler ): array {
$handler = explode( '@', $handler, 2 );
}

if ( is_callable( $handler ) ) {
if ( $handler instanceof Closure ) {
$handler = [ CallbackController::class, 'handle', [ 'handler' => $handler ] ];
}

Expand Down
16 changes: 6 additions & 10 deletions src/Middleware/DispatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,13 @@ public function handle(Request $request, Response $response, $next)
}
}

//Call the controller method
$parameters = array_merge($vars, $config);
$parameters = array_merge($parameters, ['request' => $request, 'response' => $response]);
$controller = container()->make($class);
$action = container()->call([$controller, $method], $parameters);
$response = $this->response_factory->make(
container()->call([ container()->make($class), $method ], [
...$vars,
...$config,
$request,
$response,
]),
[
'response' => $response_before_controller
]
$action,
['response' => $response_before_controller]
);

return $next($request, $response);
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/UserHasCap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UserHasCap implements Middleware
* The variable that holds the URL to redirect to.
* It can either be a string representing a valid URL or null if no redirection is needed.
*/
protected mixed $redirect_to;
protected $redirect_to;

/**
* __construct method.
Expand Down
104 changes: 52 additions & 52 deletions tests/DispatchMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,58 @@
use Illuminate\Http\Response;
use function CodeZone\Router\container;

class DispatchMiddlewareTest extends TestCase {
use HasRouter;
class DispatchMiddlewareTest extends TestCase
{
use HasRouter;

/**
* @test
*/
public function it_dispatches_responses () {
$this->router();
$request = container()->make(Request::class);
$response = container()->make(Response::class);
$request->routes = $this->router()->routes(function($router) {
$router->get('/', [Controller::class, 'request']);
})->dispatch('GET', '/');
$middleware = container()->make(DispatchController::class);
$middleware->handle($request, $response, function ($request, $response) {
$this->assertStringContainsString('Hello', $response->getContent());
});
}
/**
* @test
*/
public function it_dispatches_responses()
{
$this->router();
$request = container()->make(Request::class);
$response = container()->make(Response::class);
$request->routes = $this->router()->routes(function ($router) {
$router->get('/', [Controller::class, 'request']);
})->dispatch('GET', '/');
$middleware = container()->make(DispatchController::class);
$middleware->handle($request, $response, function ($request, $response) {
$this->assertStringContainsString('Hello', $response->getContent());
});
}

/**
* @test
*/
public function it_dispatches_responses_with_params () {
$this->router();
$request = container()->make(Request::class);
$response = container()->make(Response::class);
$request->routes = $this->router()->routes(function($router) {
$router->get('/{param}', [Controller::class, 'withParam']);
})->dispatch('GET', '/hello');
$middleware = container()->make(DispatchController::class);
$middleware->handle($request, $response, function ($request, $response) {
$this->assertStringContainsString('hello', $response->getContent());
});
}
/**
* @test
*/
public function it_dispatches_responses_with_params()
{
$this->router();
$request = container()->make(Request::class);
$response = container()->make(Response::class);
$request->routes = $this->router()->routes(function ($router) {
$router->get('/{param}', [Controller::class, 'withParam']);
})->dispatch('GET', '/hello');
$middleware = container()->make(DispatchController::class);
$middleware->handle($request, $response, function ($request, $response) {
$this->assertStringContainsString('hello', $response->getContent());
});
}

/**
* @test
*/
public function it_dispatches_strings () {
$this->router();
$request = container()->make(Request::class);
$response = container()->make(Response::class);
$request->routes = $this->router()->routes(function($router) {
$router->get('/', [Controller::class, 'returnsString']);
})->dispatch('GET', '/');
$middleware = container()->make(DispatchController::class);
$middleware->handle($request, $response, function ($request, $response) {
$this->assertStringContainsString('Hello', $response->getContent());
});
}




}
/**
* @test
*/
public function it_dispatches_strings()
{
$this->router();
$request = container()->make(Request::class);
$response = container()->make(Response::class);
$request->routes = $this->router()->routes(function ($router) {
$router->get('/', [Controller::class, 'returnsString']);
})->dispatch('GET', '/');
$middleware = container()->make(DispatchController::class);
$middleware->handle($request, $response, function ($request, $response) {
$this->assertStringContainsString('Hello', $response->getContent());
});
}
}

0 comments on commit 1b4a5ce

Please sign in to comment.