Skip to content

Commit

Permalink
17th commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adinan-cenci committed Oct 14, 2019
1 parent 94bbf2e commit 0bb2905
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGESLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.1 - 2019-10-14

Just tidying up the documentation and some grammar errors.

## 1.0.0 - 2019-10-13

### Removed
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# A small PHP router library

A simple PHP router.
A simple PHP router to handle http requests.

## How it works

Expand Down Expand Up @@ -115,7 +115,7 @@ $r->set404(function($route)

### ::before($methods = '*', $patterns, $callback)

Defines a middle-ware and the respective callback. The middle-wares will be matched against the requested url before the actual routes, and unlike the routes, more than one middle-ware callback may be executed. It accepts the the same parameter as ::add()
Defines a middleware and the respective callback. The middlewares will be matched against the requested url before the actual routes, and unlike the routes, more than one middleware callback may be executed. It accepts the the same parameter as ::add()

```php
// Example
Expand All @@ -131,9 +131,9 @@ $r->before('*', 'restricted-area', function()

Executes the router.

First it will try to match the request url and http method to <u>all</u> middle-wares, then it follows with the proper routes.
First it will try to match the request url and http method to <u>all</u> middlewares, then it follows with the proper routes.

Unlike the middle-wares, the router will execute the callback of the first matching route and stop.
Unlike the middlewares, the router will execute the callback of the first matching route and stop.

It will throw an exception if unable to execute the callback associated.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"keywords": ["router"],
"license": "MIT",
"version": "1.0.0",
"version": "1.0.1",
"authors": [
{
"name": "Adinan Cenci",
Expand Down
15 changes: 7 additions & 8 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ class Router
public function __construct()
{
// error 404 default function
$r = $this;
$this->error404 = function()
$this->error404 = function($route)
{
self::header404();
Router::header404();
echo 'Page not found';
};

Expand Down Expand Up @@ -62,7 +61,7 @@ public function namespace($namespace)
}

/**
* Associates middleware(s) to a function/method and http method(s)
* Associates route(s) and http method(s) to a middleware
*
* @param string $methods | separated http methods. Post, get, put etc. Optional.
* @param string|array $patterns Regex pattern(s)
Expand All @@ -85,7 +84,7 @@ public function before($methods = '*', $patterns = '', $callback = '')
}

/**
* Associates route(s) to a function/method and http method(s)
* Associates route(s) and http method(s) to a function/method
*
* @param string $methods | separated http methods. Post, get, put etc. Optional.
* @param string|array $patterns Regex pattern(s)
Expand All @@ -107,7 +106,7 @@ public function add($methods = '*', $patterns = '', $callback = '')
return $this;
}

/** Shortcuts for ::add */
/** Shorthands for the ::add method */
public function get($patterns, $callback)
{
$this->add('get', $patterns, $callback);
Expand Down Expand Up @@ -273,13 +272,13 @@ protected function notFound($path)

protected function sortAddParams($params)
{
$methods = 'get|post|put|delete|options|patch|head';
$methods = 'get|post|put|delete|options|patch';
$patterns = null;
$callback = null;
$x = 0;

if ($params[0] == '*') {
$methods = 'get|post|put|delete|options|patch|head';
$methods = 'get|post|put|delete|options|patch';
$x++;
} else if (is_string($params[0]) && explode('|', $params[0])) {
$methods = $params[0];
Expand Down

0 comments on commit 0bb2905

Please sign in to comment.