Completed
Pull Request — master (#85)
by
unknown
02:49
created

AbstractCore::nodeLoad()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Drupal\Driver\Cores;
4
5
use Drupal\Component\Utility\Random;
6
use Symfony\Component\DependencyInjection\Container;
7
use Drupal\Driver\DriverInterface\UnsupportedDriverActionException;
8
9
/**
10
 * Base class for core drivers.
11
 */
12
abstract class AbstractCore implements CoreInterface {
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
39
    $this->drupalRoot = realpath($drupal_root);
40
    $this->uri = $uri;
41
    if (!isset($random)) {
42
      $random = new Random();
43
    }
44
    $this->random = $random;
45
  }
46
47
  /**
48
   * {@inheritdoc}
49
   */
50
  public function getRandom() {
51
52
    return $this->random;
53
  }
54
55
  /**
56
   * {@inheritdoc}
57
   */
58
  public function getFieldHandler($entity, $entity_type, $field_name) {
59
60
    $reflection = new \ReflectionClass($this);
61
    $core_namespace = $reflection->getShortName();
62
    $field_types = $this->getEntityFieldTypes($entity_type);
63
    $camelized_type = Container::camelize($field_types[$field_name]);
64
    $default_class = sprintf('\Drupal\Driver\Fields\%s\DefaultHandler', $core_namespace);
65
    $class_name = sprintf('\Drupal\Driver\Fields\%s\%sHandler', $core_namespace, $camelized_type);
66
    if (class_exists($class_name)) {
67
      return new $class_name($entity, $entity_type, $field_name);
68
    }
69
70
    return new $default_class($entity, $entity_type, $field_name);
71
  }
72
73
  /**
74
   * Expands properties on the given entity object to the expected structure.
75
   *
76
   * @param \stdClass $entity
77
   *   Entity object.
78
   */
79
  protected function expandEntityFields($entity_type, \stdClass $entity) {
80
81
    $field_types = $this->getEntityFieldTypes($entity_type);
82
    foreach ($field_types as $field_name => $type) {
83
      if (isset($entity->$field_name)) {
84
        $entity->$field_name = $this->getFieldHandler($entity, $entity_type, $field_name)
85
          ->expand($entity->$field_name);
86
      }
87
    }
88
  }
89
90
  /**
91
   * {@inheritdoc}
92
   */
93
  public function clearStaticCaches() {
94
95
  }
96
97
  /**
98
   * {@inheritdoc}
99
   */
100
  public function nodeLoad($nid) {
101
102
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
103
  }
104
105
  /**
106
   * {@inheritdoc}
107
   */
108
  public function nodeAlter($node, $values) {
109
110
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
111
  }
112
113
  /**
114
   * {@inheritdoc}
115
   */
116
  public function userLoad($uid) {
117
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
118
  }
119
120
  /**
121
   * {@inheritdoc}
122
   */
123
  public function userAlter($user, $values) {
124
125
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
126
  }
127
128
  /**
129
   * {@inheritdoc}
130
   */
131
  public function termLoad($tid, $vocabulary = NULL) {
132
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
133
  }
134
135
  /**
136
   * {@inheritdoc}
137
   */
138
  public function termCreate(\stdClass $term) {
139
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
140
  }
141
142
  /**
143
   * {@inheritdoc}
144
   */
145
  public function termDelete(\stdClass $term) {
146
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
147
  }
148
149
  /**
150
   * {@inheritdoc}
151
   */
152
  public function roleLoad($role_name) {
153
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
154
  }
155
156
  /**
157
   * {@inheritdoc}
158
   */
159
  public function roleCreate(array $permissions) {
160
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
161
  }
162
163
  /**
164
   * {@inheritdoc}
165
   */
166
  public function roleDelete($role_name) {
167
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
168
  }
169
170
  /**
171
   * {@inheritdoc}
172
   */
173
  public function languageLoad($language_name) {
0 ignored issues
show
Unused Code introduced by
The parameter $language_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
174
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
175
  }
176
177
  /**
178
   * {@inheritdoc}
179
   */
180
  public function languageCreate(\stdClass $language) {
181
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
182
  }
183
184
  /**
185
   * {@inheritdoc}
186
   */
187
  public function languageDelete(\stdClass $language) {
188
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
189
  }
190
191
  /**
192
   * {@inheritdoc}
193
   */
194
  public function nodeDeleteMultiple(array $nids) {
195
196
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
197
  }
198
199
  /**
200
   * {@inheritdoc}
201
   */
202
  public function userDeleteMultiple(array $uids) {
203
204
    throw new UnsupportedDriverActionException(sprintf('%s::%s line %s: functionality not yet supported for this Drupal Driver.', get_class($this), __FUNCTION__, __LINE__));
205
  }
206
207
}
208