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@17: * Magic method implementation to serialize the extension object. Chris@0: * Chris@17: * @return array Chris@17: * The names of all variables that should be serialized. Chris@0: */ Chris@17: public function __sleep() { Chris@17: // @todo \Drupal\Core\Extension\ThemeExtensionList is adding custom Chris@17: // properties to the Extension object. Chris@17: $properties = get_object_vars($this); Chris@0: // Don't serialize the app root, since this could change if the install is Chris@17: // moved. Don't serialize splFileInfo because it can not be. Chris@17: unset($properties['splFileInfo'], $properties['root']); Chris@17: return array_keys($properties); Chris@0: } Chris@0: Chris@0: /** Chris@17: * Magic method implementation to unserialize the extension object. Chris@0: */ Chris@17: public function __wakeup() { Chris@0: // Get the app root from the container. Chris@18: $this->root = \Drupal::hasService('app.root') ? \Drupal::root() : DRUPAL_ROOT; Chris@0: } Chris@0: Chris@0: }