You are here

public static function ContainerAwarePluginManager::getPluginClass in Service Container 7.2

Same name and namespace in other branches
  1. 7 src/Plugin/ContainerAwarePluginManager.php \Drupal\service_container\Plugin\ContainerAwarePluginManager::getPluginClass()

Finds the class relevant for a given plugin.

Parameters

string $plugin_id: The id of a plugin.

mixed $plugin_definition: The plugin definition associated with the plugin ID.

string $required_interface: (optional) THe required plugin interface.

Return value

string The appropriate class name.

Throws

\Drupal\Component\Plugin\Exception\PluginException Thrown when there is no class specified, the class doesn't exist, or the class does not implement the specified required interface.

1 call to ContainerAwarePluginManager::getPluginClass()
ContainerAwarePluginManager::createInstance in src/Plugin/ContainerAwarePluginManager.php
Creates a pre-configured instance of a plugin.

File

src/Plugin/ContainerAwarePluginManager.php, line 112
Contains \Drupal\service_container\Plugin\ContainerAwarePluginManager

Class

ContainerAwarePluginManager
Base class for plugin managers.

Namespace

Drupal\service_container\Plugin

Code

public static function getPluginClass($plugin_id, $plugin_definition = NULL, $required_interface = NULL) {
  if (empty($plugin_definition['class'])) {
    throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id));
  }
  $class = $plugin_definition['class'];
  if (!class_exists($class)) {
    throw new PluginException(sprintf('Plugin (%s) instance class "%s" does not exist.', $plugin_id, $class));
  }
  if ($required_interface && !is_subclass_of($plugin_definition['class'], $required_interface)) {
    throw new PluginException(sprintf('Plugin "%s" (%s) in %s should implement interface %s.', $plugin_id, $plugin_definition['class'], $plugin_definition['provider'], $required_interface));
  }
  return $class;
}