X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FIndexer%2FClasses.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FIndexer%2FClasses.php;h=e5d962497a3f74c28928683004105a303b89b188;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/Classes.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/Classes.php new file mode 100644 index 000000000..e5d962497 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/Classes.php @@ -0,0 +1,118 @@ +find(Filter::isInstanceOf('\Pharborist\Objects\ClassNode')) + ->each([ $this, 'add' ]); + + $doc + ->find(Filter::isInstanceOf('\Pharborist\Objects\NewNode')) + ->each([ $this, 'add' ]); + } + + /** + * {@inheritdoc} + */ + public function add(NodeInterface $node) { + $fields = [ + 'file' => $node->getFilename(), + 'type' => get_class($node), + ]; + + if ($node instanceof ClassNode) { + $fields['id'] = (string) $node->getName(); + $fields['parent'] = (string) $node->getExtends(); + } + elseif ($node instanceof NewNode) { + $fields['id'] = (string) $node->getClassName(); + } + else { + throw new \InvalidArgumentException('Unexpected node type (expected ClassNode or NewNode).'); + } + + $this->db->insert($this->table)->fields($fields)->execute(); + } + + /** + * {@inheritdoc} + */ + public function get($identifier) { + $file = $this->getQuery(['file']) + ->condition('id', $identifier) + ->execute() + ->fetchField(); + + return $this->target + ->open($file) + ->find(Filter::isClass($identifier)) + ->get(0); + } + + /** + * {@inheritdoc} + */ + public function getFields() { + $fields = parent::getFields(); + + $fields['type'] = array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + ); + $fields['parent'] = array( + 'type' => 'varchar', + 'length' => 255, + ); + + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getUsages($identifier) { + $files = $this->getQuery(['file']) + ->distinct() + ->condition('id', $identifier) + ->condition('type', 'Pharborist\Objects\NewNode') + ->execute() + ->fetchCol(); + + $usages = new NodeCollection(); + foreach ($files as $file) { + $this->target + ->open($file) + ->find(Filter::isInstanceOf('\Pharborist\Objects\NewNode')) + ->filter(function(NewNode $node) use ($identifier) { + return $node->getClassName() == $identifier; + }) + ->addTo($usages); + } + + return $usages; + } + +}