php Slim-App类(方法)实例源码

下面列出了php Slim-App 类(方法)源码代码实例,从而了解它的用法。

作者:COCAFoundatio    项目:coca_hel   
/**
  * Process the application given a request method and URI
  *
  * @param string $requestMethod the request method (e.g. GET, POST, etc.)
  * @param string $requestUri the request URI
  * @param array|object|null $requestData the request data
  * @return \Slim\Http\Response
  */
 public function runApp($requestMethod, $requestUri, $requestData = null)
 {
     // Create a mock environment for testing with
     $environment = Environment::mock(['REQUEST_METHOD' => $requestMethod, 'REQUEST_URI' => $requestUri]);
     // Set up a request object based on the environment
     $request = Request::createFromEnvironment($environment);
     // Add request data, if it exists
     if (isset($requestData)) {
         $request = $request->withParsedBody($requestData);
     }
     // Set up a response object
     $response = new Response();
     // Use the application settings
     $settings = (require __DIR__ . '/../../src/settings.php');
     // Instantiate the application
     $app = new App($settings);
     // Set up dependencies
     require __DIR__ . '/../../src/dependencies.php';
     // Register middleware
     if ($this->withMiddleware) {
         require __DIR__ . '/../../src/middleware.php';
     }
     // Register routes
     require __DIR__ . '/../../src/routes.php';
     // Process the application
     $response = $app->process($request, $response);
     // Return the response
     return $response;
 }

作者:postalservice1    项目:sainsburys-http-servic   
/**
  * @param SlimApp $slimApp
  * @return SlimRoute
  */
 private function getSlimRouteFromApplication(SlimApp $slimApp)
 {
     $slimRouter = $slimApp->getContainer()->get('router');
     /** @var $slimRouter SlimRouter */
     $slimRoutes = $slimRouter->getRoutes();
     return $slimRoutes['route0'];
 }

作者:iceberg    项目:service-sli   
public function load(array $settings = [])
 {
     $service = new SlimApp($settings);
     $provider = new ServiceProvider();
     $provider->register($service->getContainer());
     $this->setService($service);
 }

作者:postalservice1    项目:sainsburys-http-servic   
private function hasRoutesConfigured() : bool
 {
     $slimContainer = $this->slimApp->getContainer();
     $slimRouter = $slimContainer->get('router');
     /** @var $slimRouter SlimRouter */
     return (bool) count($slimRouter->getRoutes());
 }

作者:lacteosdelcesa    项目:s3-untitledApi-   
public function __construct(App $app)
 {
     $app->group('/periodos', function () {
         $this->get('/actual', RetriveActualAction::class);
         $this->get('/{anio}', RetrivePeriodosDelAnio::class);
     });
 }

作者:onigoet    项目:imagecach   
public static function register(App $app, $config)
 {
     $app->getContainer()['imagecache'] = function () use($config) {
         return new Manager($config);
     };
     $app->get("/{$config['path_web']}/{$config['path_cache']}/{preset}/{file:.*}", (new ImagecacheRegister())->request())->setName('onigoetz.imagecache');
 }

作者:martynbi    项目:slim-modul   
/**
  * Load the module. This will run for all modules, use for routes mainly
  * @param string $moduleName Module name
  */
 public function initModules(App $app)
 {
     $container = $app->getContainer();
     $this->initDependencies($container);
     $this->initMiddleware($app);
     $this->initRoutes($app);
 }

作者:raistlfire    项目:slim-skeleto   
public function setUp()
 {
     $app = new App();
     $kernel = new Kernel($app, $app->getContainer());
     $kernel->registerServices();
     $kernel->registerRoutes();
     $this->app = $app;
 }

作者:skylin    项目:slim-MV   
function __construct(\Slim\App $app, RequestInterface $request, ResponseInterface $response, $args = false)
 {
     $this->app = $app;
     $this->container = $app->getContainer();
     $this->request = $request;
     $this->response = $response;
     $this->args = $args;
 }

作者:erdemec    项目:news-websit   
public function __construct(\Slim\App $app)
 {
     $this->app = $app;
     $this->view = $app->getContainer()->get('view');
     $this->pdo = $app->getContainer()->get('pdo');
     if (!$this->pdo instanceof PDO) {
         throw new \RuntimeException(sprintf('%s requires a PDO instance, app did not contain "PDO" key', __CLASS__));
     }
 }

作者:i4j    项目:burgermaniy   
public function init(\Slim\App $app)
 {
     $app->group('/categories', function () {
         $this->get('', '\\Controllers\\Categories:index');
         $this->map(['GET', 'POST'], '/created', '\\Controllers\\Categories:created');
         $this->map(['GET', 'POST'], '/edit/{id}', '\\Controllers\\Categories:edit');
         $this->map(['GET', 'POST'], '/delete/{id}', '\\Controllers\\Categories:delete');
     });
 }

