This class implements a pipeline of middleware, which can be attached using the pipe() method, and is itself middleware. The request and response objects are decorated using the Zend\Stratigility\Http variants in this package, ensuring that the request may store arbitrary properties, and the response exposes the convenience write(), end(), and isComplete() methods. It creates an instance of Next internally, invoking it with the provided request and response instances; if no $out argument is provided, it will create a FinalHandler instance and pass that to Next as well. Inspired by Sencha Connect.
See also: https://github.com/sencha/connect
Inheritance: implements Zend\Stratigility\MiddlewareInterface, implements Interop\Http\Middleware\ServerMiddlewareInterface
コード例 #1
0
ファイル: ComicsPage.php プロジェクト: vrkansagara/mwop.net
 public function __invoke(ContainerInterface $container) : callable
 {
     $pipeline = new MiddlewarePipe();
     $pipeline->pipe($container->get('Mwop\\Auth\\UserSession'));
     $pipeline->pipe(new Page($container->get(TemplateRendererInterface::class), $container->get(UnauthorizedResponseFactory::class)));
     return $pipeline;
 }
コード例 #2
0
ファイル: ComicsPage.php プロジェクト: bcremer/mwop.net
 public function __invoke($services)
 {
     $pipeline = new MiddlewarePipe();
     $pipeline->pipe($services->get('Mwop\\Auth\\UserSession'));
     $pipeline->pipe(new Page('mwop::comics.page', $services->get(TemplateRendererInterface::class)));
     return $pipeline;
 }
コード例 #3
0
 /**
  * Marshal a middleware pipe from an array of middleware.
  *
  * Each item in the array can be one of the following:
  *
  * - A callable middleware
  * - A string service name of middleware to retrieve from the container
  * - A string class name of a constructor-less middleware class to
  *   instantiate
  *
  * As each middleware is verified, it is piped to the middleware pipe.
  *
  * @param array $middlewares
  * @param null|ContainerInterface $container
  * @param bool $forError Whether or not the middleware pipe generated is
  *     intended to be populated with error middleware; defaults to false.
  * @return MiddlewarePipe
  * @throws Exception\InvalidMiddlewareException for any invalid middleware items.
  */
 private function marshalMiddlewarePipe(array $middlewares, ContainerInterface $container = null, $forError = false)
 {
     $middlewarePipe = new MiddlewarePipe();
     foreach ($middlewares as $middleware) {
         $middlewarePipe->pipe($this->prepareMiddleware($middleware, $container, $forError));
     }
     return $middlewarePipe;
 }
コード例 #4
0
ファイル: FullStackServer.php プロジェクト: Luceos/core
 /**
  * @param Application $app
  * @return \Zend\Stratigility\MiddlewareInterface
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     $pipe->pipe(new ApiServer());
     $pipe->pipe(new AdminServer());
     $pipe->pipe(new ForumServer());
     return $pipe;
 }
コード例 #5
0
ファイル: Performer.php プロジェクト: rostmefpoter/bh
 /**
  * @param Request $request
  * @param Response $response
  * @param callable|null $out
  * @return Response
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     foreach ($this->getMiddlewares($request, $response) as $middleware) {
         $this->pipe($middleware);
     }
     return parent::__invoke($request, $response, $out);
 }
コード例 #6
0
ファイル: RestRql.php プロジェクト: avz-cmf/zaboy-rest
 /**
  *
  * @param array $middlewares
  */
 public function __construct($middlewares)
 {
     parent::__construct();
     foreach ($middlewares as $middleware) {
         $this->pipe($middleware);
     }
 }
コード例 #7
0
 /**
  * @param AuthorizationServerInterface $authorizationServer
  */
 public function __construct(AuthorizationServerInterface $authorizationServer)
 {
     parent::__construct();
     $this->authorizationServer = $authorizationServer;
     $this->pipe('/authorize', [$this, 'handleAuthorizeRequest']);
     $this->pipe('/token', [$this, 'handleTokenRequest']);
     $this->pipe('/revoke', [$this, 'handleRevocationRequest']);
 }
