I had the idea of writing a PHP Web framework about two or three years ago and tried to develop it in practice, but for various reasons it was never completed.

This time I finally settled down and took time off to build my own PHP microframework. After a month of piecemeal development, the document was not presented until today.

In addition to the framework itself (Coole) core code, but also provide a framework application (Coolephp /skeleton) template, in addition to the preparation of a simple document, hope to also want to write the framework of the people bring a reference (god please ignore).

The life cycle

  1. The client makes a request to the entry script index.php.
  2. Create an application in the entry script and register configuration services, core services, and third-party services with the application.
  3. Define the route and load it into the application.
  4. Start and run the application.
  5. Create the request object.
  6. The route is resolved based on the request object and the controller instance is created.
  7. Actions invoke model data, render to view, and generate response objects.
  8. Pipeline filter response.
  9. Returns the response to the client.
  10. Terminate the life cycle.

Command line interface

Install the framework

$ composer require guanguans/coole -vvv
Copy the code

Quick start


      

use Guanguans\Coole\App;
use Guanguans\Coole\Facade\Router;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/vendor/autoload.php';

// 1. Create an application
$app = new App();
$app['debug'] = true;

// 2. Define a route with middleware
Router::get('/'.function (){
    return 'This is the Coole framework.';
})->setMiddleware(function (Request $request.Closure $next){
    printf('Before request.<br>');
    $response = $next($request);
    printf('<br>After request.');

    return $response;
});

// 3
$app->run();
Copy the code

The components used by each functional responsibility in the framework

  • Guanguans/DI – Containers (a derivative of illuminate/ Container)
  • Symfony/HTTP-kernel-HTTP kernel
  • Symfony/HTTP-foundation – HTTP object management layer
  • Symfony/routing – routing
  • Symfony /event-dispatcher – Event dispatcher
  • Filp /whoops – Error handling
  • Symfony /error-handler – Error handling
  • Monolog/monolog – log
  • Mpociot/Pipeline – Middleware implementation
  • Symfony /console – Command line
  • Symfony/Finder – File management
  • topthink/think-orm – ORM
  • Twig/Twig – Template engine
  • vlucas/phpdotenv – env
  • Tightenco/collect – collection

Reference article and reference frame

  • Symfony.com/doc/current… – Recommended reading
  • Github.com/slimphp/Sli… – Almost all of the built-in components implement the PSR interface specification, which is sufficiently standardized.
  • Github.com/silexphp/Si…
  • Github.com/jadephp/jad… – Slince implements its own HTTP kernel
  • Github.com/laravel/fra…

The official documentation

  • www.guanguans.cn/coole

Source link

  • Github.com/guanguans/c… – Framework core code
  • Github.com/coolephp/sk… – Frame application template