本文整理匯總了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);
}
}