Skeleton
![Latest Version on Packagist][ico-version]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
An application structure for Zapheus framework., (*2)
Installation
Install Skeleton
via Composer:, (*3)
``` bash
$ composer create-project zapheus/skeleton:dev-master "acme", (*4)
## Basic Usage
### Running the application
Use PHP's built-in web server (available in v5.4+)
``` bash
$ php -S localhost:8000 -t app/web
Now open your web browser and go to http://localhost:8000., (*5)
Adding Zapheus providers
``` php
// app/config/providers.php, (*6)
return array(
// ..., (*7)
'zapheus' => array(
// ...
// Application Providers
'App\Acme\AcmeProvider',
'App\Acme\SampleProvider',
// ...
),
);, (*8)
A Zapheus provider must be implemented in a `ProviderInterface`:
``` php
namespace Zapheus\Provider;
use Zapheus\Container\WritableInterface;
interface ProviderInterface
{
/**
* @return \Zapheus\Container\ContainerInterface
*/
public function register(WritableInterface $container);
}
Adding dependencies to MappingsProvider
``` php
// src/Zapheus/MappingsProvider.php, (*9)
class MappingsProvider implements ProviderInterface
{
public function register(WritableInterface $container)
{
$test = 'App\Acme\DelegatesController';, (*10)
return $container->set($test, new $test);
}
}, (*11)
`MappingsProvider` is only applicable for specified handling of dependencies because Zapheus will try to manage the dependencies based on instances found from the container by default. For complex dependencies, it is recommended to implement it into a `ProviderInterface` instead.
### Adding HTTP routes to `DispatcherProvider`
``` php
// src/Acme/RouteCollection.php
use Zapheus\Routing\Router;
class RouteCollection extends Router
{
/**
* Namespace applied to all class-based routes.
*
* @var string
*/
protected $namespace = 'App\Acme';
/**
* Returns an array of route instances.
*
* @return \Zapheus\Routing\Route[]
*/
public function routes()
{
$this->get('/delegates', 'DelegatesController@index');
return $this->routes;
}
}
``` php
// src/Zapheus/DispatcherProvider.php, (*12)
class DispatcherProvider implements ProviderInterface
{
/**
* An array of Zapheus\Routing\RouterInterface instances.
*
* @var string[]
*/
protected $routers = array('App\Acme\RouteCollection');, (*13)
// ..
}, (*14)
### Adding multi-directory template files
``` php
// src/Acme/AcmeProvider.php
use Zapheus\Container\WritableInterface;
use Zapheus\Provider\ProviderInterface;
class AcmeProvider implements ProviderInterface
{
/**
* Registers the bindings in the container.
*
* @param \Zapheus\Container\WritableInterface $container
* @return \Zapheus\Container\ContainerInterface
*/
public function register(WritableInterface $container)
{
// ...
$templates = __DIR__ . DIRECTORY_SEPARATOR . 'Templates';
// Add a dot notation after "app.views"
$config->set('app.views.acme', $templates);
// ...
}
}
``` php
// src/Acme/DelegatesController, (*15)
class DelegatesController
{
protected $renderer;, (*16)
public function __construct(RendererInterface $renderer)
{
$this->renderer = $renderer;
}
public function index()
{
// Use the "acme" prefix defined from AcmeProvider
return $this->renderer->render('acme.test');
}
}, (*17)
## Changelog
Please see [CHANGELOG][link-changelog] for more information what has changed recently.
## Testing
``` bash
$ composer test
License
The MIT License (MIT). Please see LICENSE for more information., (*18)