mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-02-15 18:20:20 +00:00
Initial import
This commit is contained in:
commit
2295a33590
884 changed files with 93939 additions and 0 deletions
57
php/vendor/php-di/slim-bridge/src/Bridge.php
vendored
Normal file
57
php/vendor/php-di/slim-bridge/src/Bridge.php
vendored
Normal 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 = static::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);
|
||||
}
|
||||
}
|
||||
28
php/vendor/php-di/slim-bridge/src/CallableResolver.php
vendored
Normal file
28
php/vendor/php-di/slim-bridge/src/CallableResolver.php
vendored
Normal 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);
|
||||
}
|
||||
}
|
||||
49
php/vendor/php-di/slim-bridge/src/ControllerInvoker.php
vendored
Normal file
49
php/vendor/php-di/slim-bridge/src/ControllerInvoker.php
vendored
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue