Chris@0: root = $root; Chris@0: $this->type = $type; Chris@0: $this->pathname = $pathname; Chris@0: $this->filename = $filename; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the type of the extension. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getType() { Chris@0: return $this->type; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the internal name of the extension. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getName() { Chris@0: return basename($this->pathname, '.info.yml'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the relative path of the extension. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getPath() { Chris@0: return dirname($this->pathname); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the relative path and filename of the extension's info file. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getPathname() { Chris@0: return $this->pathname; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the filename of the extension's info file. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getFilename() { Chris@0: return basename($this->pathname); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the relative path of the main extension file, if any. Chris@0: * Chris@0: * @return string|null Chris@0: */ Chris@0: public function getExtensionPathname() { Chris@0: if ($this->filename) { Chris@0: return $this->getPath() . '/' . $this->filename; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the name of the main extension file, if any. Chris@0: * Chris@0: * @return string|null Chris@0: */ Chris@0: public function getExtensionFilename() { Chris@0: return $this->filename; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Loads the main extension file, if any. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if this extension has a main extension file, FALSE otherwise. Chris@0: */ Chris@0: public function load() { Chris@0: if ($this->filename) { Chris@0: include_once $this->root . '/' . $this->getPath() . '/' . $this->filename; Chris@0: return TRUE; Chris@0: } Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Re-routes method calls to SplFileInfo. Chris@0: * Chris@0: * Offers all SplFileInfo methods to consumers; e.g., $extension->getMTime(). Chris@0: */ Chris@0: public function __call($method, array $args) { Chris@0: if (!isset($this->splFileInfo)) { Chris@0: $this->splFileInfo = new \SplFileInfo($this->pathname); Chris@0: } Chris@0: return call_user_func_array([$this->splFileInfo, $method], $args); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Implements Serializable::serialize(). Chris@0: * Chris@0: * Serializes the Extension object in the most optimized way. Chris@0: */ Chris@0: public function serialize() { Chris@0: // Don't serialize the app root, since this could change if the install is Chris@0: // moved. Chris@0: $data = [ Chris@0: 'type' => $this->type, Chris@0: 'pathname' => $this->pathname, Chris@0: 'filename' => $this->filename, Chris@0: ]; Chris@0: Chris@0: // @todo ThemeHandler::listInfo(), ThemeHandler::rebuildThemeData(), and Chris@0: // system_list() are adding custom properties to the Extension object. Chris@0: $info = new \ReflectionObject($this); Chris@0: foreach ($info->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { Chris@0: $data[$property->getName()] = $property->getValue($this); Chris@0: } Chris@0: Chris@0: return serialize($data); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function unserialize($data) { Chris@0: $data = unserialize($data); Chris@0: // Get the app root from the container. Chris@0: $this->root = DRUPAL_ROOT; Chris@0: $this->type = $data['type']; Chris@0: $this->pathname = $data['pathname']; Chris@0: $this->filename = $data['filename']; Chris@0: Chris@0: // @todo ThemeHandler::listInfo(), ThemeHandler::rebuildThemeData(), and Chris@0: // system_list() are adding custom properties to the Extension object. Chris@0: foreach ($data as $property => $value) { Chris@0: if (!isset($this->$property)) { Chris@0: $this->$property = $value; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }