Skip to content
This repository was archived by the owner on Jan 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/Midgard/CreatePHP/Metadata/RdfDriverXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,30 @@ protected function buildFileName($className)
{
return str_replace('\\', '.', $className) . '.xml';
}
protected function buildClassName($filename)
{
return str_replace('.', '\\', substr($filename, 0, -4));
}

/**
* Gets the names of all classes known to this driver.
* {@inheritDoc}
*
* @return array The names of all classes known to this driver.
* @return array The names of all classes known to this driver, indexed by
* the RDF types.
*/
function getAllClassNames()
public function getAllClassNames()
{
//TODO loop through all provided paths and convert filenames back to class names
$classes = array();
foreach ($this->directories as $dir) {
foreach (glob($dir . DIRECTORY_SEPARATOR . '*.xml') as $file) {
$xml = simplexml_load_file($file);
$namespaces = $xml->getDocNamespaces();

list($prefix, $localname) = preg_split('/:/', $xml['typeof']);
$type = $namespaces[$prefix] . $localname;
$classes[$type] = $this->buildClassName(basename($file));
}
}
return $classes;
}
}
7 changes: 6 additions & 1 deletion tests/Test/Midgard/CreatePHP/Metadata/RdfDriverXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function testLoadTypeForClassNodefinition()
*/
function testGetAllClassNames()
{
// TODO
$map = $this->driver->getAllClassNames();
$this->assertCount(1, $map);
$types = array(
'http://rdfs.org/sioc/ns#Post' => 'Test\\Midgard\\CreatePHP\\Model',
);
$this->assertEquals($types, $map);
}
}