X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FIndexer%2FConstants.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FIndexer%2FConstants.php;h=e4b80496d2f2ca18e43beae9cccb03af2c9ff270;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/Constants.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/Constants.php new file mode 100644 index 000000000..e4b80496d --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/Constants.php @@ -0,0 +1,94 @@ +find(Filter::isInstanceOf('\Pharborist\Constants\ConstantNode', '\Pharborist\Functions\DefineNode', '\Pharborist\Constants\ConstantDeclarationNode')) + ->each([ $this, 'add' ]); + } + + /** + * {@inheritdoc} + */ + public function add(NodeInterface $node) { + if ($node instanceof DefineNode) { + list ($key, $value) = $node->getArguments(); + if ($key instanceof StringNode && $value instanceof ScalarNode) { + $this->elements[ $key->toValue() ] = $value->toValue(); + } + } + elseif ($node instanceof ConstantDeclarationNode) { + $value = $node->getValue(); + if ($value instanceof ScalarNode) { + $this->elements[ (string) $node->getName() ] = $value->toValue(); + } + } + elseif ($node instanceof ConstantNode) { + $this->db + ->insert($this->table) + ->fields([ + 'id' => (string) $node->getConstantName(), + // Hardcoding file name, as file name resolution is unavailable due + // to changes upstream in Pharborist. + 'file' => 'foo.module', + ]) + ->execute(); + } + else { + throw new \InvalidArgumentException('Unexpected node type (expected DefineNode, ConstantDeclarationNode, or ConstantNode).'); + } + } + + /** + * {@inheritdoc} + */ + public function getUsages($identifier) { + $files = $this->getQuery(['file']) + ->distinct() + ->condition('id', $identifier) + ->execute() + ->fetchCol(); + + $usages = new NodeCollection(); + foreach ($files as $file) { + $this->target + ->open($file) + ->find(Filter::isInstanceOf('\Pharborist\Constants\ConstantNode')) + ->filter(function(ConstantNode $node) use ($identifier) { + return $node->getConstantName() == $identifier; + }) + ->addTo($usages); + } + + return $usages; + } + +}