本文整理汇总了PHP中Interop\Container\ContainerInterface::call方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerInterface::call方法的具体用法?PHP ContainerInterface::call怎么用?PHP ContainerInterface::call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interop\Container\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::call方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: call
/**
* Call the given function using the given parameters.
*
* Missing parameters will be resolved from the container.
*
* @param callable $callable Function to call.
* @param array $parameters Parameters to use. Can be indexed by the parameter names
* or not indexed (same order as the parameters).
* The array can also contain DI definitions, e.g. DI\get().
*
* @throws \Exception
* @return mixed Result of the function.
*/
public function call($callable, array $parameters = [])
{
if (!method_exists($this->container, 'call')) {
throw new Exception('Container method not found');
}
return $this->container->call($callable, $parameters);
}
示例2: registerHook
/**
* Registers/Runs a Hook File.
*
* @param string $file The filepath to where the hook exists.
* @return void
*/
private function registerHook($file)
{
$hook = import($file);
if (is_callable($hook)) {
$this->container->call($hook, ['config' => $this->config]);
}
}
示例3: discoverRoutes
/**
* Finds all theme route files and adds the routes to the RouteCollection.
*
* @return void
*/
private function discoverRoutes()
{
// Where are our routes located?
$parentRoutes = $this->config->paths->theme->parent->routes;
$childRoutes = $this->config->paths->theme->child->routes;
$files = $this->finder->createFinder()->files()->name('*.php')->in($parentRoutes);
if ($parentRoutes != $childRoutes && is_dir($childRoutes)) {
$files = $files->in($childRoutes);
}
// Collect all the files
$splFiles = [];
foreach ($files as $file) {
$splFiles[] = $file;
}
// Now we need to sort them ourselves because it seems Finder's
// sortByName(), only sorts per in('dir') and not across the
// entire list.
$orderedFiles = Linq::from($splFiles)->orderBy('$v', function ($a, $b) {
return strnatcasecmp($a->getBasename('.php'), $b->getBasename('.php'));
});
// Finally lets add some routes.
foreach ($orderedFiles as $file) {
$route = import($file->getRealPath(), ['route' => $this->routes]);
if (is_callable($route)) {
$this->container->call($route, ['config' => $this->config]);
}
}
}
示例4: 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;
}
示例5: handle
/**
* {@inheritdoc}
*/
public function handle(Route $route, array $inputs)
{
return $this->invoker->call($route->getHandler(), [$inputs]);
}
示例6: resolve
/**
* Used by Relay\Runner when it dispatches the middleware stack.
*
* @param string $file
* @return Closure
*/
private function resolve($file)
{
return function (IServerRequest $request, IResponse $response, callable $next) use($file) {
return $this->container->call(import($file), ['request' => $request, 'response' => $response, 'next' => $next, 'config' => $this->config]);
};
}