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