Skip to content

Commit

Permalink
merge d422d9df97fa
Browse files Browse the repository at this point in the history
  • Loading branch information
iwyg committed Feb 21, 2016
1 parent e40d0c0 commit d995344
Show file tree
Hide file tree
Showing 417 changed files with 6,765 additions and 30,686 deletions.
File renamed without changes.
3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion lucid/cache/.travis.yml → .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ install:
script:
- if [[ $CODE_COVERAGE_LOG != 'true' ]]; then php vendor/bin/phpunit --verbose; fi;
- if [[ $CODE_COVERAGE_LOG == 'true' ]]; then php vendor/bin/phpunit --coverage-clover coverage/clover.xml; fi;
- if [[ $CS_CHECK_ENABLED == 'true' ]]; then php vendor/bin/phpcs --standard=PSR2 --ignore=vendor/* src tests; fi
- if [[ $CS_CHECK_ENABLED == 'true' ]]; then php vendor/bin/phpcs --standard=PSR2 --ignore=vendor/* --ignore=*/Fixures src tests; fi

after_script:
- if [[ $CODE_COVERAGE_LOG == 'true' ]]; then php vendor/bin/coveralls; fi
Expand Down
6 changes: 3 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2014-2016 Thomas Appel
# Copyright (c) 2015-2017 Thomas Appel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
150 changes: 147 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,151 @@
# Lucid Source Repository
# A PSR-7 compatible HTTP router

