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 yesterday

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 26% 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

2799d 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

[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[flarum/core

Delightfully simple forum software.

201.4M2.2k](/packages/flarum-core)[eliashaeussler/typo3-solver

Solver - Extends TYPO3's exception handling with AI generated solutions. Problems can also be solved from command line. Several OpenAI parameters are configurable and prompts and solution providers can be customized as desired.

302.1k](/packages/eliashaeussler-typo3-solver)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73147.2k29](/packages/jaxon-php-jaxon-core)[xima/xima-typo3-frontend-edit

This extension provides an edit button for editors within frontend content elements.

1412.9k](/packages/xima-xima-typo3-frontend-edit)

PHPackages © 2026

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