PHPackages                             cevantime/sherpa-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cevantime/sherpa-core

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cevantime/sherpa-core
=====================

Sherpa Core

0.0.1(7y ago)0841MITPHPPHP &gt;=7.2

Since Oct 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Cevantime/sherpa-core)[ Packagist](https://packagist.org/packages/cevantime/sherpa-core)[ RSS](/packages/cevantime-sherpa-core/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (9)Versions (2)Used By (1)

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](https://github.com/Cevantime/sherpa-framework).

Installation
------------

[](#installation)

Sherpa Core is installable via composer

```
composer require cevantime/sherpa
```

Getting Started
---------------

[](#getting-started)

Sherpa use psr-7 for HTTP messages. You can use Zend Diactoros implementation to build your Request in your index file.

```
// index.php
use Zend\Diactoros\ServerRequestFactory;

$request = ServerRequestFactory::fromGlobals();
```

Now, you can init the Sherpa Kernel

```
use Sherpa\Kernel\Kernel;
// ...
$app = new Kernel();
```

Now, you can add a little middleware to display a simple 'Hello Sherpa' :

```
use Zend\Diactoros\Response\HtmlResponse;
// ...
$app->pipe(function(){
    return new HtmlResponse("Hello Sherpa !");
});
```

The Kernel will handle the response for the request

```
$response = $app->handle($request);
```

When the response is ready, it needs to be emitted !

```
use Zend\Diactoros\Response\SapiEmitter;
// ...
(new SapiEmitter())->emit($response);
```

That's it ! Now visit your index file. You should see "Hello Sherpa !"

Middlewares
-----------

[](#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 :

```
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

$kernel->pipe(function(ServerRequestInterface $request, RequestHandlerInterface $handler) {
	// ...
});
```

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 !

```
$kernel->pipe(function(ServerRequestInterface $request, RequestHandlerInterface $handler) {
	// check if user tries to access an admin page and check if he is admin
	if(preg_match($request->getUri()->getPath(), '~^/admin~')
		&& ! $request->getAttribute('user')->isAdmin()) {
		// if not, send an error
		return (new Response('php://memory'))
			->withStatus(403, 'You are not allowed to enter !';
	}
	// otherwise, let the process continue and the next middleware proceed
	return $handler->handle($request);
});
```

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).

```
$kernel->pipe(function(){ return new Response(...); }, 50);
```

Container and Autowiring
------------------------

[](#container-and-autowiring)

Sherpa Core use [PHP DI Container](http://php-di.org/) 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 :

```
use function DI\get;
use function DI\create;
use Psr\Log\LoggerInterface;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Psr\Container\ContainerInterface;
//...
$builder = $kernel->getContainerBuilder();
$builder->addDefinitions([
        // create definition directly...
	'log.folder' => 'var/log',
	// ... or using a callback function...
	StreamHandler::class => function(ContainerInterface $container) {
		return new StreamHandler($container->get('log.folder');
	},
	// ... or using configuration methods that come with php di
	LoggerInterface::class => create(Logger::class)
		 ->constructor('mylogger')
		 ->method('pushHandler', get(StreamHandler::class))
]);
```

Now a logger is injectable anywhere, including a class middleware :

```
use App\UserRepository;
use Psr\Log\LoggerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use Psr\Http\Message\ResponseInterface as Response;

class UserMiddleware implements MiddlewareInterface
{
	protected $userRepository;
	protected $logger;

	/**
	 * @param UserRepository $userRepository is auto-injected !
	 * @param LoggerInterface $logger hase been configure to inject an instance of Logger
	 * /
	public function __construct(UserRepository $userRepository, LoggerInterface $logger)
	{
		$this->userRepository = $userRepository;
		$this->logger = $logger;
	}
	public function process(Request $request, Handler $handler): Response
	{
		$user = $this->userRepository->findBy(['id' => $_SESSION['user_id'] ?? 0]);
		if($user) {
			$request->setAttribute('user', $user);
		} else {
			$this->logger->log('info', 'No user found in session');
		}
		return $handler->handle($request);
	}
}
```

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.

```
$kernel->pipe(UserMiddleware::class);
```

Conclusion
----------

[](#conclusion)

This kernel is fairly minimal but it is a good starting point to build great applications with full psr compliance. [Sherpa Framework](https://github.com/Cevantime/sherpa-framework) is an example of how this kernel can be used.

###  Health Score

23

—

LowBetter than 25% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2845d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5015561?v=4)[Thibault Truffert](/maintainers/Cevantime)[@Cevantime](https://github.com/Cevantime)

---

Top Contributors

[![Cevantime](https://avatars.githubusercontent.com/u/5015561?v=4)](https://github.com/Cevantime "Cevantime (16 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cevantime-sherpa-core/health.svg)

```
[![Health](https://phpackages.com/badges/cevantime-sherpa-core/health.svg)](https://phpackages.com/packages/cevantime-sherpa-core)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k39.6k](/packages/matomo-matomo)[cakephp/cakephp

The CakePHP framework

8.9k20.0M1.8k](/packages/cakephp-cakephp)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.6k2.2M138](/packages/mcp-sdk)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[flarum/core

Delightfully simple forum software.

211.5M2.5k](/packages/flarum-core)[cakephp/authentication

Authentication plugin for CakePHP

1214.3M118](/packages/cakephp-authentication)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
