當前位置: 首頁>>代碼示例>>PHP>>正文


PHP App::getContainer方法代碼示例

本文整理匯總了PHP中Slim\App::getContainer方法的典型用法代碼示例。如果您正苦於以下問題:PHP App::getContainer方法的具體用法?PHP App::getContainer怎麽用?PHP App::getContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Slim\App的用法示例。


在下文中一共展示了App::getContainer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: hasRoutesConfigured

 private function hasRoutesConfigured() : bool
 {
     $slimContainer = $this->slimApp->getContainer();
     $slimRouter = $slimContainer->get('router');
     /** @var $slimRouter SlimRouter */
     return (bool) count($slimRouter->getRoutes());
 }
開發者ID:postalservice14,項目名稱:sainsburys-http-service,代碼行數:7,代碼來源:SlimAppAdapter.php

示例2: __construct

 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__));
     }
 }
開發者ID:erdemece,項目名稱:news-website,代碼行數:9,代碼來源:SiteSettings.php

示例3: runApp

 /**
  * @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();
 }
開發者ID:asaokamei,項目名稱:slim-tuum,代碼行數:15,代碼來源:UnitTestsAppTrait.php

示例4: testExtendSingle

 /**
  * 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());
 }
開發者ID:activecollab,項目名稱:bootstrap,代碼行數:15,代碼來源:RouterTest.php

示例5: setRouteForPostTypes

 protected function setRouteForPostTypes($postType, $defaultController)
 {
     $controllerPageMapping = $this->app->getContainer()->get(ControllerPageMappingField::class);
     /**
      * @FIXME: In future versions, need to change
      * adding routes to the map of get|post. All WP PAGES and POSTS must
      * coresponds to only GET method. Because it is has content only for reading.
      * All other logic like writing or another logic should be implemented in WIDGETS
      * or in controllers via declarring new routes and handlers for them.
      */
     foreach ($this->wpService->get_posts(['numberposts' => -1, 'post_type' => $postType]) as $post) {
         $controller = $controllerPageMapping->getValue($post->ID);
         $this->app->map(['get', 'post'], parse_url(get_permalink($post), PHP_URL_PATH), $this->app->getContainer()->get(empty($controller) ? $defaultController : $controller))->setArgument('requestedEntity', $post);
     }
 }
開發者ID:milsdev,項目名稱:wordpress-plugin-sarcofag,代碼行數:15,代碼來源:App.php

示例6: __invoke

 /**
  * @param \swoole_http_request $request
  * @param \swoole_http_response $response
  * @throws \Exception
  */
 public function __invoke($request, $response)
 {
     $this->app->getContainer()['environment'] = $this->app->getContainer()->factory(function () {
         return new Environment($_SERVER);
     });
     $this->app->getContainer()['request'] = $this->app->getContainer()->factory(function ($container) {
         return Request::createFromEnvironment($container['environment']);
     });
     $this->app->getContainer()['response'] = $this->app->getContainer()->factory(function ($container) {
         $headers = new Headers(['Content-Type' => 'text/html']);
         $response = new Response(200, $headers);
         return $response->withProtocolVersion($container->get('settings')['httpVersion']);
     });
     /**
      * @var ResponseInterface $appResponse
      */
     $appResponse = $this->app->run(true);
     // set http header
     foreach ($appResponse->getHeaders() as $key => $value) {
         $filter_header = function ($header) {
             $filtered = str_replace('-', ' ', $header);
             $filtered = ucwords($filtered);
             return str_replace(' ', '-', $filtered);
         };
         $name = $filter_header($key);
         foreach ($value as $v) {
             $response->header($name, $v);
         }
     }
     // set http status
     $response->status($appResponse->getStatusCode());
     // send response to browser
     if (!$this->isEmptyResponse($appResponse)) {
         $body = $appResponse->getBody();
         if ($body->isSeekable()) {
             $body->rewind();
         }
         $settings = $this->app->getContainer()->get('settings');
         $chunkSize = $settings['responseChunkSize'];
         $contentLength = $appResponse->getHeaderLine('Content-Length');
         if (!$contentLength) {
             $contentLength = $body->getSize();
         }
         $totalChunks = ceil($contentLength / $chunkSize);
         $lastChunkSize = $contentLength % $chunkSize;
         $currentChunk = 0;
         while (!$body->eof() && $currentChunk < $totalChunks) {
             if (++$currentChunk == $totalChunks && $lastChunkSize > 0) {
                 $chunkSize = $lastChunkSize;
             }
             $response->write($body->read($chunkSize));
             if (connection_status() != CONNECTION_NORMAL) {
                 break;
             }
         }
         $response->end();
     }
 }
