file BootstrapConstant.php

Namespace

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

Classes

Name Description
BootstrapConstant Defines a BootstrapConstant annotation object.