From 1a3399aabbe91068e131e726662d48bbf22a86ee Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 27 Oct 2012 17:55:23 +0200 Subject: [PATCH] implement RdfDriverXml::getAllClassNames --- .../CreatePHP/Metadata/RdfDriverXml.php | 24 +++++++++++++++---- .../CreatePHP/Metadata/RdfDriverXmlTest.php | 7 +++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Midgard/CreatePHP/Metadata/RdfDriverXml.php b/src/Midgard/CreatePHP/Metadata/RdfDriverXml.php index 0175710..c5d149c 100644 --- a/src/Midgard/CreatePHP/Metadata/RdfDriverXml.php +++ b/src/Midgard/CreatePHP/Metadata/RdfDriverXml.php @@ -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; } } diff --git a/tests/Test/Midgard/CreatePHP/Metadata/RdfDriverXmlTest.php b/tests/Test/Midgard/CreatePHP/Metadata/RdfDriverXmlTest.php index 8efd1e1..1141c80 100644 --- a/tests/Test/Midgard/CreatePHP/Metadata/RdfDriverXmlTest.php +++ b/tests/Test/Midgard/CreatePHP/Metadata/RdfDriverXmlTest.php @@ -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); } }