本文整理汇总了PHP中Container::resolve方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::resolve方法的具体用法?PHP Container::resolve怎么用?PHP Container::resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container::resolve方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeFilters
protected function executeFilters()
{
$filterObjects = [];
//Create filter objects
foreach ($this->filters as $filter) {
$filterObjects[] = $this->container->resolve($filter);
}
//Execute filters
/** @var FilterAbstract $filterObject */
foreach ($filterObjects as $filterObject) {
$filterObject->execute();
}
}
示例2: callMethods
/**
* Execute the methods added via call()
*
* @param object $object The instatiated $class on which to call the methods.
*
* @return mixed The created object
*/
protected function callMethods($object)
{
if (!empty($this->methods)) {
foreach (array_reverse($this->methods) as $method => $args) {
$reflection = new \ReflectionMethod($object, $method);
$arguments = [];
foreach ($args as $arg) {
if (is_string($arg) && (class_exists($arg) || $this->container->bound($arg))) {
$arguments[] = $this->container->resolve($arg);
continue;
}
$arguments[] = $arg;
}
$reflection->invokeArgs($object, $arguments);
}
}
return $object;
}
示例3: resolveArgs
protected function resolveArgs(\ReflectionMethod $reflected_method, $args)
{
$results = [];
if (is_array($args)) {
foreach ($reflected_method->getParameters() as $key => $reflected_parameter) {
try {
$class = $reflected_parameter->getClass();
$name = $reflected_parameter->getName();
if (isset($args[$name])) {
$results[$key] = $args[$name];
if (is_object($results[$key]) && $results[$key] instanceof DefinitionInterface) {
$results[$key] = $results[$key]->resolve();
} elseif ($class && is_string($results[$key])) {
$results[$key] = $this->container->resolve($results[$key]);
} elseif (is_array($results[$key])) {
array_walk_recursive($results[$key], function (&$item) {
if (is_object($item) && $item instanceof DefinitionInterface) {
$item = $item->resolve();
}
});
}
} elseif ($class) {
if ($reflected_parameter->allowsNull()) {
$results[$key] = null;
} else {
$results[$key] = $this->container->resolve($class->getName());
}
} elseif ($reflected_parameter->isOptional()) {
$results[$key] = $reflected_parameter->getDefaultValue();
}
} catch (DefinitionException $e) {
throw new ResolveArgsException('Can not resolve argument ' . $reflected_parameter->getName() . ' while resolving arguments for ' . $reflected_method->getName(), 0, $e);
}
}
}
return $results;
}
示例4: testFakeFile
/**
* @covers PublicVendor\Container::resolve
*/
public function testFakeFile()
{
$container = new Container(VENDOR_PATH);
$result = $container->resolve('fake/vendor', 'fake/file.html');
$this->assertFalse(file_exists($result));
}
示例5: runAction
private static function runAction()
{
$action = self::$func;
if (is_string($action)) {
$tmp = explode('@', $action);
$tmp[0] = "\\App\\Controller\\" . $tmp[0];
$middleware = null;
if (self::$middleware) {
$middleClass = "\\App\\Controller\\" . self::$middleware;
$middleware = Container::resolve($middleClass, 'handle', self::$requestParams);
if ($middleware == 'next' or is_object($middleware) or is_array($middleware)) {
return Container::resolve($tmp[0], $tmp[1], self::$requestParams, $middleware);
}
return $middleware;
}
return Container::resolve($tmp[0], $tmp[1], self::$requestParams);
}
return call_user_func_array($action, self::$requestParams);
}