コード例 #8
0
ファイル: Middleware.php プロジェクト: anctemarry27/cogs
 /**
  * @param RequestInterface|Request   $request
  * @param ResponseInterface|Response $response
  * @param callable|NULL              $next
  *
  * @return Response
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next = NULL)
 {
     /** @var Events $events - cache for event object */
     //static $events;
     //$events = $events ?: $this->forge->make('events');
     # TODO: Middleware Pre-Hook?
     # call the app middleware before event
     $this->events->fire(Application::NOTIFY_MIDDLEWARE, [$this, $request, $response]);
     # call parent middleware
     return parent::__invoke($this->decorateRequest($request), $this->decorateResponse($response), $next);
     # TODO: Middleware Post-Hook?
 }
コード例 #9
0
ファイル: Server.php プロジェクト: johnulist/core
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     if ($app->isInstalled()) {
         $app->register('Flarum\\Api\\ApiServiceProvider');
         $routes = $app->make('flarum.api.routes');
         $apiPath = parse_url($app->url('api'), PHP_URL_PATH);
         $pipe->pipe($apiPath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Api\\Middleware\\AuthenticateWithHeader'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Api\\Middleware\\FakeHttpMethods'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', compact('routes')));
         $pipe->pipe($apiPath, $app->make('Flarum\\Api\\Middleware\\HandleErrors'));
     }
     return $pipe;
 }
コード例 #10
0
ファイル: Server.php プロジェクト: ygbhf/flarum-full
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     if ($app->isInstalled()) {
         $adminPath = parse_url($app->url('admin'), PHP_URL_PATH);
         $errorDir = __DIR__ . '/../../error';
         if ($app->isUpToDate()) {
             $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie'));
             $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
             $pipe->pipe($adminPath, $app->make('Flarum\\Admin\\Middleware\\RequireAdministrateAbility'));
             $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')]));
             $pipe->pipe($adminPath, new HandleErrors($errorDir, $app->inDebugMode()));
         } else {
             $app->register('Flarum\\Update\\UpdateServiceProvider');
             $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.update.routes')]));
             $pipe->pipe($adminPath, new HandleErrors($errorDir, true));
         }
     }
     return $pipe;
 }
コード例 #11
0
ファイル: Server.php プロジェクト: ygbhf/flarum-full
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     $apiPath = parse_url($app->url('api'), PHP_URL_PATH);
     if ($app->isInstalled() && $app->isUpToDate()) {
         $pipe->pipe($apiPath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Api\\Middleware\\AuthenticateWithHeader'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Api\\Middleware\\FakeHttpMethods'));
         $pipe->pipe($apiPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.api.routes')]));
         $pipe->pipe($apiPath, $app->make('Flarum\\Api\\Middleware\\HandleErrors'));
     } else {
         $pipe->pipe($apiPath, function () {
             $document = new Document();
             $document->setErrors([['code' => 503, 'title' => 'Service Unavailable']]);
             return new JsonApiResponse($document, 503);
         });
     }
     return $pipe;
 }
コード例 #12
0
ファイル: Server.php プロジェクト: ygbhf/flarum-full
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     $basePath = parse_url($app->url(), PHP_URL_PATH);
     $errorDir = __DIR__ . '/../../error';
     if (!$app->isInstalled()) {
         $app->register('Flarum\\Install\\InstallServiceProvider');
         $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.install.routes')]));
         $pipe->pipe($basePath, new HandleErrors($errorDir, true));
     } elseif ($app->isUpToDate()) {
         $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie'));
         $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
         $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')]));
         $pipe->pipe($basePath, new HandleErrors($errorDir, $app->inDebugMode()));
     } else {
         $pipe->pipe($basePath, function () use($errorDir) {
             return new HtmlResponse(file_get_contents($errorDir . '/503.html', 503));
         });
     }
     return $pipe;
 }
コード例 #13
0
ファイル: Server.php プロジェクト: johnulist/core
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     if ($app->isInstalled()) {
         $app->register('Flarum\\Admin\\AdminServiceProvider');
         $adminPath = parse_url($app->url('admin'), PHP_URL_PATH);
         $routes = $app->make('flarum.admin.routes');
         $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie'));
         $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
         $pipe->pipe($adminPath, $app->make('Flarum\\Admin\\Middleware\\RequireAdministrateAbility'));
         $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', compact('routes')));
         $pipe->pipe(new HandleErrors(__DIR__ . '/../../error', $app->inDebugMode()));
     }
     return $pipe;
 }
