Vendor lock

This commit is contained in:
2023-06-16 02:08:47 +00:00
parent 7933e70e90
commit 3351b92dd6
4099 changed files with 345789 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# Contributing
First of all, **thank you** for contributing!
Here are a few rules to follow in order to ease code reviews and merging:
- follow [PSR-1](http://www.php-fig.org/psr/1/) and [PSR-2](http://www.php-fig.org/psr/2/)
- run the test suite
- write (or update) unit tests when applicable
- write documentation for new features
- use [commit messages that make sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
One may ask you to [squash your commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) too. This is used to "clean" your pull request before merging it (we don't want commits such as `fix tests`, `fix 2`, `fix 3`, etc.).
When creating your pull request on GitHub, please write a description which gives the context and/or explains why you are creating it.

21
vendor/php-di/slim-bridge/LICENSE vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Matthieu Napoli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

119
vendor/php-di/slim-bridge/README.md vendored Normal file
View File

@ -0,0 +1,119 @@
# PHP-DI integration with Slim
This package configures Slim to work with the [PHP-DI container](http://php-di.org/).
[![Build Status](https://travis-ci.org/PHP-DI/Slim-Bridge.svg?branch=master)](https://travis-ci.org/PHP-DI/Slim-Bridge)
[![](https://img.shields.io/packagist/dt/php-di/slim-bridge.svg)](https://packagist.org/packages/php-di/slim-bridge)
The full documentation is here: **http://php-di.org/doc/frameworks/slim.html**
## Why?
### PHP-DI as a container
The most obvious difference with the default Slim installation is that you will be using PHP-DI as the container, which has the following benefits:
- [autowiring](http://php-di.org/doc/autowiring.html)
- powerful [configuration format](http://php-di.org/doc/php-definitions.html)
- support for [modular systems](http://php-di.org/doc/definition-overriding.html)
- ...
If you want to learn more about all that PHP-DI can offer [have a look at its introduction](http://php-di.org/).
### Controllers as services
While your controllers can be simple closures, you can also **write them as classes and have PHP-DI instantiate them only when they are called**:
```php
class UserController
{
private $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function delete($request, $response)
{
$this->userRepository->remove($request->getAttribute('id'));
$response->getBody()->write('User deleted');
return $response;
}
}
$app->delete('/user/{id}', ['UserController', 'delete']);
```
Dependencies can then be injected in your controller using [autowiring, PHP-DI config files or even annotations](http://php-di.org/doc/definition.html).
### Controller parameters
By default, Slim controllers have a strict signature: `$request, $response, $args`. The PHP-DI bridge offers a more flexible and developer friendly alternative.
Controller parameters can be any of these things:
- the request or response (parameters must be named `$request` or `$response`)
- route placeholders
- request attributes
- services (injected by type-hint)
You can mix all these types of parameters together too. They will be matched by priority in the order of the list above.
#### Request or response injection
You can inject the request or response in the controller parameters by name:
```php
$app->get('/', function (ResponseInterface $response, ServerRequestInterface $request) {
// ...
});
```
As you can see, the order of the parameters doesn't matter. That allows to skip injecting the `$request` if it's not needed for example.
#### Route placeholder injection
```php
$app->get('/hello/{name}', function ($name, ResponseInterface $response) {
$response->getBody()->write('Hello ' . $name);
return $response;
});
```
As you can see above, the route's URL contains a `name` placeholder. By simply adding a parameter **with the same name** to the controller, PHP-DI will directly inject it.
#### Request attribute injection
```php
$app->add(function ($request, $response, $next) {
$request = $request->withAttribute('name', 'Bob');
return $next($request, $response);
});
$app->get('/', function ($name, ResponseInterface $response) {
$response->getBody()->write('Hello ' . $name);
return $response;
});
```
As you can see above, a middleware sets a `name` attribute. By simply adding a parameter **with the same name** to the controller, PHP-DI will directly inject it.
#### Service injection
To inject services into your controllers, you can write them as classes. But if you want to write a micro-application using closures, you don't have to give up dependency injection either.
You can inject services by type-hinting them:
```php
$app->get('/', function (ResponseInterface $response, Twig $twig) {
return $twig->render($response, 'home.twig');
});
```
> Note: you can only inject services that you can type-hint and that PHP-DI can provide. Type-hint injection is simple, it simply injects the result of `$container->get(/* the type-hinted class */)`.
## Documentation
The documentation can be read here: **http://php-di.org/doc/frameworks/slim.html**

26
vendor/php-di/slim-bridge/composer.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"name": "php-di/slim-bridge",
"description": "PHP-DI integration in Slim",
"license": "MIT",
"type": "library",
"autoload": {
"psr-4": {
"DI\\Bridge\\Slim\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DI\\Bridge\\Slim\\Test\\": "tests/"
}
},
"require": {
"php": "~7.1",
"php-di/php-di": "^6.0.0",
"php-di/invoker": "^2.0.0",
"slim/slim": "^4.2.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0",
"zendframework/zend-diactoros": "^2.1"
}
}

View File

@ -0,0 +1,57 @@
<?php declare(strict_types=1);
namespace DI\Bridge\Slim;
use DI\Container;
use Invoker\Invoker;
use Invoker\ParameterResolver\AssociativeArrayResolver;
use Invoker\ParameterResolver\Container\TypeHintContainerResolver;
use Invoker\ParameterResolver\DefaultValueResolver;
use Invoker\ParameterResolver\ResolverChain;
use Psr\Container\ContainerInterface;
use Slim\App;
use Slim\Factory\AppFactory;
use \Invoker\CallableResolver as InvokerCallableResolver;
use Slim\Interfaces\CallableResolverInterface;
/**
* This factory creates a Slim application correctly configured with PHP-DI.
*
* To use this, replace `Slim\Factory\AppFactory::create()`
* with `DI\Bridge\Slim\Bridge::create()`.
*/
class Bridge
{
public static function create(ContainerInterface $container = null): App
{
$container = $container ?: new Container;
$callableResolver = new InvokerCallableResolver($container);
$container->set(CallableResolverInterface::class, new CallableResolver($callableResolver));
$app = AppFactory::createFromContainer($container);
$container->set(App::class, $app);
$controllerInvoker = self::createControllerInvoker($container);
$app->getRouteCollector()->setDefaultInvocationStrategy($controllerInvoker);
return $app;
}
private static function createControllerInvoker(ContainerInterface $container): ControllerInvoker
{
$resolvers = [
// Inject parameters by name first
new AssociativeArrayResolver(),
// Then inject services by type-hints for those that weren't resolved
new TypeHintContainerResolver($container),
// Then fall back on parameters default values for optional route parameters
new DefaultValueResolver(),
];
$invoker = new Invoker(new ResolverChain($resolvers), $container);
return new ControllerInvoker($invoker);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace DI\Bridge\Slim;
use Slim\Interfaces\CallableResolverInterface;
/**
* Resolve middleware and route callables using PHP-DI.
*/
class CallableResolver implements CallableResolverInterface
{
/**
* @var \Invoker\CallableResolver
*/
private $callableResolver;
public function __construct(\Invoker\CallableResolver $callableResolver)
{
$this->callableResolver = $callableResolver;
}
/**
* {@inheritdoc}
*/
public function resolve($toResolve): callable
{
return $this->callableResolver->resolve($toResolve);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace DI\Bridge\Slim;
use Invoker\InvokerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Interfaces\InvocationStrategyInterface;
class ControllerInvoker implements InvocationStrategyInterface
{
/**
* @var InvokerInterface
*/
private $invoker;
public function __construct(InvokerInterface $invoker)
{
$this->invoker = $invoker;
}
/**
* Invoke a route callable.
*
* @param callable $callable The callable to invoke using the strategy.
* @param ServerRequestInterface $request The request object.
* @param ResponseInterface $response The response object.
* @param array $routeArguments The route's placeholder arguments
*
* @return ResponseInterface|string The response from the callable.
*/
public function __invoke(
callable $callable,
ServerRequestInterface $request,
ResponseInterface $response,
array $routeArguments
): ResponseInterface {
// Inject the request and response by parameter name
$parameters = [
'request' => $request,
'response' => $response,
];
// Inject the route arguments by name
$parameters += $routeArguments;
// Inject the attributes defined on the request
$parameters += $request->getAttributes();
return $this->invoker->call($callable, $parameters);
}
}