opsbears / piccolo-web
Web components for Piccolo
Requires
- php: ^7.0
- opsbears/piccolo: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.3
- opsbears/piccolo-dev-tools: ^1.0
- opsbears/piccolo-dic-auryn: ^1.0
Suggests
This package is not auto-updated.
Last update: 2020-10-16 21:39:21 UTC
README
The Piccolo web components provide the basic wiring for web based projects. They take care of everything from parsing the request into a PSR-7 compliant form to routing the request to the controller.
Optionally the data retrieved from the controller can also be routed to a templating engine, which is normally done by a separate component.
Installation
The installation of these components can be done via composer:
composer require opsbears/piccolo-web
It is also recommended that you install the following extra components, unless you want to replace them:
opsbears/piccolo-web-processor-controller-view-templating
to route controller responses to templates for view rendering.opsbears/piccolo-web-io-standard
to process standard PHP IO mechansims ($_GET
,$_POST
, etc) into PSR-7 requests.opsbears/piccolo-web-http-guzzle
to provide PSR-7 compatibilityopsbears/piccolo-web-router-fastroute
for routing.opsbears/piccolo-templating-engine-twig
for templating.
Usage
In order to use the Web package, you should include the WebModule
class into your configuration:
'modules' => [
WebModule::class,
//...
],
If you want to use the standard modules that the web module needs to operate, you can also include those:
'modules' => [
ControllerProcessorWebModule::class,
GuzzleHTTPModule::class,
StandardWebIOModule::class,
FastRouteModule::class,
TemplatingViewModule::class,
TwigTemplatingModule::class,
//...
],
You can then instantiate the WebApplication
class from your index.php
file:
$application = new WebApplication($dic, $config);
$application->execute();
In this example $dic
would be your dependency injection container (see the opsbears/piccolo
module for detailed
documentation) and $config
would be your configuration in array form.
The full setup in your index.php could then look something like this:
use Piccolo\DependencyInjection\Auryn\AurynDependencyInjectionContainer;
use Piccolo\Web\WebApplication;
require_once (__DIR__ . '/../vendor/autoload.php');
$dic = new AurynDependencyInjectionContainer();
$config = require(__DIR__ . '/../config/config.php');
$application = new WebApplication($dic, $config);
$application->execute();
Tip: the ControllerProcessorWebModule
module automatically loads the WebModule
, if you use that, you don't
need to explicitly load the WebModule
.