開發者ID:praswicaksono,項目名稱:veloce,代碼行數:63,代碼來源:RequestHandler.php

示例7: run

 /**
  * @inheritdoc
  */
 public function run($appNamespace = self::ROOT_NAMESPACE)
 {
     //
     // Each application must exist inside its own namespace. Chubby uses that namespace to search for modules.
     $this->appNamespace = $appNamespace;
     //
     // Slim can be initiated in one of two ways:
     // 1. Without a container. Slim will create the default container.
     // 2. Receiving a container in the constructor. We can pass Slim some settings and services
     //      by passing a pre-created container. We do this here via a configuration file.
     $container = $this->getContainerConfig();
     $this->slim = new \Slim\App($container);
     $container = $this->slim->getContainer();
     //
     $this->modules = \Chubby\PackageLoader::loadModules($container);
     if (!is_array($this->modules) || !count($this->modules)) {
         throw new \Exception("Chubby Framework requires at least one module.");
     }
     //
     // Initialize the modules following the order given by each module's priority.
     foreach ($this->modules as $priority => $modules) {
         foreach ($modules as $module) {
             $module['object']->setApp($this);
             $module['object']->init();
         }
     }
     //
     $this->slim->run();
     return $this;
 }
開發者ID:a3gz,項目名稱:chubby,代碼行數:33,代碼來源:App.php

示例8: register

 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');
 }
開發者ID:onigoetz,項目名稱:imagecache,代碼行數:7,代碼來源:ImagecacheRegister.php

示例9: getSlimRouteFromApplication

 /**
  * @param SlimApp $slimApp
  * @return SlimRoute
  */
 private function getSlimRouteFromApplication(SlimApp $slimApp)
 {
     $slimRouter = $slimApp->getContainer()->get('router');
     /** @var $slimRouter SlimRouter */
     $slimRoutes = $slimRouter->getRoutes();
     return $slimRoutes['route0'];
 }
開發者ID:postalservice14,項目名稱:sainsburys-http-service,代碼行數:11,代碼來源:RoutingComponentTest.php

示例10: testLoginLogout

 public function testLoginLogout()
 {
     /**
      * @var Auth $auth
      * @var Request $request
      * @var Response $response
      */
     $container = $this->app->getContainer();
     $auth = $container->get("auth");
     $request = $container->get('request');
     $response = $container->get('response');
     $middleware = $this->middleware;
     $middleware($request, $response, $this->app);
     /** @var Response $response */
     $response = $auth->login($response, "wrong@mail.com", "wrongpw");
     $this->assertInstanceOf(Response::class, $response);
     $this->assertEmpty($response->getHeaders());
     $this->assertNull($auth->getUser());
     $this->assertFalse($auth->isAuthenticated());
     /** @var Response $response */
     $response = $auth->login($response, "test@test.com", "test1234");
     $this->assertInstanceOf(Response::class, $response);
     $this->assertArrayHasKey("Set-Cookie", $response->getHeaders());
     $this->assertInstanceOf(TestUser::class, $auth->getUser());
     $this->assertTrue($auth->isAuthenticated());
     /** @var Response $response */
     $response = $auth->logout($response);
     $this->assertInstanceOf(Response::class, $response);
     $this->assertArrayHasKey("Set-Cookie", $response->getHeaders());
     $this->assertNull($auth->getUser());
     $this->assertFalse($auth->isAuthenticated());
 }
開發者ID:dtkahl,項目名稱:php-auth,代碼行數:32,代碼來源:AuthTest.php

示例11: initModules

 /**
  * 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);
 }
開發者ID:martynbiz,項目名稱:slim-module,代碼行數:11,代碼來源:Initializer.php

示例12: load

 public function load(array $settings = [])
 {
     $service = new SlimApp($settings);
     $provider = new ServiceProvider();
     $provider->register($service->getContainer());
     $this->setService($service);
 }
開發者ID:iceberg2,項目名稱:service-slim,代碼行數:7,代碼來源:Manager.php

示例13: setUp

 public function setUp()
 {
     $app = new App();
     $kernel = new Kernel($app, $app->getContainer());
     $kernel->registerServices();
     $kernel->registerRoutes();
     $this->app = $app;
 }
開發者ID:raistlfiren,項目名稱:slim-skeleton,代碼行數:8,代碼來源:AbstractTestFunctional.php

示例14:

 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;
 }
開發者ID:skyling,項目名稱:slim-MVC,代碼行數:8,代碼來源:Controller.php

示例15: init

 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);
 }
開發者ID:ruthio,項目名稱:Slim-Controller,代碼行數:12,代碼來源:Controller.php


注:本文中的Slim\App::getContainer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。