Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php

php:
- 7.0
- 7.1
- 7.2

before_script:
- composer install --no-interaction
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
10.0
====

- Most code has been moved to thecodingmachine/splash-router
- Only classes specific to Mouf or embedding some display logic stay in this package

7.0
===

Expand Down
120 changes: 3 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,121 +6,7 @@
[![Build Status](https://travis-ci.org/thecodingmachine/mvc.splash-common.svg?branch=8.0)](https://travis-ci.org/thecodingmachine/mvc.splash-common)
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/mvc.splash-common/badge.svg?branch=8.0&service=github)](https://coveralls.io/github/thecodingmachine/mvc.splash-common?branch=8.0)

Splash: a highly configurable PSR-7 router
==========================================
Splash: a highly configurable PSR-15 router
===========================================

What is Splash?
---------------

Splash is a PHP router. It takes an HTTP request and dispatches it to the appropriate controller.

- Splash is [PSR-7 compatible](http://www.php-fig.org/psr/psr-7/)
- It acts as a [PSR-7 middleware](https://akrabat.com/writing-psr-7-middleware/)
- It is based on **controllers** and **annotations** (routes are declared as annotations in the controllers)
- It is heavily optimized, relying on an underlying [PSR-6 cache](http://www.php-fig.org/psr/psr-6/)
- It is a **pure** router. It is not a full-featured MVC framework. No views management, no model, only routing!
- It promotes best practices. Controllers must be declared in a [container-interop compatible container](https://github.com/container-interop/container-interop/).
- It is extensible.
- It integrates with a high number of tools:
- With [Mouf](http://mouf-php.com): this provides a friendly UI to generate controllers
- With [Drupal (through Druplash, a module that adds a Splash-compatible MVC framework)](http://mouf-php.com/packages/mouf/integration.drupal.druplash),
- With [Wordpress (through Moufpress, a plugin that adds a Splash-compatible MVC framework)](http://mouf-php.com/packages/mouf/integration.wordpress.moufpress),
- With [Joomla (through Moufla, a plugin that adds a Splash-compatible MVC framework)](http://mouf-php.com/packages/mouf/integration.wordpress.moufpress),
- With [Magento (through Moufgento, a plugin that adds a Splash-compatible MVC framework)](http://mouf-php.com/packages/mouf/integration.magento.moufgento),
- And it supports emoji routes (mydomain.com/😍)


Clean controllers
-----------------

Want to get a feeling of Splash? Here is a typical controller:

```php
use Mouf\Mvc\Splash\Annotations\Get;
use Mouf\Mvc\Splash\Annotations\URL;

class MyController
{
/**
* @URL("/my/path")
* @Get
*/
public function index(ServerRequestInterface $request)
{
return new JsonResponse(["Hello" => "World!"]);
}
}
```

Ok, so far, things should be fairly obvious to anyone used to PSR-7. The important parts are:

- Routing is done using the **@URL** annotation. When a method has the **@URL** annotation, we call it an *action*.
- **Controllers are clean**. They don't extend any "Splash" object (so are reusable in any other PSR-7 compatible MVC framework)
- Actions can optionally have a **@Get**, **@Post**, **@Put**, **@Delete** annotation to restrict the response to some HTTP method.
- Splash analyzes the action signature. If it finds a type-hinted `ServerRequestInterface` parameter, it will fill it the PSR-7 request object.
- Actions must return an object implementing the PSR-7 `ResponseInterface`.


Even better
-----------

But Splash can provide much more than this.

Here is a more advanced routing scenario:

```php
use Mouf\Mvc\Splash\Annotations\Post;
use Mouf\Mvc\Splash\Annotations\URL;
use Psr\Http\Message\UploadedFileInterface;

class MyController
{
/**
* @URL("/user/{id}")
* @Post
*/
public function index($id, $firstName, $lastName, UploadedFileInterface $logo)
{
return //...;
}
}
```

Look at the signature: `public function index($id, $firstName, $lastName, UploadedFileInterface $logo)`.

- `$id` will be fetched from the URL (`@URL("/user/{id}")`)
- `$firstName` and `$lastName` will be automatically fetched from the GET/POST parameters
- finally, `$logo` will contain the uploaded file from `$_FILES['logo']`

See the magic? **Just by looking at your method signature, you know what parameters your route is expecting.** The method signature is self-documenting the route!

Even better, Splash is highly extensible. You can add your own plugins to automatically fill some parameters of the request (we call those `ParameterFetchers`).
You could for instance write a parameter fetcher to automatically load Doctrine entities:

```php
/**
* Lo and behold: you can extend Splash to automatically fill the function parameters with objects of your liking
*
* @URL("/product/{product}")
* @Post
*/
public function index(My\Entities\Product $product)
{
return //...;
}

```

Best practices
--------------

You might wonder: "*How will Splash instantiate your controller*?" Well, Splash will not instantiate your controller.
Instantiating services and containers is the role of the dependency injection container. Splash connects to any *container-interop* compatible container and will fetch your controllers from the container.

This means that you **must** declare your controller in the container you are using. This is actually a *good thing* as this encourages you to not use the container as a service locator.


High performance
----------------

For best performance, Splash is caching the list of routes it detects. Unlike what can be seen in most micro-frameworks where the application slows down as the number of routes increases, in Splash, **performance stays constant as the number of routes increases**.
[Splash documentation is available at https://thecodingmachine.github.io/splash-router/](https://thecodingmachine.github.io/splash-router/)
77 changes: 8 additions & 69 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,24 @@
],
"require" : {
"php" : ">=7.0",
"psr/cache": "^1.0",
"cache/void-adapter": "^0.3.0",
"doctrine/annotations": "^1.2",
"thecodingmachine/splash-router": "^10",
"mouf/mouf": "^2.0",
"mouf/html.htmlelement" : "^2.0",
"mouf/utils.action.common-action" : "~1.0",
"mouf/utils.common.url-interface" : "~1.0",
"mouf/html.renderer.twig-extensions": "~1.0",
"mouf/utils.common.conditioninterface": "~2.0",
"mouf/utils.cache.cache-interface": "~2.0",
"zendframework/zend-diactoros": "~1.0",
"mouf/html.template.templateinterface": "^2.1",
"container-interop/service-provider": "^0.4",
"thecodingmachine/common-factories": "^0.4",
"thecodingmachine/middleware-list-universal-module": "~1.0",
"http-interop/http-middleware": "^0.4"
"mouf/html.template.templateinterface": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"satooshi/php-coveralls": "^1.0",
"mouf/picotainer": "~1.0",
"mnapoli/simplex": "^0.3",
"cache/array-adapter": "^0.4.0"
},
"conflict": {
"zendframework/zend-stratigility": "<2.0"
"cache/array-adapter": "^0.4.0",
"phpstan/phpstan": "^0.10.1"
},
"autoload" : {
"psr-4" : {
"Mouf\\Annotations\\" : "src/Mouf/Annotations",
"Mouf\\Mvc\\Splash\\" : "src/Mouf/Mvc/Splash"
}
},
Expand All @@ -58,64 +47,14 @@
"Mouf\\Mvc\\Splash\\" : "tests/Mouf/Mvc/Splash"
}
},
"scripts": {
"phpstan": "phpstan analyse src/Mouf -c phpstan.neon --level=0 --no-progress -vvv"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra" : {
"mouf" : {
"logo" : "doc/images/logo.png",
"doc" : [{
"title" : "Installing Splash",
"url" : "doc/install/index.md",
"children": [
{
"title" : "Standalone mode",
"url" : "doc/install/standalone.md"
},
{
"title" : "Mouf integration",
"url" : "doc/install/mouf.md"
},
{
"title" : "Service provider",
"url" : "doc/service-provider.md"
}
]
},
{
"title" : "Writing controllers",
"url" : "doc/writing_controllers_manually.md"
},
{
"title" : "Integrations",
"children" : [
{
"title" : "Mouf",
"children" : [
{
"title" : "Controller creation wizard",
"url" : "doc/mouf/writing_controllers.md"
},
{
"title" : "Advanced: configuring routing",
"url" : "doc/url_routing.md"
}
]
}
]
},
{
"title" : "Managing URL parameters",
"url" : "doc/url_parameters.md"
},
{
"title" : "Writing your own filters",
"url" : "doc/filters.md"
},
{
"title" : "Migrating from older version",
"url" : "doc/migrating.md"
}
],
"section": {
"name": "MVC",
"description": "All the tools you need to route requests and display pages",
Expand Down
91 changes: 0 additions & 91 deletions doc/filters.md

This file was deleted.

Binary file removed doc/images/activate_splash.png
Binary file not shown.
Binary file removed doc/images/configure_splash.jpg
Binary file not shown.
Binary file removed doc/images/create_instance.jpg
Binary file not shown.
Binary file removed doc/images/create_instance.png
Binary file not shown.
Binary file removed doc/images/create_instance_splash.jpg
Binary file not shown.
Binary file removed doc/images/images.ppt
Binary file not shown.
Binary file removed doc/images/install_splash.png
Binary file not shown.
Binary file removed doc/images/install_splash_2.png
Binary file not shown.
Binary file removed doc/images/install_splash_3.png
Binary file not shown.
Binary file removed doc/images/logo.png
Binary file not shown.
Binary file removed doc/images/register_controller_file.jpg
Binary file not shown.
Binary file removed doc/images/splash_instance.png
Binary file not shown.
Binary file removed doc/images/splash_menu.png
Binary file not shown.
Binary file removed doc/images/splash_menu_section.png
Binary file not shown.
Binary file removed doc/images/template_structure.png
Binary file not shown.
Binary file removed doc/images/wizard.png
Binary file not shown.
Binary file removed doc/images/wizard_menu.png
Binary file not shown.
9 changes: 0 additions & 9 deletions doc/install/index.md

This file was deleted.

Loading