Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: miladrahimi/phprouter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.1.4
Choose a base ref
...
head repository: miladrahimi/phprouter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 5 commits
  • 34 files changed
  • 2 contributors

Commits on Nov 30, 2023

  1. update to new php style

    miladrahimi committed Nov 30, 2023
    Copy the full SHA
    29ed5a4 View commit details
  2. Update README.md

    miladrahimi authored Nov 30, 2023
    Copy the full SHA
    068b3e7 View commit details

Commits on Jan 31, 2024

  1. Update README.md

    miladrahimi authored Jan 31, 2024
    Copy the full SHA
    b312c6f View commit details

Commits on Aug 17, 2024

  1. remove exact versions

    miladrahimi committed Aug 17, 2024
    Copy the full SHA
    52dd13d View commit details

Commits on Aug 19, 2024

  1. Update README.md

    miladrahimi authored Aug 19, 2024
    Copy the full SHA
    92cc519 View commit details
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# These are supported funding model platforms

custom: ["https://miladrahimi.com/pay.html"]
github: miladrahimi
custom: ["https://miladrahimi.com/pay.html", "https://www.paypal.com/paypalme/realmiladrahimi"]
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI
on: [push, pull_request]
jobs:
run:
strategy:
matrix:
include:
- php: '7.4'
- php: '8.0'
- php: '8.1'
- php: '8.2'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
- name: Install dependencies
run: composer self-update && composer install && composer dump-autoload
- name: Run tests and collect coverage
run: vendor/bin/phpunit --coverage-clover coverage.xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4-beta
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[![Latest Stable Version](https://poser.pugx.org/miladrahimi/phprouter/v)](//packagist.org/packages/miladrahimi/phprouter)
[![Total Downloads](https://poser.pugx.org/miladrahimi/phprouter/downloads)](//packagist.org/packages/miladrahimi/phprouter)
[![Build Status](https://travis-ci.org/miladrahimi/phprouter.svg?branch=master)](https://travis-ci.org/miladrahimi/phprouter)
[![Coverage Status](https://coveralls.io/repos/github/miladrahimi/phprouter/badge.svg?branch=master)](https://coveralls.io/github/miladrahimi/phprouter?branch=master)
[![Build](https://github.com/miladrahimi/phprouter/actions/workflows/ci.yml/badge.svg)](https://github.com/miladrahimi/phprouter/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/miladrahimi/phprouter/graph/badge.svg?token=KctrYUweFd)](https://codecov.io/gh/miladrahimi/phprouter)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/miladrahimi/phprouter/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/miladrahimi/phprouter/?branch=master)
[![License](https://poser.pugx.org/miladrahimi/phprouter/license)](//packagist.org/packages/miladrahimi/phprouter)

# PhpRouter

PhpRouter is a powerful, lightweight, and very fast HTTP URL router for PHP projects.
PhpRouter is a full-featured yet very fast HTTP URL router for PHP projects.

Some of the provided features:
* Route parameters
@@ -341,7 +342,7 @@ $router->dispatch();

### Views

You might need to create a classic-style website that uses views.
You might need to create a classic-style server-side rendered (SSR) website that uses views.
PhpRouter has a simple feature for working with PHP/HTML views.
Look at the following example.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -16,21 +16,21 @@
"authors": [
{
"name": "Milad Rahimi",
"email": "info@miladrahimi.com",
"email": "i@miladrahimi.com",
"homepage": "https://miladrahimi.com",
"role": "Developer"
}
],
"support": {
"email": "info@miladrahimi.com",
"email": "i@miladrahimi.com",
"source": "https://github.com/miladrahimi/phprouter/issues"
},
"require": {
"php": ">=7.1",
"php": ">=7.4",
"ext-json": "*",
"ext-mbstring": "*",
"laminas/laminas-diactoros": "^2.2",
"miladrahimi/phpcontainer": "^5.3.1"
"laminas/laminas-diactoros": "^2",
"miladrahimi/phpcontainer": "^5"
},
"require-dev": {
"phpunit/phpunit": "^7|^8|^9"
22 changes: 12 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<phpunit backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="main">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<logging/>
</phpunit>
19 changes: 4 additions & 15 deletions src/Dispatching/Caller.php
Original file line number Diff line number Diff line change
@@ -10,23 +10,12 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Class Caller
* It calls (runs) middleware and controllers
*
* @package MiladRahimi\PhpRouter\Dispatching
*/
class Caller
{
/**
* @var Container
*/
private $container;
private Container $container;

/**
* Constructor
*
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
@@ -75,13 +64,13 @@ public function call($callable)

[$class, $method] = $callable;

if (class_exists($class) == false) {
if (!class_exists($class)) {
throw new InvalidCallableException("Class `$class` not found.");
}

$object = $this->container->instantiate($class);

if (method_exists($object, $method) == false) {
if (!method_exists($object, $method)) {
throw new InvalidCallableException("Method `$class::$method` is not declared.");
}

@@ -104,7 +93,7 @@ public function call($callable)
}
}

if (is_callable($callable) == false) {
if (!is_callable($callable)) {
throw new InvalidCallableException('Invalid callable.');
}

16 changes: 2 additions & 14 deletions src/Dispatching/Matcher.php
Original file line number Diff line number Diff line change
@@ -8,23 +8,12 @@
use Psr\Http\Message\ServerRequestInterface;

/**
* Class Matcher
* It finds an appropriate route for HTTP requests
*
* @package MiladRahimi\PhpRouter\Dispatching
*/
class Matcher
{
/**
* @var Repository
*/
private $repository;
private Repository $repository;

/**
* Constructor
*
* @param Repository $repository
*/
public function __construct(Repository $repository)
{
$this->repository = $repository;
@@ -38,7 +27,7 @@ public function __construct(Repository $repository)
* @return Route
* @throws RouteNotFoundException
*/
public function find(ServerRequestInterface $request, array $patterns)
public function find(ServerRequestInterface $request, array $patterns): Route
{
foreach ($this->repository->findByMethod($request->getMethod()) as $route) {
$parameters = [];
@@ -59,7 +48,6 @@ public function find(ServerRequestInterface $request, array $patterns)
*
* @param string[] $parameters
* @return string[]
* @noinspection PhpUnusedParameterInspection
*/
private function pruneRouteParameters(array $parameters): array
{
3 changes: 0 additions & 3 deletions src/Exceptions/InvalidCallableException.php
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@
use Exception;

/**
* Class InvalidCallableException
* It'd be thrown when a callable (controller or middleware) is not valid
*
* @package MiladRahimi\PhpRouter\Exceptions
*/
class InvalidCallableException extends Exception
{
3 changes: 0 additions & 3 deletions src/Exceptions/RouteNotFoundException.php
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@
use Exception;

/**
* Class RouteNotFoundException
* It'd be thrown when no route that matches the user request
*
* @package MiladRahimi\PhpRouter\Exceptions
*/
class RouteNotFoundException extends Exception
{
3 changes: 0 additions & 3 deletions src/Exceptions/UndefinedRouteException.php
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@
use Exception;

/**
* Class UndefinedRouteException
* It'd be thrown when cannot find a route to generate URL from
*
* @package MiladRahimi\PhpRouter\Exceptions
*/
class UndefinedRouteException extends Exception
{
3 changes: 0 additions & 3 deletions src/Publisher/HttpPublisher.php
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@
use Psr\Http\Message\ResponseInterface;

/**
* Class HttpPublisher
* It publishes responses provided by controllers and middleware as HTTP responses
*
* @package MiladRahimi\PhpRouter\Services
*/
class HttpPublisher implements Publisher
{
3 changes: 0 additions & 3 deletions src/Publisher/Publisher.php
Original file line number Diff line number Diff line change
@@ -3,10 +3,7 @@
namespace MiladRahimi\PhpRouter\Publisher;

/**
* Interface Publisher
* It publishes responses provided by controllers and middleware
*
* @package MiladRahimi\PhpRouter\Services
*/
interface Publisher
{
39 changes: 6 additions & 33 deletions src/Router.php
Original file line number Diff line number Diff line change
@@ -20,54 +20,27 @@
use Laminas\Diactoros\ServerRequestFactory;

/**
* Class Router
* It defines the application routes and dispatches them (runs the application).
*
* @package MiladRahimi\PhpRouter
*/
class Router
{
/**
* @var Container
*/
private $container;
private Container $container;

/**
* @var Storekeeper
*/
private $storekeeper;
private Storekeeper $storekeeper;

/**
* @var Matcher
*/
private $matcher;
private Matcher $matcher;

/**
* @var Caller
*/
private $caller;
private Caller $caller;

/**
* @var Publisher
*/
private $publisher;
private Publisher $publisher;

/**
* List of defined parameter patterns with `pattern()` method
*
* @var string[]
*/
private $patterns = [];
private array $patterns = [];

/**
* Constructor
*
* @param Container $container
* @param Storekeeper $storekeeper
* @param Matcher $matcher
* @param Caller $caller
* @param Publisher $publisher
*/
public function __construct(
Container $container,
Storekeeper $storekeeper,
3 changes: 0 additions & 3 deletions src/Routing/Attributes.php
Original file line number Diff line number Diff line change
@@ -3,10 +3,7 @@
namespace MiladRahimi\PhpRouter\Routing;

/**
* Class Attributes
* It is an Enum that holds route attributes
*
* @package MiladRahimi\PhpRouter\Routing
*/
class Attributes
{
5 changes: 1 addition & 4 deletions src/Routing/Repository.php
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@
use Closure;

/**
* Class Repository
* It is a repository for the defined routes
*
* @package MiladRahimi\PhpRouter\Routing
*/
class Repository
{
@@ -17,7 +14,7 @@ class Repository
*
* @var Route[]
*/
private $routes = [];
private array $routes = [];

/**
* Save a new route
Loading