Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-driver / src / Drupal / Driver / Cores / AbstractCore.php
1 <?php
2
3 namespace Drupal\Driver\Cores;
4
5 use Drupal\Component\Utility\Random;
6 use Symfony\Component\DependencyInjection\Container;
7
8 /**
9  * Base class for core drivers.
10  */
11 abstract class AbstractCore implements CoreInterface {
12
13   /**
14    * System path to the Drupal installation.
15    *
16    * @var string
17    */
18   protected $drupalRoot;
19
20   /**
21    * URI for the Drupal installation.
22    *
23    * @var string
24    */
25   protected $uri;
26
27   /**
28    * Random generator.
29    *
30    * @var \Drupal\Component\Utility\Random
31    */
32   protected $random;
33
34   /**
35    * {@inheritdoc}
36    */
37   public function __construct($drupal_root, $uri = 'default', Random $random = NULL) {
38     $this->drupalRoot = realpath($drupal_root);
39     $this->uri = $uri;
40     if (!isset($random)) {
41       $random = new Random();
42     }
43     $this->random = $random;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getRandom() {
50     return $this->random;
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function getFieldHandler($entity, $entity_type, $field_name) {
57     $reflection = new \ReflectionClass($this);
58     $core_namespace = $reflection->getShortName();
59     $field_types = $this->getEntityFieldTypes($entity_type);
60     $camelized_type = Container::camelize($field_types[$field_name]);
61     $default_class = sprintf('\Drupal\Driver\Fields\%s\DefaultHandler', $core_namespace);
62     $class_name = sprintf('\Drupal\Driver\Fields\%s\%sHandler', $core_namespace, $camelized_type);
63     if (class_exists($class_name)) {
64       return new $class_name($entity, $entity_type, $field_name);
65     }
66     return new $default_class($entity, $entity_type, $field_name);
67   }
68
69   /**
70    * Expands properties on the given entity object to the expected structure.
71    *
72    * @param \stdClass $entity
73    *   Entity object.
74    */
75   protected function expandEntityFields($entity_type, \stdClass $entity) {
76     $field_types = $this->getEntityFieldTypes($entity_type);
77     foreach ($field_types as $field_name => $type) {
78       if (isset($entity->$field_name)) {
79         $entity->$field_name = $this->getFieldHandler($entity, $entity_type, $field_name)
80           ->expand($entity->$field_name);
81       }
82     }
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function clearStaticCaches() {
89   }
90
91 }