[![Author](http://img.shields.io/badge/author-iwyg-blue.svg?style=flat-square)](https://github.com/iwyg)
[![Source Code](http://img.shields.io/badge/source-lucid/mux-blue.svg?style=flat-square)](https://github.com/lucidphp/mux/tree/master)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/lucidphp/mux/blob/master/LICENSE.md)

[![Build Status](https://img.shields.io/travis/lucidphp/mux/master.svg?style=flat-square)](https://travis-ci.org/lucidphp/mux)
[![Code Coverage](https://img.shields.io/coveralls/lucidphp/mux/master.svg?style=flat-square)](https://coveralls.io/r/lucidphp/mux)
[![HHVM](https://img.shields.io/hhvm/lucid/mux/dev-master.svg?style=flat-square)](http://hhvm.h4cc.de/package/lucid/mux)

## Installation

```bash
$ composer -v install
```shell
> composer require lucid/mux:dev-master
```

## Usage

### Creating coute collections

#### Manualy

```php
<?php

use Lucid\Mux\Route;
use Lucid\Mux\Routes;

$routes = new Routes;
$routes->add('index', new Route('/', 'Acme\FrontController@getIndex'));

```

#### Using the Builder

```php
<?php

use Lucid\Mux\RouteCollectionBuilder as Builder;

$builder = new Builder;

// adds a GET route
$builder->get('/', 'Acme\FrontController@getIndex');

// adds a POST route
$builder->post('/user', 'Acme\UserController@createUser');

// adds a UPDATE route
$builder->update('/user/{id}', 'Acme\UserController@updateUser');

// adds a DELETE route
$builder->delete('/user/{id}', 'Acme\UserController@deleteUser');

```

### Dispatching routes

The router component takes a request context object to dispatch the
corresponding routing action.

```php
<?php
use Lucid\Mux\Router;
use Lucid\Mux\Request\Context as RequestContext;

$router = new Router($builder->getCollection());

$request = new RequestContext(
current(explode('?', $_SERVER['REQUEST_URI'])),
$_SERVER['REQUEST_METHOD']
);

$response = $router->dispatch($request);

```

#### Working with PSR-7 requests

You can easily create a requestcontext from an existing psr7 compatible
server request by using the `Context::fromPsrRequest()` method.

```php
<?php
$request = new RequestContext::fromPsrRequest($psrRequest);
```

#### Dispatching named routes

```php
<?php

$options = [
'id' => 12
];

$response = $router->route('user.delete', $options);
```

### Advanced router configuration

The router mostly relies on two main components:

1. a handler dispatcher, which is responsible for finding and executing the
given action (defined on the route object)
- a response mapper, which is capable of mapping the responsens to a desired
type

#### The handler dispatcher

By default, the handler dispatcher/resolver will check if the given handler is
callable. If the handler is a string containing an @ symbol, it is assumed that
the left hand side represents a classname and the right hand site a method.

##### Dependency Injection

If the handler resolver (`Lucid\Mux\Handler\Resolver` by default) is constructed
with an instance of `Interop\Container\ContainerInterface` it will also check if
the left hand side is a service registered by the di container.

```php
<?php

use Lucid\Mux\Handler\Resolver;
use Lucid\Mux\Handler\Dispatcher;

$resolver = new Resolver($container)
$dispatcher = new Dispatcher($resolver);
```

#### The response mapper

By default, the response mapper is a simple passthrough mapper. However it's easy
to create a custom mapper that suites your
specific needs.

```php
<?php

use Zend\Diactoros\Response;

use Lucid\Mux\Request\ResponseMapperInterface.php;

class PsrResponseMapper implements ResponseMapperInterface
{
public function mapResponse($response)
{
return new Response($response);
}
}
```
108 changes: 0 additions & 108 deletions build/publish

This file was deleted.

67 changes: 17 additions & 50 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,36 @@
{
"name": "lucid/lucid",
"require": {
"php":">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "5.2.*@dev",
"psr/http-message": "1.0.*@dev",
"container-interop/container-interop": "dev-master",
"phpseclib/phpseclib": "0.3.*@dev"
},
"name": "lucid/mux",
"license": "MIT",
"description": "Psr7 compatible http Routing Library",
"keywords": ["http", "prs7", "routing"],
"authors": [
{
"name": "iwyg",
"email": "mail@thomas-appel.com"
}
],
"require": {
"php":"^5.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "5.2.*@dev",
"lucid/resource": "dev-develop",
"container-interop/container-interop": "~1.1.0",
"zendframework/zend-diactoros":"^1.3"
},
"autoload": {
"psr-4": {
"Lucid\\Cache\\":"lucid/cache/src/",
"Lucid\\Common\\":"lucid/common/src/",
"Lucid\\Config\\":"lucid/config/src/",
"Lucid\\DI\\":"lucid/di/src/",
"Lucid\\Filesystem\\":"lucid/filesystem/src/",
"Lucid\\Hash\\":"lucid/hash/src/",
"Lucid\\Http\\":"lucid/http/src/",
"Lucid\\Mux\\":"lucid/mux/src/",
"Lucid\\Mux\\Cache\\":"lucid/mux-cache/src/",
"Lucid\\Resource\\":"lucid/resource/src/",
"Lucid\\Signal\\":"lucid/signal/src/",
"Lucid\\Template\\":"lucid/template/src/",
"Lucid\\Writer\\":"lucid/writer/src/",
"Lucid\\Xml\\":"lucid/xml/src/"
"Lucid\\Mux\\":"src/"
}
},
"autoload-dev": {
"psr-4": {
"Lucid\\Cache\\Tests\\":"lucid/cache/tests/",
"Lucid\\Common\\Tests\\":"lucid/common/tests/",
"Lucid\\Config\\Tests\\":"lucid/config/tests/",
"Lucid\\DI\\Tests\\":"lucid/di/tests/",
"Lucid\\Filesystem\\Tests\\":"lucid/filesystem/tests/",
"Lucid\\Hash\\Tests\\":"lucid/hash/tests/",
"Lucid\\Http\\Tests\\":"lucid/http/tests/",
"Lucid\\Mux\\Tests\\":"lucid/mux/tests/",
"Lucid\\Mux\\Cache\\Tests\\":"lucid/mux-cache/tests/",
"Lucid\\Resource\\Tests\\":"lucid/resource/tests/",
"Lucid\\Signal\\Tests\\":"lucid/signal/tests/",
"Lucid\\Template\\Tests\\":"lucid/template/tests/",
"Lucid\\Writer\\Tests\\":"lucid/writer/tests/",
"Lucid\\Xml\\Tests\\":"lucid/xml/tests/"
"Lucid\\Mux\\Tests\\":"tests/"
}
},
"provides": {
"lucid/common": "dev-master",
"lucid/config": "dev-master",
"lucid/di": "dev-master",
"lucid/filesystem": "dev-master",
"lucid/mux": "dev-master",
"lucid/mux-cache": "dev-master",
"lucid/resource": "dev-master",
"lucid/signal": "dev-master",
"lucid/template": "dev-master",
"lucid/writer": "dev-master",
"lucid/xml": "dev-master"
"suggest": {
"lucid/resource": "For loading routes from file definitions.",
"container-interop/container-interop": "For resolving controllers via a DI container."
},
"minimum-stability": "dev"
}
Loading

0 comments on commit d995344

Please sign in to comment.