ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Slim\CallableResolver Class Reference

This class resolves a string of the format 'class:method' into a closure that can be dispatched. More...

+ Inheritance diagram for Slim\CallableResolver:
+ Collaboration diagram for Slim\CallableResolver:

Public Member Functions

 __construct (ContainerInterface $container)
 
 resolve ($toResolve)
 Resolve toResolve into a closure so that the router can dispatch. More...
 
 resolve ($toResolve)
 Invoke the resolved callable. More...
 

Data Fields

const CALLABLE_PATTERN = '!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!'
 

Protected Member Functions

 resolveCallable ($class, $method='__invoke')
 Check if string is something in the DIC that's callable or is a class name which has an __invoke() method. More...
 
 assertCallable ($callable)
 

Private Attributes

 $container
 

Detailed Description

This class resolves a string of the format 'class:method' into a closure that can be dispatched.

Definition at line 19 of file CallableResolver.php.

Constructor & Destructor Documentation

◆ __construct()

Slim\CallableResolver::__construct ( ContainerInterface  $container)
Parameters
ContainerInterface$container

Definition at line 31 of file CallableResolver.php.

32 {
33 $this->container = $container;
34 }

References $container.

Member Function Documentation

◆ assertCallable()

Slim\CallableResolver::assertCallable (   $callable)
protected
Parameters
Callable$callable
Exceptions

RuntimeException if the callable is not resolvable

Definition at line 101 of file CallableResolver.php.

102 {
103 if (!is_callable($callable)) {
104 throw new RuntimeException(sprintf(
105 '%s is not resolvable',
106 is_array($callable) || is_object($callable) ? json_encode($callable) : $callable
107 ));
108 }
109 }

◆ resolve()

Slim\CallableResolver::resolve (   $toResolve)

Resolve toResolve into a closure so that the router can dispatch.

If toResolve is of the format 'class:method', then try to extract 'class' from the container otherwise instantiate it and then dispatch 'method'.

Parameters
mixed$toResolve
Returns
callable
Exceptions
RuntimeExceptionif the callable does not exist
RuntimeExceptionif the callable is not resolvable

Implements Slim\Interfaces\CallableResolverInterface.

Definition at line 49 of file CallableResolver.php.

50 {
51 if (is_callable($toResolve)) {
52 return $toResolve;
53 }
54
55 if (!is_string($toResolve)) {
56 $this->assertCallable($toResolve);
57 }
58
59 // check for slim callable as "class:method"
60 if (preg_match(self::CALLABLE_PATTERN, $toResolve, $matches)) {
61 $resolved = $this->resolveCallable($matches[1], $matches[2]);
62 $this->assertCallable($resolved);
63
64 return $resolved;
65 }
66
67 $resolved = $this->resolveCallable($toResolve);
68 $this->assertCallable($resolved);
69
70 return $resolved;
71 }
resolveCallable($class, $method='__invoke')
Check if string is something in the DIC that's callable or is a class name which has an __invoke() me...

◆ resolveCallable()

Slim\CallableResolver::resolveCallable (   $class,
  $method = '__invoke' 
)
protected

Check if string is something in the DIC that's callable or is a class name which has an __invoke() method.

Parameters
string$class
string$method
Returns
callable
Exceptions

RuntimeException if the callable does not exist

Definition at line 83 of file CallableResolver.php.

84 {
85 if ($this->container->has($class)) {
86 return [$this->container->get($class), $method];
87 }
88
89 if (!class_exists($class)) {
90 throw new RuntimeException(sprintf('Callable %s does not exist', $class));
91 }
92
93 return [new $class($this->container), $method];
94 }

Field Documentation

◆ $container

Slim\CallableResolver::$container
private

Definition at line 26 of file CallableResolver.php.

◆ CALLABLE_PATTERN

const Slim\CallableResolver::CALLABLE_PATTERN = '!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!'

Definition at line 21 of file CallableResolver.php.


The documentation for this class was generated from the following file: