3 namespace Drupal\Driver\Cores;
5 use Drupal\Component\Utility\Random;
6 use Symfony\Component\DependencyInjection\Container;
9 * Base class for core drivers.
11 abstract class AbstractCore implements CoreInterface {
14 * System path to the Drupal installation.
18 protected $drupalRoot;
21 * URI for the Drupal installation.
30 * @var \Drupal\Component\Utility\Random
37 public function __construct($drupal_root, $uri = 'default', Random $random = NULL) {
38 $this->drupalRoot = realpath($drupal_root);
40 if (!isset($random)) {
41 $random = new Random();
43 $this->random = $random;
49 public function getRandom() {
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);
66 return new $default_class($entity, $entity_type, $field_name);
70 * Expands properties on the given entity object to the expected structure.
72 * @param \stdClass $entity
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);
88 public function clearStaticCaches() {