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
- The client makes a request to the entry script index.php.
- Create an application in the entry script and register configuration services, core services, and third-party services with the application.
- Define the route and load it into the application.
- Start and run the application.
- Create the request object.
- The route is resolved based on the request object and the controller instance is created.
- Actions invoke model data, render to view, and generate response objects.
- Pipeline filter response.
- Returns the response to the client.
- 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