file BootstrapConstant.php

Contains \Drupal\bootstrap\Annotation\BootstrapConstant.

Namespace

Drupal\bootstrap\Annotation
Source
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drupal\bootstrap\Annotation\BootstrapConstant.
  5. */
  6. namespace Drupal\bootstrap\Annotation;
  7. use Doctrine\Common\Annotations\AnnotationException;
  8. use Drupal\Component\Annotation\AnnotationBase;
  9. /**
  10. * Defines a BootstrapConstant annotation object.
  11. *
  12. * @Annotation
  13. *
  14. * @ingroup utility
  15. */
  16. class BootstrapConstant extends AnnotationBase {
  17. /**
  18. * The stored constant value.
  19. *
  20. * @var mixed
  21. */
  22. protected $value;
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function __construct(array $values) {
  27. $string = $values['value'];
  28. // Handle classes.
  29. if (strpos($string, '::') !== FALSE) {
  30. list($class, $constant) = explode('::', $string);
  31. try {
  32. $reflection = new \ReflectionClass($class);
  33. if ($reflection->hasConstant($constant)) {
  34. $this->value = $reflection->getConstant($constant);
  35. return;
  36. }
  37. }
  38. catch (\ReflectionException $e) {
  39. }
  40. }
  41. // Handle procedural constants.
  42. if (!$this->value && defined($string)) {
  43. $this->value = constant($string);
  44. return;
  45. }
  46. throw AnnotationException::semanticalErrorConstants($this->value);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function get() {
  52. return $this->value;
  53. }
  54. }

Classes

Namesort descending Description
BootstrapConstant Defines a BootstrapConstant annotation object.