本文整理汇总了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));
});
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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));
}
}
}
示例6: setRequest
/**
* @param ServerRequestInterface $request
*
* @return Application
*/
public function setRequest(ServerRequestInterface $request) : Application
{
$this->request = $request;
$this->container->add(ServerRequestInterface::class, $request);
return $this;
}