YamlDiscoveryDecorator.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Drupal\Core\Plugin\Discovery;
  3. use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
  4. /**
  5. * Enables YAML discovery for plugin definitions.
  6. *
  7. * You should normally extend this class to add validation for the values in the
  8. * YAML data or to restrict use of the class or derivatives keys.
  9. */
  10. class YamlDiscoveryDecorator extends YamlDiscovery {
  11. /**
  12. * The Discovery object being decorated.
  13. *
  14. * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface
  15. */
  16. protected $decorated;
  17. /**
  18. * Constructs a YamlDiscoveryDecorator object.
  19. *
  20. * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
  21. * The discovery object that is being decorated.
  22. * @param string $name
  23. * The file name suffix to use for discovery; for instance, 'test' will
  24. * become 'MODULE.test.yml'.
  25. * @param array $directories
  26. * An array of directories to scan.
  27. */
  28. public function __construct(DiscoveryInterface $decorated, $name, array $directories) {
  29. parent::__construct($name, $directories);
  30. $this->decorated = $decorated;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function getDefinitions() {
  36. return parent::getDefinitions() + $this->decorated->getDefinitions();
  37. }
  38. /**
  39. * Passes through all unknown calls onto the decorated object.
  40. */
  41. public function __call($method, $args) {
  42. return call_user_func_array([$this->decorated, $method], $args);
  43. }
  44. }