本文整理汇总了PHP中Interop\Container\ContainerInterface::make方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerInterface::make方法的具体用法?PHP ContainerInterface::make怎么用?PHP ContainerInterface::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interop\Container\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::make方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: make
/**
* Resolves an entry by its name.
* If given a class name, it will return a new instance of that class.
*
* @param string $name Entry name or a class name.
* @param array $parameters Optional parameters to use to build the entry. Use this to force specific
* parameters to specific values. Parameters not defined in this array will
* be automatically resolved.
*
* @throws \Exception Error while resolving the entry.
* @return mixed
*/
public function make($name, array $parameters = [])
{
if (!method_exists($this->container, 'make')) {
throw new Exception('Container method not found');
}
return $this->container->make($name, $parameters);
}
示例2: dispatch
/**
* Dispatch a route.
*
* @param ResolvedRequestInterface $resolvedRequest A resolved request.
* @return string The response.
*/
public function dispatch(ResolvedRequestInterface $resolvedRequest)
{
$route = $resolvedRequest->getRoute();
$controller = $this->container->make($route->getController(), ['resolvedRequest' => $resolvedRequest]);
// Call the before hook, if defined.
if (method_exists($controller, 'before')) {
$this->container->call([$controller, 'before'], ['resolvedRequest' => $resolvedRequest]);
}
// Call the action.
$response = $this->container->call([$controller, 'action' . $route->getAction()], ['resolvedRequest' => $resolvedRequest]);
// Call the after hook, if defined.
if (method_exists($controller, 'after')) {
$this->container->call([$controller, 'after'], ['resolvedRequest' => $resolvedRequest]);
}
return $response;
}
示例3: __invoke
/**
* Create an object
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
*
* @return object
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
if ($container instanceof Container) {
return $container->make($requestedName, $options ? $options : []);
} else {
return $container->get($requestedName);
}
}