コード例 #14
0
ファイル: Server.php プロジェクト: johnulist/core
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     $installed = $app->isInstalled();
     $basePath = parse_url($app->url(), PHP_URL_PATH);
     if ($installed) {
         $app->register('Flarum\\Forum\\ForumServiceProvider');
         $routes = $app->make('flarum.forum.routes');
         $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie'));
         $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
     } else {
         $app->register('Flarum\\Install\\InstallServiceProvider');
         $routes = $app->make('flarum.install.routes');
     }
     $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', compact('routes')));
     $pipe->pipe(new HandleErrors(__DIR__ . '/../../error', $app->inDebugMode() || !$installed));
     return $pipe;
 }
コード例 #15
0
ファイル: Server.php プロジェクト: Luceos/core
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     $path = parse_url($app->url(), PHP_URL_PATH);
     $errorDir = __DIR__ . '/../../error';
     if (!$app->isInstalled()) {
         $app->register('Flarum\\Install\\InstallServiceProvider');
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.install.routes')]));
         $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), true));
     } elseif ($app->isUpToDate() && !$app->isDownForMaintenance()) {
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale'));
         event(new ConfigureMiddleware($pipe, $path, $this));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')]));
         $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $app->inDebugMode()));
     } else {
         $pipe->pipe($path, function () use($errorDir) {
             return new HtmlResponse(file_get_contents($errorDir . '/503.html', 503));
         });
     }
     return $pipe;
 }
コード例 #16
0
ファイル: index.php プロジェクト: simukti/kadalkesit
<?php

use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Server;
use Middleware\RouteManager;
require_once __DIR__ . '/../vendor/autoload.php';
$app = new MiddlewarePipe();
$app->pipe(new RouteManager(require_once __DIR__ . '/../config/routes.php'));
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen();
コード例 #17
0
ファイル: index.php プロジェクト: avz-cmf/zaboy-res
    array(
        'driver' => 'Pdo_Mysql',
        'database' => 'zav_res',
        'username' => 'root',
        'password' => ''
     )
);
$qi = function($name) use ($adapter) { return $adapter->platform->quoteIdentifier($name); };
$fp = function($name) use ($adapter) { return $adapter->driver->formatParameterName($name); };
$statement = $adapter->query('SELECT * FROM '
    . $qi('res_test')
    . ' WHERE id = ' . $fp('val_id'));
$results = $statement->execute(array('val_id' => 3));
$row = $results->current();
$name = $row['notes'];
*/
$memory = $container->get('testMemory');
var_dump($memory);
$app = new MiddlewarePipe();
// Landing page
$app->pipe('/', function ($req, $res, $next) {
    if (!in_array($req->getUri()->getPath(), ['/', ''], true)) {
        return $next($req, $res);
    }
    return $res->end('Hello world!');
});
$restPipe = (new RestActionPipeFactory())->__invoke();
// Another page
$app->pipe('/rest', $restPipe);
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen();
コード例 #18
0
<?php

