Coder Social home page Coder Social logo

mcp-panthor's Introduction

MCP Panthor

Build Status Code Climate Latest Stable Version License

A thin PHP microframework built on Slim and Symfony.

Slim + Symfony = ๐Ÿ’ž

โš ๏ธ Panthor was recently updated to 3.0. Check out the Upgrade Guide for 3.0.

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

Table of Contents

Compatibility

  • 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

Starting a new application?

Installation

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:

Quick Start

  1. Create an application with the following file hiearchy:

    configuration/
        bootstrap.php
        config.yml
        di.yml
        routes.yml
    public/
        index.php
    src/
        TestController.php
    
  2. 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" }
    }
  3. 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
  4. configuration/di.yml will contain service definitions for your application, such as controllers.

    services:
        page.hello_world:
            class: 'TestApplication\TestController'
  5. 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']
  6. 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);
  7. 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();
  8. 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;
        }
    }
  9. 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.

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.

Documentation

Dependencies

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

Optional Dependencies

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.