本文整理汇总了PHP中Interop\Container\ContainerInterface::set方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerInterface::set方法的具体用法?PHP ContainerInterface::set怎么用?PHP ContainerInterface::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interop\Container\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor application.
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param \Interop\Container\ContainerInterface $container
*/
public function __construct(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response)
{
$this->container = $container;
$this->request = $request;
$this->response = $response;
// Check container set exist
if (method_exists($this->container, 'set')) {
// Inject self application for middlewares freedom
$this->container->set(ApplicationInterface::class, $this);
}
}
示例2: __construct
/**
* Application initialization.
*
* @param mixed $router Routing system.
* @param ContainerInterface $container Dependency Injection container.
*/
public function __construct($router = null, ContainerInterface $container = null)
{
$this->container = $container ?: $this->buildContainer(Loader::load());
$container =& $this->container;
$this->response = new Response();
$this->request = ServerRequestFactory::fromGlobals();
if ($router == null && $container->has('router') == false) {
throw new Exception('Define router config');
}
if ($container->has('router') == false) {
$container->set('router', $router);
}
$container->set('event_manager', DI\object('Zend\\EventManager\\EventManager'));
$container->set('dispatcher', DI\object('GianArb\\Penny\\Dispatcher')->constructor($container->get('router')));
$container->set('di', $container);
}
示例3: set
/**
* Define an object or a value in the container.
*
* @param string $name Entry name
* @param mixed $value Value, use definition helpers to define objects
* @throws \Exception
*/
public function set($name, $value)
{
if (!method_exists($this->container, 'set')) {
throw new Exception('Container method not found');
}
return $this->container->set($name, $value);
}