zapheus / skeleton
An application structure for Zapheus framework.
Requires
- php: >=5.3.0
- vlucas/phpdotenv: ~2.0
- zapheus/zapheus: ~0.1
Requires (Dev)
- phpunit/phpunit: ~4.2|~5.7
- scrutinizer/ocular: ~1.1.0
- zapheus/slytherin-bridge: ~0.1
This package is auto-updated.
Last update: 2024-10-23 00:15:27 UTC
README
An application structure for Zapheus framework.
Installation
Install Skeleton
via Composer:
$ composer create-project zapheus/skeleton:dev-master "acme"
Basic Usage
Running the application
Use PHP's built-in web server (available in v5.4+)
$ php -S localhost:8000 -t app/web
Now open your web browser and go to http://localhost:8000.
Adding Zapheus providers
// app/config/providers.php return array( // ... 'zapheus' => array( // ... // Application Providers 'App\Acme\AcmeProvider', 'App\Acme\SampleProvider', // ... ), );
A Zapheus provider must be implemented in a ProviderInterface
:
namespace Zapheus\Provider; use Zapheus\Container\WritableInterface; interface ProviderInterface { /** * @return \Zapheus\Container\ContainerInterface */ public function register(WritableInterface $container); }
Adding dependencies to MappingsProvider
// src/Zapheus/MappingsProvider.php class MappingsProvider implements ProviderInterface { public function register(WritableInterface $container) { $test = 'App\Acme\DelegatesController'; return $container->set($test, new $test); } }
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
// 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; } }
// src/Zapheus/DispatcherProvider.php class DispatcherProvider implements ProviderInterface { /** * An array of Zapheus\Routing\RouterInterface instances. * * @var string[] */ protected $routers = array('App\Acme\RouteCollection'); // .. }
Adding multi-directory template files
// 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); // ... } }
// src/Acme/DelegatesController class DelegatesController { protected $renderer; public function __construct(RendererInterface $renderer) { $this->renderer = $renderer; } public function index() { // Use the "acme" prefix defined from AcmeProvider return $this->renderer->render('acme.test'); } }
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
License
The MIT License (MIT). Please see LICENSE for more information.