teknoo / east-foundation
East Foundation is a universal package to implement the #east philosophy ( http://blog.est.voyage/phpTour2015/ ) with any framework supporting PSR-11 or with Symfony 4+.
Fund package maintenance!
Patreon
TeknooSoftware
Installs: 11 752
Dependents: 4
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- ext-json: *
- php-di/php-di: ^6.3
- psr/container: ^1.0||^2.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
- teknoo/immutable: ^3.0.1
- teknoo/recipe: ^4.1.2
- teknoo/states: ^6.0.1
Requires (Dev)
- behat/behat: ^3.10
- laminas/laminas-diactoros: ^2.9
- nikic/php-parser: ^v4.13.2
- phploc/phploc: ^7.0.2
- phpstan/phpstan: ^1.5.4
- phpunit/phpunit: ^9.5.20
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^6.0.3
- squizlabs/php_codesniffer: ^3.6.2
- symfony/config: ^6.0
- symfony/console: ^6.0
- symfony/dependency-injection: ^6.0
- symfony/framework-bundle: ^6.0
- symfony/http-foundation: ^6.0
- symfony/http-kernel: ^6.0
- symfony/messenger: ^6.0
- symfony/psr-http-message-bridge: ^2.1
- symfony/routing: ^6.0
- symfony/security-core: ^6.0
- symfony/serializer: ^6.0.3
- symfony/yaml: ^6.0
- twig/twig: ^3.3
- dev-master
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.3.11
- 5.3.10
- 5.3.9
- 5.3.7
- 5.3.6
- 5.3.5
- 5.3.4
- 5.3.3
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.0
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.3
- 4.0.2
- 4.0.1
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.2.0-beta5
- 3.2.0-beta4
- 3.2.0-beta3
- 3.2.0-beta2
- 3.2.0-beta1
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-beta2
- 3.0.0-beta1
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.1.0-beta5
- 2.1.0-beta4
- 2.1.0-beta3
- 2.1.0-beta2
- 2.1.0-beta1
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-beta9
- 2.0.0-beta8
- 2.0.0-beta7
- 2.0.0-beta6
- 2.0.0-beta5
- 2.0.0-beta4
- 2.0.0-beta3
- 2.0.0-beta1
- 1.0.2
- 1.0.1
- 1.0.0
- 0.0.11
- 0.0.10
- 0.0.9
- 0.0.8
- 0.0.8-beta3
- 0.0.8-beta2
- 0.0.8-beta1
- 0.0.7
- 0.0.7-beta6
- 0.0.7-beta5
- 0.0.7-beta4
- 0.0.7-beta3
- 0.0.7-beta2
- 0.0.7-beta1
- 0.0.6
- 0.0.5
- 0.0.5-beta10
- 0.0.5-beta9
- 0.0.5-beta8
- 0.0.5-beta7
- 0.0.5-beta6
- 0.0.5-beta5
- 0.0.5-beta4
- 0.0.5-beta3
- 0.0.5-beta2
- 0.0.5-beta1
- 0.0.4
- 0.0.4-beta2
- 0.0.4-beta1
- 0.0.4-alpha13
- 0.0.4-alpha12
- 0.0.4-alpha11
- 0.0.4-alpha10
- 0.0.4-alpha9
- 0.0.4-alpha8
- 0.0.4-alpha7
- 0.0.4-alpha6
- 0.0.4-alpha5
- 0.0.4-alpha4
- 0.0.4-alpha3
- 0.0.4-alpha2
- 0.0.4-alpha1
- 0.0.3
- 0.0.2
- 0.0.1
- 0.0.1-alpha3
- 0.0.1-alpha2
- 0.0.1-alpha1
This package is auto-updated.
Last update: 2022-05-25 20:03:21 UTC
README
East Foundation is a universal package to implement the #east philosophy with any framework supporting PSR-11 or with Symfony 6.0+. : All public method of objects must return $this or a new instance of $this.
This bundle uses PSR7 requests and responses and do automatically the conversion from Symfony's requests and responses. So your controllers and services can be independent of Symfony. This bundle reuse internally Symfony's components to manage routes and find controller to call.
Quick Example
<?php
declare(strict_types=1);
use Psr\Http\Message\MessageInterface;
use Teknoo\East\Foundation\Client\ResponseInterface;
use Teknoo\East\Foundation\Router\ResultInterface;
use DI\ContainerBuilder;
use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\Response\TextResponse;
use Teknoo\East\Foundation\Client\ClientInterface;
use Teknoo\East\Foundation\Manager\ManagerInterface;
use Teknoo\East\Foundation\Middleware\MiddlewareInterface;
use Teknoo\East\Foundation\Recipe\RecipeInterface;
use Teknoo\East\Foundation\Router\Result;
use Teknoo\East\Foundation\Router\RouterInterface;
use function DI\decorate;
require_once 'vendor/autoload.php';
//Simulate client, accepts responses from controller and pass them to the "framework" or lower layer to send them to
//the browser.
$client = new class implements ClientInterface {
private ResponseInterface | MessageInterface | null $response = null;
private bool $inSilentlyMode = false;
public function updateResponse(callable $modifier): ClientInterface
{
$modifier($this, $this->response);
return $this;
}
public function acceptResponse(ResponseInterface | MessageInterface $response): ClientInterface
{
$this->response = $response;
return $this;
}
public function sendResponse(
ResponseInterface | MessageInterface | null $response = null,
bool $silently = false
): ClientInterface
{
$silently = $silently || $this->inSilentlyMode;
if (null !== $response) {
$this->acceptResponse($response);
}
if (true === $silently && null === $this->response) {
return $this;
}
if ($this->response instanceof MessageInterface) {
print $this->response->getBody() . PHP_EOL;
} else {
print $this->response . PHP_EOL;
}
return $this;
}
public function errorInRequest(Throwable $throwable, bool $silently = false): ClientInterface
{
print $throwable->getMessage() . PHP_EOL;
return $this;
}
public function mustSendAResponse(): ClientInterface
{
$this->inSilentlyMode = false;
return $this;
}
public function sendAResponseIsOptional(): ClientInterface
{
$this->inSilentlyMode = true;
return $this;
}
};
//First controller / endpoint, dedicated for the request /foo
$endPoint1 = static function (MessageInterface $message, ClientInterface $client) {
$client->sendResponse(
new TextResponse('request /bar, endpoint 1, value : ' . $message->getQueryParams()['value'])
);
};
//Second controller / endpoint, dedicated for the request /bar
$endPoint2 = static function (ClientInterface $client, string $value) {
$client->sendResponse(
new class ($value) implements ResponseInterface {
public function __construct(
private string $value,
) {
}
public function __toString()
{
return "request /bar, endpoint 2, value : {$this->value}";
}
}
);
};
/**
* Simulate router
*/
$router = new class($endPoint1, $endPoint2) implements RouterInterface {
/**
* @var callable
*/
private $endPoint1;
/**
* @var callable
*/
private $endPoint2;
public function __construct(callable $endPoint1 , callable $endPoint2)
{
$this->endPoint1 = $endPoint1;
$this->endPoint2 = $endPoint2;
}
public function execute(
ClientInterface $client ,
MessageInterface $message,
ManagerInterface $manager
): MiddlewareInterface
{
$uri = (string) $message->getUri();
$manager->updateWorkPlan([
ResultInterface::class => match ($uri) {
'/foo' => new Result($this->endPoint1),
'/bar' => new Result($this->endPoint2),
},
]);
$manager->continueExecution($client, $message);
return $this;
}
};
$builder = new ContainerBuilder();
$builder->addDefinitions('src/di.php');
$builder->addDefinitions([
RouterInterface::class => $router,
RecipeInterface::class => decorate(function ($previous) use ($router) {
if ($previous instanceof RecipeInterface) {
$previous = $previous->registerMiddleware(
$router,
RouterInterface::MIDDLEWARE_PRIORITY
);
}
return $previous;
})
]);
$container = $builder->build();
//Simulate Server request reception
$request1 = new ServerRequest([], [], '/foo', 'GET');
$request1 = $request1->withQueryParams(['value' => 'bar']);
$request2 = new ServerRequest([], [], '/bar', 'GET');
$request2 = $request2->withQueryParams(['value' => 'foo']);
$manager = $container->get(ManagerInterface::class);
$manager->receiveRequest($client, $request1);
//Print: request /bar, endpoint 1, value : bar
$manager->receiveRequest($client, $request2);
//Print: request /bar, endpoint 2, value : foo
Support this project
This project is free and will remain free, but it is developed on my personal time. If you like it and help me maintain it and evolve it, don't hesitate to support me on Patreon. Thanks :) Richard.
Installation & Requirements
To install this library with composer, run this command :
composer require teknoo/east-foundation
To install with Symfony
composer require teknoo/composer-install
composer require teknoo/east-foundation-symfony
This library requires :
* PHP 8.1+
* A PHP autoloader (Composer is recommended)
* Teknoo/Immutable.
* Teknoo/States.
* Teknoo/Recipe.
* Optional: Symfony 6.0+
News from Teknoo East Foundation 6.0
This library requires PHP 8.1 or newer and it's only compatible with Symfony 6.1 or newer :
- Constants are final in
SessionMiddleware
, processors, routers and sessions components. - Use readonly for immutables objects (
Processor
and routers' results). - Support Fibers in main
Cookbook
andRecipeEndPoint
.RecipeEndPoint
accepts also bowl andFiberRecipeBowl
. - Remove support of PHP 8.0 and Symfony 5.4 and below.
News from Teknoo East Foundation 5.0
This library requires PHP 8.0 or newer and it's only compatible with Symfony 5.2 or newer :
- Migrate to PHP 8.0+
- Remove support of Symfony 4.4, only 5.2+
- Constructor Property Promotion
- Non-capturing catches
- switch to str_contains
- Messenger's executor use an empty manager and clone it
- Add method to configure client's behavior when a it must send a missing response (silently or throw an exception)
- Add
ClientInterface::mustSendAResponse
- Add
ClientInterface::sendAResponseIsOptional
- Processor will configure in non silent mode if a compatible callable is available and was returned by Router
- This behavior can be disable by set
teknoo.east.client.must_send_response
to false in DI - Move ClientInterface to
Teknoo\East\Foundation\Client
fromTeknoo\East\Foundation\Http
- Add
Teknoo\East\Foundation\Client\ResultInterface
ClientInterface
accept also ResultInterface instead PSR's message- All clients implementations adopts new client interfaces
- Symfony Clients implementations supports
ResultInterface
andJsonSerializable
responses
News from Teknoo East Foundation 4.0
This library requires PHP 7.4 or newer and it's only compatible with Symfony 4.4 or newer :
- Switch to States 4.1.9 and PHPStan 0.12.79
- Prepare library to be used in non HTTP context
- Use MessageInterface instead of ServerRequestInterface
- Cookbook and ProcessorCookbook use BaseCookbookTrait
- Add PSR11 Message only implementation
- Add MessageFactory
- Update Client Interface to use MessageInterface instead of RequestInterface
- Add Recipe executor dedicated to Symfony Messenger
- Add Client dedicated to Symfony Messenger
- Remove some public services
News from Teknoo East Foundation 3.0
This library requires PHP 7.4 or newer and it's only compatible with Symfony 4.4 or newer :
- Remove Symfony Template component (integration deprecated into symfony)
- Create EngineInterface to allow creation of adapter to any templating Engine
- Create ResultInterface to allow asynchrone template rendering for callback streaming
- Create Twig Engine implementing EngineInterface and ResultInterface
- Remove 'east.controller.service' tag (not used)
- Add east.endpoint.template to inject Twig engine adapter
- Fix services definitions
- Complete tests
- Migrate universal folder in src to src's root and remove legacy support
News from Teknoo East Foundation 2.0
This library requires PHP 7.4 or newer and it's only compatible with Symfony 4.4 or newer :
- PHP 7.4 is the minimum required
- Switch to typed properties
- Remove some PHP useless DockBlocks
- Replace array_merge by "..." operators for integer indexed arrays
- Support zendframework/zend-diactoros 2.2
- Restrict to Symfony 4.4 or 5.+ and remove some deprecated
- Set
Teknoo\East\Foundation\Manager\ManagerInterface
andTeknoo\East\Foundation\Http\ClientInterface
as synthetic services into Symfony's services definitions to avoid compilation error with Symfony 4.4 - Set
Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory
into Symfony's services definitions to avoid compilation error with Symfony 4.4 - Enable PHPStan in QA Tools and disable PHPMD
Credits
Richard Déloge - richarddeloge@gmail.com - Lead developer. Teknoo Software - http://teknoo.software
About Teknoo Software
Teknoo Software is a PHP software editor, founded by Richard Déloge. Teknoo Software's DNA is simple : Provide to our partners and to the community a set of high quality services or software, sharing knowledge and skills.
License
East Foundation is licensed under the MIT License - see the licenses folder for details
Contribute :)
You are welcome to contribute to this project. Fork it on Github