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


PHP ContainerInterface::add方法代碼示例

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


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

示例1: register

 /**
  * @return void
  */
 public function register()
 {
     $this->container->add(ResponseInterface::class, \Zend\Diactoros\Response::class);
     $this->container->add(Router::class, function () {
         return new Router($this->container->get(RouteInterface::class));
     });
 }
開發者ID:ytake,項目名稱:vu,代碼行數:10,代碼來源:Dependency.php

示例2: set

 /**
  * Sets the component.
  *
  * @param  \Interop\Container\ContainerInterface $container
  * @return void
  */
 public function set(ContainerInterface &$container)
 {
     if ($container instanceof Container) {
         $container->add('Psr\\Http\\Message\\ServerRequestInterface', $this->request);
         $container->add('Psr\\Http\\Message\\ResponseInterface', $this->response);
     }
 }
開發者ID:rougin,項目名稱:slytherin-skeleton,代碼行數:13,代碼來源:HttpComponent.php

示例3: __invoke

 public function __invoke(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, callable $next)
 {
     //Save session to request
     $attr = $this->attribute;
     $this->container->add('sessions.' . $this->attribute, function () use($request, $attr) {
         return $request->getAttribute($attr);
     });
     return $next($request, $response);
 }
開發者ID:laasti,項目名稱:sessions,代碼行數:9,代碼來源:SaveSessionToContainerMiddleware.php

示例4: set

 /**
  * Sets the component and add it to the container of your choice.
  *
  * @param  \Interop\Container\ContainerInterface $container
  * @return void
  */
 public function set(ContainerInterface &$container)
 {
     $config = Setup::createAnnotationMetadataConfiguration(config('doctrine.model_paths'), config('doctrine.developer_mode'));
     $config->setProxyDir(config('doctrine.proxy_path'));
     $config->setAutoGenerateProxyClasses(config('doctrine.developer_mode'));
     $entityManager = EntityManager::create(config('database.mysql'), $config);
     if ($container instanceof Container) {
         $container->add('Doctrine\\ORM\\EntityManager', $entityManager);
     }
 }
開發者ID:rougin,項目名稱:slytherin-skeleton,代碼行數:16,代碼來源:DoctrineComponent.php

示例5: set

 /**
  * Sets the component.
  *
  * @param  \Interop\Container\ContainerInterface $container
  * @return void
  */
 public function set(ContainerInterface &$container)
 {
     $entityManager = $container->get('Doctrine\\ORM\\EntityManager');
     $path = base('src/Repositories/');
     $files = glob($path . '*Repository.php');
     foreach ($files as $item) {
         $entity = str_replace([$path, 'Repository.php'], ['', ''], $item);
         $model = 'App\\Models\\' . $entity;
         $name = 'App\\Repositories\\' . $entity . 'Repository';
         $metadata = $entityManager->getClassMetadata($model);
         if ($container instanceof Container) {
             $container->add($name, new $name($entityManager, $metadata));
         }
     }
 }
開發者ID:rougin,項目名稱:slytherin-skeleton,代碼行數:21,代碼來源:RepositoryComponent.php

示例6: setRequest

 /**
  * @param ServerRequestInterface $request
  *
  * @return Application
  */
 public function setRequest(ServerRequestInterface $request) : Application
 {
     $this->request = $request;
     $this->container->add(ServerRequestInterface::class, $request);
     return $this;
 }
開發者ID:ytake,項目名稱:vu,代碼行數:11,代碼來源:Application.php


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