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 64552f1 commit f154007
Show file tree
Hide file tree
Showing 44 changed files with 420 additions and 595 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +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
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The ICanBoogie/HTTP package is free software.
The icanboogie/http package is free software.
It is released under the terms of the following BSD License.

Copyright (c) 2011-2016 by Olivier Laviale
Copyright (c) 2011-2018 by Olivier Laviale
All rights reserved.

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

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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ $response = dispatch($request);

## Requirements

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



Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"prefer-stable": true,
"prefer-dist": true,
"require": {
"php": ">=5.6",
"icanboogie/prototype": "^3.0 | ^4.0",
"icanboogie/event": "^3.0",
"php": "^7.2",
"icanboogie/prototype": "^5.0",
"icanboogie/event": "^4.0",
"icanboogie/datetime": "^1.2"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions lib/AuthenticationRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
class AuthenticationRequired extends ClientError implements SecurityError
{
const DEFAULT_MESSAGE = "The requested URL requires authentication.";
public const DEFAULT_MESSAGE = "The requested URL requires authentication.";

/**
* @inheritdoc
*/
public function __construct($message = self::DEFAULT_MESSAGE, $code = Status::UNAUTHORIZED, \Exception $previous = null)
public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = Status::UNAUTHORIZED, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
10 changes: 4 additions & 6 deletions lib/CallableDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,23 @@ class CallableDispatcher implements Dispatcher
/**
* @param callable $callable
*/
public function __construct($callable)
public function __construct(callable $callable)
{
$this->callable = $callable;
}

/**
* @inheritdoc
*/
public function __invoke(Request $request)
public function __invoke(Request $request): ?Response
{
$callable = $this->callable;

return $callable instanceof \Closure ? $callable($request) : call_user_func($callable, $request);
return ($this->callable)($request);
}

/**
* @inheritdoc
*/
public function rescue(\Exception $exception, Request $request)
public function rescue(\Throwable $exception, Request $request): Response
{
throw $exception;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ClientError.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ClientError extends \Exception implements Exception
/**
* @inheritdoc
*/
public function __construct($message = null, $code = Status::BAD_REQUEST, \Exception $previous = null)
public function __construct(string $message = null, int $code = Status::BAD_REQUEST, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ interface Dispatcher
*
* @param Request $request
*
* @return Response A response to the request.
* @return Response|null A response or `null` if the dispatcher cannot handle the request.
*/
public function __invoke(Request $request);
public function __invoke(Request $request): ?Response;

/**
* Rescues the exception that was thrown during the request process.
*
* @param \Exception $exception
* @param \Throwable $exception
* @param Request $request
*
* @return Response A response to the request exception.
*
* @throws \Exception when the request exception cannot be rescued.
* @throws \Throwable when the request exception cannot be rescued.
*/
public function rescue(\Exception $exception, Request $request);
public function rescue(\Throwable $exception, Request $request): Response;
}
20 changes: 5 additions & 15 deletions lib/DispatcherNotDefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,25 @@ class DispatcherNotDefined extends \LogicException implements Exception
*/
private $dispatcher_id;

/**
* @return string
*/
protected function get_dispatcher_id()
protected function get_dispatcher_id(): string
{
return $this->dispatcher_id;
}

/**
* @param string $dispatcher_id
* @param string|null $message
* @param \Exception|int $code
* @param \Exception|null $previous
* @param \Throwable|int $code
* @param \Throwable|null $previous
*/
public function __construct($dispatcher_id, $message = null, $code = Status::INTERNAL_SERVER_ERROR, \Exception $previous = null)
public function __construct(string $dispatcher_id, string $message = null, int $code = Status::INTERNAL_SERVER_ERROR, \Throwable $previous = null)
{
$this->dispatcher_id = $dispatcher_id;

parent::__construct($message ?: $this->format_message($dispatcher_id), $code, $previous);
}

/**
* Formats exception message.
*
* @param string $dispatcher_id
*
* @return string
*/
protected function format_message($dispatcher_id)
private function format_message(string $dispatcher_id): string
{
return format("The dispatcher %dispatcher_id is not defined.", [

Expand Down
8 changes: 4 additions & 4 deletions lib/DispatcherProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DispatcherProvider
*
* @return callable|null
*/
static public function defined()
static public function defined(): ?callable
{
return self::$provider;
}
Expand All @@ -38,7 +38,7 @@ static public function defined()
*
* @return callable|null The previous provider, or `null` if none was defined.
*/
static public function define(callable $provider)
static public function define(callable $provider): ?callable
{
$previous = self::$provider;

Expand All @@ -50,7 +50,7 @@ static public function define(callable $provider)
/**
* Undefine the current {@link Dispatcher} provider.
*/
static public function undefine()
static public function undefine(): void
{
self::$provider = null;
}
Expand All @@ -62,7 +62,7 @@ static public function undefine()
*
* @throws DispatcherProviderNotDefined if no provider is defined.
*/
static public function provide()
static public function provide(): Dispatcher
{
$provider = self::$provider;

Expand Down
4 changes: 2 additions & 2 deletions lib/DispatcherProviderNotDefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/
class DispatcherProviderNotDefined extends \LogicException implements Exception
{
const DEFAULT_MESSAGE = "No provider is defined yet. Please define one with `DispatcherProvider::define(\$provider)`.";
public const DEFAULT_MESSAGE = "No provider is defined yet. Please define one with `DispatcherProvider::define(\$provider)`.";

/**
* @inheritdoc
*/
public function __construct($message = self::DEFAULT_MESSAGE, $code = Status::INTERNAL_SERVER_ERROR, \Exception $previous = null)
public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = Status::INTERNAL_SERVER_ERROR, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
Loading

0 comments on commit f154007

Please sign in to comment.