/** * Handle a call to the app * * @param string $method GET/POST * @param string $path URI * @param array $options */ public function request($method, $path, $options = []) { ob_start(); $settings = (require __DIR__ . '/../../lib/settings.php'); $container = new \Slim\Container($settings); require __DIR__ . '/../../lib/containers.php'; $container->get('environment')['REQUEST_URI'] = $path; $container->get('environment')['REQUEST_METHOD'] = $method; // Set up custom 404 so that we can easilly check if the page wasn't found $container['notFoundHandler'] = function ($container) { return function ($request, $response) use($container) { return $container['response']->withStatus(404)->withHeader('Content-Type', 'text/plain')->write('Page not found'); }; }; $sentinel = m::mock('sentinel'); $container['sentinel'] = function ($container) use($sentinel) { return $sentinel; }; $app = new \Slim\App($container); // Set up dependencies require __DIR__ . '/../../lib/dependencies.php'; // Register middleware require __DIR__ . '/../../lib/middleware.php'; // Register routes require __DIR__ . '/../../lib/routes.php'; $app->run(); $this->app = $app; $this->request = $app->getContainer()->request; $this->response = $app->getContainer()->response; $this->page = ob_get_clean(); }
/** * Returns a response with redirection to the login page. * When redirecting to the login page, the URL carries a query containing the original's request target. * This should be used by the login process to resume the original flow after a successful login. * * @return Psr\Http\Message\ResponseInterface */ public function redirectToLogin($resume = false) { $uri = $resume; if ($uri == false) { $uri = $this->container->get('request')->getUri(); } $loginUrl = "{$this->urlRoot}/auth/login?resume={$uri}"; return $this->container->get('response')->withRedirect($loginUrl); }
<?php $container = new Slim\Container((new SlimApi\Module())->loadDependencies()); foreach ($container->get('slim-api')['modules'] as $moduleNamespace) { $container->get($moduleNamespace . '\\Init'); } require 'application.php';
<?php require __DIR__ . '/../vendor/autoload.php'; $capsule = new \Illuminate\Database\Capsule\Manager(); $capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../data/database.db']); $capsule->bootEloquent(); // Instantiate the app $settings = (require __DIR__ . '/../lib/settings.php'); // Set up containers $container = new \Slim\Container($settings); require __DIR__ . '/../lib/containers.php'; $container->get('environment')['REQUEST_URI'] = $argv[1]; $container->get('environment')['REQUEST_METHOD'] = 'GET'; // Start the app $app = new \Slim\App($container); // Set up dependencies require __DIR__ . '/../lib/dependencies.php'; // Register middleware require __DIR__ . '/../lib/middleware.php'; // Register routes require __DIR__ . '/../lib/routes_cli.php'; // Run app $app->run();
* * @return srtring */ $c['mode'] = function ($c) { return 'development'; }; /** * Get configurations * * the functions inside refer to the two files * included at the parameter * * @return array */ $c['myConfig'] = function ($c) { return new \Noodlehaus\Config($c->get('mode') === 'development' ? 'config/development.php' : 'config/production.php'); }; /** * Get Slim Setting * * @return array */ $c['settings'] = function ($c) { return ['httpVersion' => '1.1', 'responseChunkSize' => 4096, 'outputBuffering' => 'append', 'determineRouteBeforeAppMiddleware' => false, 'displayErrorDetails' => $c->get('mode') === 'development' ? true : false]; }; /** * Register CSRF Guard * * @return \Guard */ $c['csrf'] = function ($c) {