comparison core/lib/Drupal/Core/Extension/Extension.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
2 2
3 namespace Drupal\Core\Extension; 3 namespace Drupal\Core\Extension;
4 4
5 /** 5 /**
6 * Defines an extension (file) object. 6 * Defines an extension (file) object.
7 *
8 * This class does not implement the Serializable interface since problems
9 * occurred when using the serialize method.
10 *
11 * @see https://bugs.php.net/bug.php?id=66052
7 */ 12 */
8 class Extension implements \Serializable { 13 class Extension {
9 14
10 /** 15 /**
11 * The type of the extension (e.g., 'module'). 16 * The type of the extension (e.g., 'module').
12 * 17 *
13 * @var string 18 * @var string
154 } 159 }
155 return call_user_func_array([$this->splFileInfo, $method], $args); 160 return call_user_func_array([$this->splFileInfo, $method], $args);
156 } 161 }
157 162
158 /** 163 /**
159 * Implements Serializable::serialize(). 164 * Magic method implementation to serialize the extension object.
160 * 165 *
161 * Serializes the Extension object in the most optimized way. 166 * @return array
167 * The names of all variables that should be serialized.
162 */ 168 */
163 public function serialize() { 169 public function __sleep() {
170 // @todo \Drupal\Core\Extension\ThemeExtensionList is adding custom
171 // properties to the Extension object.
172 $properties = get_object_vars($this);
164 // Don't serialize the app root, since this could change if the install is 173 // Don't serialize the app root, since this could change if the install is
165 // moved. 174 // moved. Don't serialize splFileInfo because it can not be.
166 $data = [ 175 unset($properties['splFileInfo'], $properties['root']);
167 'type' => $this->type, 176 return array_keys($properties);
168 'pathname' => $this->pathname,
169 'filename' => $this->filename,
170 ];
171
172 // @todo ThemeHandler::listInfo(), ThemeHandler::rebuildThemeData(), and
173 // system_list() are adding custom properties to the Extension object.
174 $info = new \ReflectionObject($this);
175 foreach ($info->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
176 $data[$property->getName()] = $property->getValue($this);
177 }
178
179 return serialize($data);
180 } 177 }
181 178
182 /** 179 /**
183 * {@inheritdoc} 180 * Magic method implementation to unserialize the extension object.
184 */ 181 */
185 public function unserialize($data) { 182 public function __wakeup() {
186 $data = unserialize($data);
187 // Get the app root from the container. 183 // Get the app root from the container.
188 $this->root = DRUPAL_ROOT; 184 $this->root = DRUPAL_ROOT;
189 $this->type = $data['type'];
190 $this->pathname = $data['pathname'];
191 $this->filename = $data['filename'];
192
193 // @todo ThemeHandler::listInfo(), ThemeHandler::rebuildThemeData(), and
194 // system_list() are adding custom properties to the Extension object.
195 foreach ($data as $property => $value) {
196 if (!isset($this->$property)) {
197 $this->$property = $value;
198 }
199 }
200 } 185 }
201 186
202 } 187 }