use Zend\Stratigility\MiddlewarePipe;
use Application\NotFound;
return call_user_func(function () {
    $services = (include 'config/services.php');
    $app = new MiddlewarePipe();
    // basics eg.redirect
    // site 1
    $app->pipe($services->get('application'));
    // errors
    $app->pipe(new NotFound());
    // authentication
    // error handler
    $app->pipe($services->get('ErrorHandler'));
    return $app;
});
コード例 #19
0
ファイル: Application.php プロジェクト: kynx/zend-expressive
 /**
  * Overload pipe() operation.
  *
  * Middleware piped may be either callables or service names. Middleware
  * specified as services will be wrapped in a closure similar to the
  * following:
  *
  * <code>
  * function ($request, $response, $next = null) use ($container, $middleware) {
  *     $invokable = $container->get($middleware);
  *     if (! is_callable($invokable)) {
  *         throw new Exception\InvalidMiddlewareException(sprintf(
  *             'Lazy-loaded middleware "%s" is not invokable',
  *             $middleware
  *         ));
  *     }
  *     return $invokable($request, $response, $next);
  * };
  * </code>
  *
  * This is done to delay fetching the middleware until it is actually used;
  * the upshot is that you will not be notified if the service is invalid to
  * use as middleware until runtime.
  *
  * Additionally, ensures that the route middleware is only ever registered
  * once.
  *
  * @param string|callable $path Either a URI path prefix, or middleware.
  * @param null|string|callable $middleware Middleware
  * @return self
  */
 public function pipe($path, $middleware = null)
 {
     // Lazy-load middleware from the container when possible
     $container = $this->container;
     if (null === $middleware && is_string($path) && $container && $container->has($path)) {
         $middleware = $this->marshalLazyMiddlewareService($path, $container);
         $path = '/';
     } elseif (is_string($middleware) && !is_callable($middleware) && $container && $container->has($middleware)) {
         $middleware = $this->marshalLazyMiddlewareService($middleware, $container);
     } elseif (null === $middleware && is_callable($path)) {
         $middleware = $path;
         $path = '/';
     }
     if ($middleware === [$this, 'routeMiddleware'] && $this->routeMiddlewareIsRegistered) {
         return $this;
     }
     parent::pipe($path, $middleware);
     if ($middleware === [$this, 'routeMiddleware']) {
         $this->routeMiddlewareIsRegistered = true;
     }
     return $this;
 }
コード例 #20
0
ファイル: admin.php プロジェクト: redstarxz/flarumone
<?php

/*
 * This file is part of Flarum.
 *
 * (c) Toby Zerner <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Flarum\Core;
use Flarum\Forum\Middleware\HandleErrors;
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
use Zend\Diactoros\Server;
use Zend\Stratigility\MiddlewarePipe;
$app = (require __DIR__ . '/flarum/bootstrap.php');
$app->register('Flarum\\Admin\\AdminServiceProvider');
$admin = new MiddlewarePipe();
$admin->pipe($app->make('Flarum\\Api\\Middleware\\ReadJsonParameters'));
$admin->pipe($app->make('Flarum\\Admin\\Middleware\\LoginWithCookieAndCheckAdmin'));
$adminPath = parse_url(Core::url('admin'), PHP_URL_PATH);
$router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.admin.routes')]);
$admin->pipe($adminPath, $router);
if (Core::inDebugMode()) {
    $admin->pipe(new WhoopsMiddleware());
} else {
    $admin->pipe(new HandleErrors(base_path('error')));
}
$server = Server::createServer($admin, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen();
コード例 #21
0
ファイル: index.php プロジェクト: redstarxz/flarumone
use Flarum\Forum\Middleware\HandleErrors;
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
use Zend\Diactoros\Server;
use Zend\Stratigility\MiddlewarePipe;
$app = (require __DIR__ . '/flarum/bootstrap.php');
// If Flarum's configuration exists, then we can assume that installation has
// been completed. We will set up a middleware pipe to route the request through
// to one of the main forum actions.
if (Core::isInstalled()) {
    $app->register('Flarum\\Forum\\ForumServiceProvider');
    $flarum = new MiddlewarePipe();
    $flarum->pipe($app->make('Flarum\\Forum\\Middleware\\LoginWithCookie'));
    $flarum->pipe($app->make('Flarum\\Api\\Middleware\\ReadJsonParameters'));
    $basePath = parse_url(Core::url(), PHP_URL_PATH);
    $router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.forum.routes')]);
    $flarum->pipe($basePath, $router);
    if (Core::inDebugMode()) {
        $flarum->pipe(new WhoopsMiddleware());
    } else {
        $flarum->pipe(new HandleErrors(base_path('error')));
    }
} else {
    $app->register('Flarum\\Install\\InstallServiceProvider');
    $flarum = new MiddlewarePipe();
    $basePath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    $router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.install.routes')]);
    $flarum->pipe($basePath, $router);
    $flarum->pipe(new WhoopsMiddleware());
}
$server = Server::createServer($flarum, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen();
コード例 #22
0
 /**
  * Pipe an error handler.
  *
  * Middleware piped may be either callables or service names. Middleware
  * specified as services will be wrapped in a closure similar to the
  * following:
  *
  * <code>
  * function ($error, $request, $response, $next) use ($container, $middleware) {
  *     $invokable = $container->get($middleware);
  *     if (! is_callable($invokable)) {
  *         throw new Exception\InvalidMiddlewareException(sprintf(
  *             'Lazy-loaded middleware "%s" is not invokable',
  *             $middleware
  *         ));
  *     }
  *     return $invokable($error, $request, $response, $next);
  * };
  * </code>
  *
  * This is done to delay fetching the middleware until it is actually used;
  * the upshot is that you will not be notified if the service is invalid to
  * use as middleware until runtime.
  *
  * Once middleware detection and wrapping (if necessary) is complete,
  * proxies to pipe().
  *
  * @param string|callable $path Either a URI path prefix, or middleware.
  * @param null|string|callable $middleware Middleware
  * @return self
  */
 public function pipeErrorHandler($path, $middleware = null)
 {
     if (null === $middleware) {
         $middleware = $this->prepareMiddleware($path, $this->container, $forError = true);
         $path = '/';
     }
     if (!is_callable($middleware) && (is_string($middleware) || is_array($middleware))) {
         $middleware = $this->prepareMiddleware($middleware, $this->container, $forError = true);
     }
     parent::pipe($path, $middleware);
     return $this;
 }
