protected EntityResolverManager::getControllerClass(array $defaults)
Gets the controller class using route defaults.
By design we cannot support all possible routes, but just the ones which use the defaults provided by core, which are _controller and _form.
Rather than creating an instance of every controller determine the class and method that would be used. This is not possible for the service:method notation as the runtime container does not allow static introspection.
Parameters
array $defaults: The default values provided by the route.
Return value
string|null Returns the controller class, otherwise NULL.
See also
\Drupal\Core\Controller\ControllerResolver::getControllerFromDefinition()
\Drupal\Core\Controller\ClassResolver::getInstanceFromDefinition()
File
- core/lib/Drupal/Core/Entity/EntityResolverManager.php, line 62
Class
- EntityResolverManager
- Sets the entity route parameter converter options automatically.
Namespace
Drupal\Core\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | protected function getControllerClass( array $defaults ) { $controller = NULL; if (isset( $defaults [ '_controller' ])) { $controller = $defaults [ '_controller' ]; } if (isset( $defaults [ '_form' ])) { $controller = $defaults [ '_form' ]; // Check if the class exists and if so use the buildForm() method from the // interface. if ( class_exists ( $controller )) { return array ( $controller , 'buildForm' ); } } if ( strpos ( $controller , ':' ) === FALSE) { if (method_exists( $controller , '__invoke' )) { return array ( $controller , '__invoke' ); } if (function_exists( $controller )) { return $controller ; } return NULL; } $count = substr_count( $controller , ':' ); if ( $count == 1) { // Controller in the service:method notation. Get the information from the // service. This is dangerous as the controller could depend on services // that could not exist at this point. There is however no other way to // do it, as the container does not allow static introspection. list( $class_or_service , $method ) = explode ( ':' , $controller , 2); return array ( $this ->classResolver->getInstanceFromDefinition( $class_or_service ), $method ); } elseif ( strpos ( $controller , '::' ) !== FALSE) { // Controller in the class::method notation. return explode ( '::' , $controller , 2); } return NULL; } |
Please login to continue.