X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FFixer%2FCreateClass.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FFixer%2FCreateClass.php;h=45d4734c7a44d8e8605266babb0f46549d8d3a9d;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/CreateClass.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/CreateClass.php new file mode 100644 index 000000000..45d4734c7 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/CreateClass.php @@ -0,0 +1,84 @@ +fs = new Filesystem(); + } + + public function execute() { + $ns = $this->extractNS($this->configuration['class']); + $class = $this->extractLocal($this->configuration['class']); + + $doc = RootNode::create($ns); + $ns = $doc->getNamespace($ns); + Token::newline()->insertBefore($ns); + Token::newline()->appendTo($ns); + $class = ClassNode::create($class); + + if ($parent = $this->configuration['parent']) { + Parser::parseSnippet('use ' . ltrim($parent, '\\') . ';') + ->appendTo($ns) + ->after(Token::newline()); + $class->setExtends($this->extractLocal($parent)); + } + + $interfaces = (array) $this->configuration['interfaces']; + foreach ($interfaces as $interface) { + Parser::parseSnippet('use ' . ltrim($interface, '\\') . ';') + ->appendTo($ns) + ->after(Token::newline()); + } + $class->setImplements(array_map([ $this, 'extractLocal' ], $interfaces)); + + if (isset($this->configuration['doc'])) { + $class->setDocComment(DocCommentNode::create($this->configuration['doc'])); + } + + $class->appendTo($ns)->before(Token::newline()); + + $destination = $this->getUnaliasedPath($this->configuration['destination']); + $dir = subStr($destination, 0, strrPos($destination, '/')); + $this->fs->mkdir($dir); + file_put_contents($destination, $doc->getText()); + // Need to store the class' local name as its index identifier because + // \Pharborist\Filter::isClass() doesn't support lookup by qualified path. + $this->target->getIndexer('class')->addFile($destination); + } + + protected function extractLocal($path) { + return subStr($path, strrPos($path, '\\') + 1); + } + + protected function extractNS($path) { + $path = ltrim($path, '\\'); + return subStr($path, 0, strrPos($path, '\\')); + } + +}