コード例 #23
0
 /**
  * Test that FinalHandler is passed the original response.
  *
  * Tests that MiddlewarePipe passes the original response passed to it when
  * creating the FinalHandler instance, and that FinalHandler compares the
  * response passed to it on invocation to its original response.
  *
  * If the two differ, the response passed during invocation should be
  * returned unmodified; this is an indication that a middleware has provided
  * a response, and is simply passing further up the chain to allow further
  * processing (e.g., to allow an application-wide logger at the end of the
  * request).
  *
  * @group nextChaining
  */
 public function testPassesOriginalResponseToFinalHandler()
 {
     $request = new Request([], [], 'http://local.example.com/foo', 'GET', 'php://memory');
     $response = new Response();
     $test = new Response();
     $pipeline = new MiddlewarePipe();
     $pipeline->pipe(function ($req, $res, $next) use($test) {
         return $next($req, $test);
     });
     // Pipeline MUST return response passed to $next if it differs from the
     // original.
     $result = $pipeline($request, $response);
     $this->assertSame($test, $result);
 }
コード例 #24
0
ファイル: api.php プロジェクト: ncusoho/flarum
<?php

/*
 * This file is part of Flarum.
 *
 * (c) Toby Zerner <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Flarum\Api\Middleware\JsonApiErrors;
use Flarum\Core;
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
use Zend\Diactoros\Server;
use Zend\Stratigility\MiddlewarePipe;
$app = (require __DIR__ . '/flarum/bootstrap.php');
$app->register('Flarum\\Api\\ApiServiceProvider');
$api = new MiddlewarePipe();
$api->pipe($app->make('Flarum\\Api\\Middleware\\ReadJsonParameters'));
$api->pipe($app->make('Flarum\\Api\\Middleware\\LoginWithHeader'));
$apiPath = parse_url(Core::url('api'), PHP_URL_PATH);
$router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.api.routes')]);
$api->pipe($apiPath, $router);
if (Core::inDebugMode()) {
    $api->pipe(new WhoopsMiddleware());
} else {
    $api->pipe(new JsonApiErrors());
}
$server = Server::createServer($api, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen();
コード例 #25
0
ファイル: Server.php プロジェクト: hyn/laravel-flarum
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     $path = config('hyn.laravel-flarum.paths.api');
     //        if ($app->isInstalled() && $app->isUpToDate()) {
     $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
     $pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\FakeHttpMethods'));
     $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
     $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie'));
     $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession'));
     $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithHeader'));
     $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale'));
     event(new ConfigureMiddleware($pipe, $path, $this));
     $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.api.routes')]));
     $pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\HandleErrors'));
     //        } else {
     //            $pipe->pipe($path, function () {
     //                $document = new Document;
     //                $document->setErrors([
     //                    [
     //                        'code' => 503,
     //                        'title' => 'Service Unavailable'
     //                    ]
     //                ]);
     //
     //                return new JsonApiResponse($document, 503);
     //            });
     //        }
     return $pipe;
 }
コード例 #26
0
ファイル: index.php プロジェクト: avz-cmf/zaboy-middleware
<?php

// Change to the project root, to simplify resolving paths
chdir(dirname(__DIR__));
// Setup autoloading
require '/vendor/autoload.php';
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Server;
use zaboy\middleware\Middleware;
$container = (include 'config/container.php');
$app = new MiddlewarePipe();
$head = new MiddlewarePipe();
$head->pipe('/', new Middleware\HTML\Head());
$head->pipe('/', new Middleware\Dojo\DojoInHead());
$head->pipe('/', new Middleware\Dojo\Grid\GetAllRequestHeaders());
$head->pipe('/', new Middleware\Dojo\Grid\GetAllAllType());
$head->pipe('/', new Middleware\Returner());
$app->pipe('/HTML', $head);
$app->pipe('/HTML', new Middleware\HTML\Html());
$app->pipe('/HTML', new Middleware\HTML\Body());
//$app->pipe('/', new Middleware\WriteURI());
$app->pipe('/HTML', new Middleware\Rql\RqlParser());
$app->pipe('/GetAllRequestHeaders', new Middleware\API\Get\GetAllRequestHeaders());
$app->pipe('/AllType', $container->get('GetAllAllType'));
$rest = new MiddlewarePipe();
//set Attribute 'Resource-Name'
//It can do router if you use zend-expressive
$rest->pipe('/', new Middleware\ResourceResolver());
$restMiddlewareLazy = function ($request, $response, $next = null) use($container) {
    $resourceName = $request->getAttribute('Resource-Name');
    $restActionPipeFactory = new RestActionPipeFactory();
コード例 #27
0
ファイル: ConfigureMiddleware.php プロジェクト: flarum/core
 public function pipe(callable $middleware)
 {
     $this->pipe->pipe($this->path, $middleware);
 }
コード例 #28
0
 /**
  * Marshal a middleware pipe from an array of middleware.
  *
  * Each item in the array can be one of the following:
  *
  * - A callable middleware
  * - A string service name of middleware to retrieve from the container
  * - A string class name of a constructor-less middleware class to
  *   instantiate
  *
  * As each middleware is verified, it is piped to the middleware pipe.
  *
  * @param array $middlewares
  * @return MiddlewarePipe
  * @throws Exception\InvalidMiddlewareException for any invalid middleware items.
  */
 private function marshalMiddlewarePipe(array $middlewares)
 {
     $middlewarePipe = new MiddlewarePipe();
     foreach ($middlewares as $middleware) {
         $middlewarePipe->pipe($this->marshalMiddleware($middleware));
     }
     return $middlewarePipe;
 }
コード例 #29
0
ファイル: Router.php プロジェクト: spiffyjr/tonis
 /**
  * @param string|callable $pathOrMiddleware
  * @param null|callable $middleware
  */
 public function add($pathOrMiddleware, $middleware = null)
 {
     $this->pipe->pipe($pathOrMiddleware, $middleware);
 }
コード例 #30
0
 /**
  * Overload pipe() operation
  *
  * Ensures that the route middleware is only ever registered once.
  *
  * @param string|callable|object $path Either a URI path prefix, or middleware.
  * @param null|callable|object $middleware Middleware
  * @return self
  */
 public function pipe($path, $middleware = null)
 {
     if (null === $middleware && is_callable($path)) {
         $middleware = $path;
         $path = '/';
     }
     if ($middleware === [$this, 'routeMiddleware'] && $this->routeMiddlewareIsRegistered) {
         return $this;
     }
     parent::pipe($path, $middleware);
     if ($middleware === [$this, 'routeMiddleware']) {
         $this->routeMiddlewareIsRegistered = true;
     }
     return $this;
 }