Download the PHP package cevantime/sherpa-core without Composer
On this page you can find all versions of the php package cevantime/sherpa-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sherpa-core
Sherpa Core
A basic core class to build psr compliant applicationswith ease. The code is intentionnally minimal. For a more integrated experience, see Sherpa Framework.
Installation
Sherpa Core is installable via composer
Getting Started
Sherpa use psr-7 for HTTP messages. You can use Zend Diactoros implementation to build your Request in your index file.
Now, you can init the Sherpa Kernel
Now, you can add a little middleware to display a simple 'Hello Sherpa' :
The Kernel will handle the response for the request
When the response is ready, it needs to be emitted !
That's it ! Now visit your index file. You should see "Hello Sherpa !"
Middlewares
Sherpa Core do his best to be compliant with psr7 and psr-15 recommandations. Those recommendations introduces the usage of Message Interface and Middlewares. Piping middlewares in the Kernel is pretty simple :
Accordingly to the specifications, middlewares must return an instance of Psr\Http\Message\ResponseInterface
. It can do so by :
- Delegating the Response creation to the next middleware by calling
$handler->handle($request)
and eventually modify the response. - Generate his own Response and bypass the next Middlewares.
Here is a (imaginary) examplen that check if we are visiting an admin uri and prevent user that are not admin to enter !
Optionnally (but it is worth noting it !) an integer can be provided as second param in order to set a priority for the middleware (higher comes before).
Container and Autowiring
Sherpa Core use PHP DI Container as a Dependency Container and Dependency Injector. This package lets you inject any class of your project (even your vendor) with minimal configuration. Every type hinted parameter can be injected. You only need to configure parameters than can't be guessed by type hinting. Classes that are defined using class/interface names as keys will become injectable :
Now a logger is injectable anywhere, including a class middleware :
The Kernel will use di container to inject the middleware in the middleware stack. Thus you can pipe middlewares by only providing their class names.
Conclusion
This kernel is fairly minimal but it is a good starting point to build great applications with full psr compliance. Sherpa Framework is an example of how this kernel can be used.
All versions of sherpa-core with dependencies
psr/http-server-middleware Version ~1.0
psr/http-server-handler Version ~1.0
symfony/event-dispatcher Version ^4.0
zendframework/zend-diactoros Version ~1.0
doctrine/cache Version ~1.4
php-di/php-di Version ^6.0
php Version >=7.2