Skip to content

Commit

Permalink
Requires PHP 7.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Mar 18, 2018
1 parent 739fdab commit f34f5bf
Show file tree
Hide file tree
Showing 27 changed files with 223 additions and 304 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ cache:
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- nightly

before_script:
- if [[ $TRAVIS_PHP_VERSION != "5.6" ]]; then phpenv config-rm xdebug.ini; fi
matrix:
allow_failures:
- php: nightly

script:
- if [[ $TRAVIS_PHP_VERSION == "5.6" ]]; then make test-coveralls; else make test; fi
- if [[ $TRAVIS_PHP_VERSION == "7.2" ]]; then make test-coveralls; else make test; fi
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The ICanBoogie/Routing package is free software.
It is released under the terms of the following BSD License.

Copyright (c) 2007-2015 by Olivier Laviale
Copyright (c) 2007-2018 by Olivier Laviale
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# customization

PACKAGE_NAME = icanboogie/routing
PACKAGE_VERSION = 4.0
PHPUNIT_VERSION = phpunit-5.phar
PACKAGE_VERSION = 5.0
PHPUNIT_VERSION = phpunit-7.phar
PHPUNIT_FILENAME = build/$(PHPUNIT_VERSION)
PHPUNIT = php $(PHPUNIT_FILENAME)

# do not edit the following lines

all: $(PHPUNIT_FILENAME) vendor

usage:
@echo "test: Runs the test suite.\ndoc: Creates the documentation.\nclean: Removes the documentation, the dependencies and the Composer files."

Expand All @@ -22,18 +20,20 @@ update:
autoload: vendor
@composer dump-autoload

test-dependencies: vendor $(PHPUNIT_FILENAME)

$(PHPUNIT_FILENAME):
mkdir -p build
wget https://phar.phpunit.de/$(PHPUNIT_VERSION) -O $(PHPUNIT_FILENAME)

test: all
test: test-dependencies
@$(PHPUNIT)

test-coverage: all
test-coverage: test-dependencies
@mkdir -p build/coverage
@$(PHPUNIT) --coverage-html build/coverage