作者:PaulJuli    项目:php-slim-echo-grove   
public static function Route()
 {
     $app = new App();
     // Reminder: the request is processed from the bottom up,
     // the response is processed from the top down.
     $app->add(SlimMiddleware::class);
     $app->add(Grover::class);
     $app->run();
 }

作者:asaokame    项目:slim-tuu   
/**
  * @param String $method
  * @param Uri   $uri
  * @param array $post
  */
 protected function runApp($method, $uri, $post = [])
 {
     $this->buildApp();
     $this->buildRequest($method, $uri, $post);
     $this->app->getContainer()['request'] = $this->request;
     $this->app->getContainer()['response'] = $this->response;
     $this->response = $this->app->run(true);
     $this->response->getBody()->rewind();
     $this->html = $this->response->getBody()->getContents();
 }

作者:mroswal    项目:invm   
public function register(App &$app)
 {
     $app->get('/version', function (Request $request, Response $response) {
         $response->getBody()->write(json_encode("v1.0.0"));
         return $response->withHeader('Access-Control-Allow-Origin', '*');
     });
     $app->options('/version', function (Request $request, Response $response, $args) use(&$self) {
         return $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', 'Content-Type');
     });
 }

作者:SharkIn    项目:ss-pane   
public function newApp()
 {
     // config
     $debug = false;
     if (defined("DEBUG")) {
         $debug = true;
     }
     // Make a Slim App
     $app = new App(['settings' => ['debug' => $debug, 'whoops.editor' => 'sublime']]);
     $app->add(new WhoopsMiddleware());
     $this->app = $app;
 }

作者:ruthi    项目:Slim-Controlle   
public static function init(\Slim\App $app)
 {
     error_reporting(E_ALL);
     ini_set('display_errors', true);
     date_default_timezone_set('Asia/Shanghai');
     $container = $app->getContainer();
     $settings = $container->get('settings');
     $settings['displayErrorDetails'] = true;
     $settings['core.baseNamespace'] = 'Application';
     $settings['view.basePath'] = __DIR__;
     return parent::init($app);
 }

作者:activecolla    项目:bootstra   
/**
  * Test extend single routes.
  */
 public function testExtendSingle()
 {
     $this->assertCount(0, $this->slim_app->getContainer()->get('router')->getRoutes());
     $this->model_router->mapModel('App\\Model\\User', null, null, function (Extender $extender) {
         $extender->extend('accounts');
     });
     $this->assertCount(3, $this->slim_app->getContainer()->get('router')->getRoutes());
     /** @var Route $user_accounts_route */
     $user_accounts_route = $this->slim_app->getContainer()->get('router')->getRoutes()['route2'];
     $this->assertEquals(['GET'], $user_accounts_route->getMethods());
     $this->assertEquals('user_accounts', $user_accounts_route->getName());
 }

作者:php-middlewar    项目:phpdebugba   
protected function dispatchApplication(array $server, array $pipe = [])
 {
     $app = new App();
     $app->getContainer()['environment'] = function () use($server) {
         return new Environment($server);
     };
     $middlewareFactory = new PhpDebugBarMiddlewareFactory();
     $middleware = $middlewareFactory();
     $app->add($middleware);
     foreach ($pipe as $pattern => $middleware) {
         $app->get($pattern, $middleware);
     }
     return $app->run(true);
 }

作者:kitchen    项目:slim-debugba   
/**
  * Register DebugBar service.
  *
  * @param  App $app
  *
  * @return void
  */
 public function register(App $app)
 {
     $container = $app->getContainer();
     $container['debugbar'] = function ($container) {
         return new SlimDebugBar($container, $this->settings);
     };
     if (!$this->settings['enabled']) {
         return;
     }
     $app->group('/_debugbar', function () {
         $this->get('/open', 'Kitchenu\\Debugbar\\Controllers\\OpenHandlerController:handle')->setName('debugbar-openhandler');
         $this->get('/assets/stylesheets', 'Kitchenu\\Debugbar\\Controllers\\AssetController:css')->setName('debugbar-assets-css');
         $this->get('/assets/javascript', 'Kitchenu\\Debugbar\\Controllers\\AssetController:js')->setName('debugbar-assets-js');
     });
     $app->add(new Debugbar($container['debugbar'], $container['errorHandler']));
 }

作者:quickenloans-mc    项目:mcp-pantho   
/**
  * @param ResponseInterface $response
  */
 private function renderResponse(ResponseInterface $response)
 {
     if ($this->slim) {
         $this->slim->respond($response);
     } else {
         // do something
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号