A thin PHP microframework built on Slim and Symfony.
Slim + Symfony = ๐
Panthor uses the simplicity of Slim and provides a bit more structure for applications with additional Symfony components. Utilities and helpers are provided to simplify template caching and dependency injection using Symfony Dependency Injection and Slim. It can be used for html applications, APIs, or both.
Slim/Slim
- The core microframework.Symfony/Config
- Cascading configuration to handle merging multiple config files.Symfony/DependencyInjection
- A robust and flexible dependency injection container.
Here's a few of the features Panthor provides:
- Standard interfaces for Controllers, Middleware, and Templates
- Error Handling (with Content Negotiation)
- Cookie Encryption with PECL Libsodium
- All configuration through YAML (including Slim routes)
- Support for HTTP Problem
- Utilities for Unit Testing
- Utilities for Templating
- Panthor 1
- Slim ~2.0
- Symfony ~2.0
- Panthor 2
- Slim ~2.0
- Symfony ~2.0
- Panthor 3
- Slim ~3.3
- Symfony ~3.0
- PHP ~5.6 || ~7.0
composer require ql/mcp-panthor ~3.0
See Panthor Skeleton for an example skeleton.
Never used Composer, Slim or Symfony before? Here are some resources:
-
Create an application with the following file hiearchy:
configuration/ bootstrap.php config.yml di.yml routes.yml public/ index.php src/ TestController.php
-
Initialize composer with the following commands:
composer init composer require ql/mcp-panthor ~3.0 paragonie/random_compat ~1.1 # Also require twig/twig if using html templating composer require twig/twig ~1.20
Add autoloader configuration to
composer.json
:"autoload": { "psr-4": { "TestApplication\\": "src" } }
-
configuration/config.yml
should import other config resources.imports: - resource: ../vendor/ql/mcp-panthor/configuration/panthor-slim.yml - resource: ../vendor/ql/mcp-panthor/configuration/panthor.yml - resource: di.yml - resource: routes.yml
-
configuration/di.yml
will contain service definitions for your application, such as controllers.services: page.hello_world: class: 'TestApplication\TestController'
-
configuration/routes.yml
contains routes.Routes is simply another config parameter passed into the DI container. It maps a route name to a url and list of services to call.
parameters: routes: hello_world: route: '/' stack: ['page.hello_world']
-
configuration/bootstrap.php
should load the composer autoloader and return the DI container.<?php namespace TestApplication\Bootstrap; use QL\Panthor\Bootstrap\Di; use TestApplication\CachedContainer; $root = __DIR__ . '/..'; require_once $root . '/vendor/autoload.php'; return Di::getDi($root, CachedContainer::class);
-
public/index.php
loads the bootstrap, attaches routes and starts Slim.<?php namespace TestApplication\Bootstrap; if (!$container = @include __DIR__ . '/../configuration/bootstrap.php') { http_response_code(500); echo "The application failed to start.\n"; exit; }; $slim = $container->get('slim'); $routes = $container->get('router.loader'); $routes($app); $slim->run();
-
src/TestController.php
is a simple controller that can be invoked as a callable.<?php namespace TestApplication; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use QL\Panthor\ControllerInterface; class TestController implements ControllerInterface { public function __invoke(ServerRequestInterface $request, ResponseInterface $response) { $response->getBody()->write('Hello World!'); return $response; } }
-
Don't forget your web server configuration!
- Panthor is just Slim under the hood, so it uses the same NGINX or Apache configuration as Slim (standard
index.php
rewrite). - Check out the slim documentation on web servers for more details.
- Panthor is just Slim under the hood, so it uses the same NGINX or Apache configuration as Slim (standard
Now just visit localhost
(or your preferred virtual host name) and your controller should load!
This quickstart leaves out many things such as Twig Templating, Cookie Encryption, and Error Handling. Check the documentation links below for further details.
-
Details on where code and configuration goes.
-
Explanations of controllers and middleware, as well as services injected into the Di Container by Panthor.
-
How to use the included error handler and logger.
-
Example setups for nginx and apache.
This library contains many convenience utilities and classes for your application. Some of this functionality requires other libraries, but because they are optional, they are not strict requirements.
Library / Extension | Used by |
---|---|
slim/slim | Bootstrap\ |
symfony/config | Bootstrap\ |
symfony/dependency-injection | Bootstrap\ |
symfony/yaml | Bootstrap\ |
psr/log | ErrorHandling\ |
ql/mcp-common | Encryption\ , Twig\ , HTTP\ , Middleware\EncryptedCookiesMiddleware |
dflydev/fig-cookies | HTTP\CookieHandler , Middleware\EncryptedCookiesMiddleware |
Please take note of the following packages and include them in your composer require
if you
use the associated Panthor functionality.
Library / Extension | Required for |
---|---|
twig/twig | Twig\ , ErrorHandling\ContentHandler |
paragonie/random_compat or PHP7 | Encryption\ |
PECL Libsodium | Encryption\ , Middleware\EncryptedCookiesMiddleware |