test-coveralls: all
test-coveralls: test-dependencies
@mkdir -p build/logs
COMPOSER_ROOT_VERSION=$(PACKAGE_VERSION) composer require satooshi/php-coveralls
@$(PHPUNIT) --coverage-clover build/logs/clover.xml
Expand Down
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ Routing\Helpers::patch('decontextualize', function($str) use($path) {

## Requirements

The package requires PHP 5.6 or later.
The package requires PHP 7.2 or later.



Expand Down Expand Up @@ -893,29 +893,29 @@ The package is continuously tested by [Travis CI](http://about.travis-ci.org/).



[ControllerBindings]: https://icanboogie.org/api/bind-routing/0.2/class-ICanBoogie.Binding.Routing.ControllerBindings.html
[Response]: https://icanboogie.org/api/http/3.0/class-ICanBoogie.HTTP.Response.html
[Request]: https://icanboogie.org/api/http/3.0/class-ICanBoogie.HTTP.Request.html
[RequestDispatcher]: https://icanboogie.org/api/http/3.0/class-ICanBoogie.HTTP.RequestDispatcher.html
[documentation]: https://icanboogie.org/api/routing/4.0/
[ActionNotDefined]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.ActionNotDefined.html
[ActionTrait]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Controller.ActionTrait.html
[Controller]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Controller.html
[Controller\BeforeActionEvent]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Controller.BeforeActionEvent.html
[Controller\ActionEvent]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Controller.ActionEvent.html
[ControllerNotDefined]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.ControllerNotDefined.html
[FormattedRoute]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.FormattedRoute.html
[Pattern]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Pattern.html
[PatternNotDefined]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.PatternNotDefined.html
[ResourceTrait]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Controller.ResourceTrait.html
[Route]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Route.html
[Route\RescueEvent]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.Route.RescueEvent.html
[RouteCollection]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.RouteCollection.html
[RouteDispatcher]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.RouteDispatcher.html
[RouteDispatcher\BeforeDispatchEvent]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.RouteDispatcher.BeforeDispatchEvent.html
[RouteDispatcher\DispatchEvent]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.RouteDispatcher.DispatchEvent.html
[RouteMaker]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.RouteMaker.html
[RouteNotDefined]: https://icanboogie.org/api/routing/4.0/class-ICanBoogie.Routing.RouteNotDefined.html
[ControllerBindings]: https://icanboogie.org/api/bind-routing/5.0/class-ICanBoogie.Binding.Routing.ControllerBindings.html
[Response]: https://icanboogie.org/api/http/4.0/class-ICanBoogie.HTTP.Response.html
[Request]: https://icanboogie.org/api/http/4.0/class-ICanBoogie.HTTP.Request.html
[RequestDispatcher]: https://icanboogie.org/api/http/4.0/class-ICanBoogie.HTTP.RequestDispatcher.html
[documentation]: https://icanboogie.org/api/routing/5.0/
[ActionNotDefined]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.ActionNotDefined.html
[ActionTrait]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Controller.ActionTrait.html
[Controller]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Controller.html
[Controller\BeforeActionEvent]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Controller.BeforeActionEvent.html
[Controller\ActionEvent]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Controller.ActionEvent.html
[ControllerNotDefined]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.ControllerNotDefined.html
[FormattedRoute]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.FormattedRoute.html
[Pattern]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Pattern.html
[PatternNotDefined]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.PatternNotDefined.html
[ResourceTrait]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Controller.ResourceTrait.html
[Route]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Route.html
[Route\RescueEvent]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.Route.RescueEvent.html
[RouteCollection]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.RouteCollection.html
[RouteDispatcher]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.RouteDispatcher.html
[RouteDispatcher\BeforeDispatchEvent]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.RouteDispatcher.BeforeDispatchEvent.html
[RouteDispatcher\DispatchEvent]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.RouteDispatcher.DispatchEvent.html
[RouteMaker]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.RouteMaker.html
[RouteNotDefined]: https://icanboogie.org/api/routing/5.0/class-ICanBoogie.Routing.RouteNotDefined.html
[ICanBoogie]: https://github.com/ICanBoogie/ICanBoogie
[icanboogie/bind-routing]: https://github.com/ICanBoogie/bind-routing
[icanboogie/service]: https://github.com/ICanBoogie/service
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"prefer-stable": true,
"prefer-dist": true,
"require": {
"php": ">=5.6",
"icanboogie/http": "^3.0"
"php": "^7.2",
"icanboogie/http": "^4.0"
},
"autoload": {
"psr-4": {
Expand Down
33 changes: 12 additions & 21 deletions lib/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ abstract class Controller extends Prototyped
* @return string|null The underscored name of the controller, or `null` if it cannot be
* extracted.
*/
protected function get_name()
protected function get_name(): ?string
{
$controller_class = get_class($this);
$controller_class = \get_class($this);

if (preg_match('/(\w+)Controller$/', $controller_class, $matches))
if (\preg_match('/(\w+)Controller$/', $controller_class, $matches))
{
return underscore($matches[1]);
}
Expand All @@ -78,26 +78,17 @@ protected function get_name()
*/
private $request;

/**
* @return Request
*/
protected function get_request()
protected function get_request(): Request
{
return $this->request;
}

/**
* @return Route
*/
protected function get_route()
protected function get_route(): Route
{
return $this->request->context->route;
}

/**
* @return Response
*/
protected function lazy_get_response()
protected function lazy_get_response(): Response
{
return new Response(null, Status::OK, [

Expand Down Expand Up @@ -170,7 +161,7 @@ abstract protected function action(Request $request);
*
* @return RedirectResponse
*/
public function redirect($url, $status = Status::FOUND, array $headers = [])
public function redirect($url, int $status = Status::FOUND, array $headers = []): Response
{
if ($url instanceof Route)
{
Expand All @@ -194,13 +185,13 @@ public function forward_to($destination)
return $this->forward_to_route($destination);
}

if (is_object($destination))
if (\is_object($destination))
{
$destination = "instance of " . get_class($destination);
$destination = "instance of " . \get_class($destination);
}
else if (is_array($destination))
else if (\is_array($destination))
{
$destination = json_encode($destination);
$destination = \json_encode($destination);
}

throw new \InvalidArgumentException("Don't know how to forward to: $destination.");
Expand All @@ -227,7 +218,7 @@ protected function forward_to_route(Route $route)

$controller = $route->controller;

if (!is_callable($controller))
if (!\is_callable($controller))
{
$controller = new $controller;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ActionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ActionEvent extends Event
* The event is constructed with the type {@link self::TYPE}.
*
* @param Controller $target
* @param string $result
* @param mixed $result
*/
public function __construct(Controller $target, &$result)
{
Expand Down
40 changes: 18 additions & 22 deletions lib/Controller/ActionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
*/
trait ActionTrait
{
/**
* Returns the action being executed.
*
* @return string
*/
protected function get_action()
protected function get_action(): string
{
return $this->route->action;
$action = $this->route->action;

if (empty($action))
{
throw new ActionNotDefined("Action not defined for route {$this->route->id}.");
}

return $action;
}

/**
Expand All @@ -57,15 +59,9 @@ protected function action(Request $request)
*
* @return callable
*/
protected function resolve_action(Request $request)
protected function resolve_action(Request $request): callable
{
$action = $this->action;

if (!$action)
{
throw new ActionNotDefined("Action not defined in route {$this->route->id}.");
}

$method = $this->resolve_action_method($action, $request);
$args = $this->resolve_action_args($action, $request);

Expand All @@ -84,24 +80,24 @@ protected function resolve_action(Request $request)
*
* @return string The method name.
*/
protected function resolve_action_method($action, Request $request)
protected function resolve_action_method(string $action, Request $request)
{
$action = strtr($action, '-', '_');
$method = 'action_' . strtolower($request->method) . '_' . $action;
$action = \strtr($action, '-', '_');
$method = 'action_' . \strtolower($request->method) . '_' . $action;

if (method_exists($this, $method))
if (\method_exists($this, $method))
{
return $method;
}

$method = 'action_any_' . $action;

if (method_exists($this, $method))
if (\method_exists($this, $method))
{
return $method;
}

return $method = 'action_' . $action;
return 'action_' . $action;
}

/**
Expand All @@ -112,8 +108,8 @@ protected function resolve_action_method($action, Request $request)
*
* @return array The arguments for the action.
*/
protected function resolve_action_args($action, Request $request)
protected function resolve_action_args(string $action, Request $request): array
{
return array_values($request->path_params);
return \array_values($request->path_params);
}
}
2 changes: 1 addition & 1 deletion lib/Controller/BeforeActionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BeforeActionEvent extends Event
* The event is constructed with the type {@link self::TYPE}.
*
* @param Controller $target
* @param string $result
* @param mixed $result
*/
public function __construct(Controller $target, &$result)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* {
* // a routing exception
* }
* catch (\Exception $e
* catch (\Throwable $e
* {
* // another type of exception
* }
Expand Down
10 changes: 5 additions & 5 deletions lib/FormattedRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class FormattedRoute
*/
protected $url;

protected function get_url()
protected function get_url(): string
{
return contextualize((string) $this);
}

protected function get_absolute_url()
protected function get_absolute_url(): string
{
return absolutize_url($this->get_url());
}
Expand All @@ -48,7 +48,7 @@ protected function get_absolute_url()
*/
protected $route;

protected function get_route()
protected function get_route(): Route
{
return $this->route;
}
Expand All @@ -59,13 +59,13 @@ protected function get_route()
* @param string $url
* @param Route $route
*/
public function __construct($url, Route $route)
public function __construct(string $url, Route $route)
{
$this->url = $url;
$this->route = $route;
}

public function __toString()
public function __toString(): string
{
return $this->url;
}
Expand Down
Loading

0 comments on commit f34f5bf

Please sign in to comment.