/** * 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 use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; require 'errors.php'; require 'db.php'; require 'MonologProvider.php'; $container = new \Slim\Container(); $container->register(new MonologProvider()); $app = new \Slim\App($container); /** * Security checks before every request */ $app->add(function (Request $request, Response $response, $next) { if (!checkOriginHeaders($request)) { logger($this)->addError('Wrong origin', getPath($request)); return forbidden($response); } $response = $next($request, $response); return $response; }); /** * Serve index.html in the development mode */ $app->get('/', function (Request $request, Response $response) { $response->getBody()->write(file_get_contents("index.html")); }); // CUSTOMERS $app->get('/api/customers/profile', function (Request $request, Response $response) { try { $cookieParams = $request->getCookieParams();
<?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();
<?php require __DIR__ . '/../vendor/autoload.php'; define('APP_BASE', realpath(__DIR__ . DIRECTORY_SEPARATOR . '..')); session_start(); // Instantiate the container and inject settings $container = new \Slim\Container(); $container['settings'] = new \Slim\Collection(require __DIR__ . '/../config/app.php'); // Register Service Providers foreach ($container['settings']['services'] as $service) { if (is_string($service)) { $service = new $service(); } $container->register($service); } // Instantiate the app $app = new \Slim\App($container); // Register middleware require __DIR__ . '/../app/Http/middleware.php'; // Register routes require __DIR__ . '/../app/Http/routes.php'; return $app;
<?php // Define a working path defined('APP_PATH') || define('APP_PATH', dirname(__DIR__)); defined('ROOT_PATH') || define('ROOT_PATH', dirname(APP_PATH)); // Load all class require_once ROOT_PATH . '/vendor/autoload.php'; // Load application settings $settings = (require_once APP_PATH . '/config/app.php'); // Create container for application $container = new \Slim\Container($settings); // Register service providers & factories $container->register(new \App\Providers\LogServiceProvider()); $container->register(new \App\Providers\TwigServiceProvider()); $container->register(new \App\Providers\HttpCacheServiceProvider()); $container->register(new \App\Providers\AppServiceProvider()); // Create new application $app = new \Slim\App($container); // Register middlewares and routes require_once APP_PATH . '/config/routes.php'; return $app;
<?php use RandomLib\Factory as RandomLib; use Katanium\Helpers\Hash; use Katanium\Helpers\Validator; use Katanium\Mail\Mailer; $c = new \Slim\Container(); /** * Simply returns app-mode * * @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 */