Skip to content

Commit

Permalink
Merge pull request #98 from Ocramius/file-driver-as-orm-behavior
Browse files Browse the repository at this point in the history
File driver as orm behavior
  • Loading branch information
beberlei committed Mar 30, 2012
2 parents 7ec510d + bcbb9ad commit e02873e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/Doctrine/Common/Persistence/Mapping/Driver/FileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function getGlobalBasename()
* This will lazily load the mapping file if it is not loaded yet
*
* @return array $element The element of schema meta data
* @throws MappingException
*/
public function getElement($className)
{
Expand All @@ -97,6 +98,9 @@ public function getElement($className)
}

$result = $this->loadMappingFile($this->locator->findMappingFile($className));
if (!isset($result[$className])) {
throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->locator->getFileExtension());
}

return $result[$className];
}
Expand Down Expand Up @@ -175,4 +179,24 @@ protected function initialize()
}
}
}

/**
* Retrieve the locator used to discover mapping files by className
*
* @return FileLocator
*/
public function getLocator()
{
return $this->locator;
}

/**
* Set the locator used to discover mapping files by className
*
* @param FileLocator $locator
*/
public function setLocator(FileLocator $locator)
{
$this->locator = $locator;
}
}
5 changes: 5 additions & 0 deletions lib/Doctrine/Common/Persistence/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ public static function mappingFileNotFound($entityName, $fileName)
{
return new self("No mapping file found named '$fileName' for class '$entityName'.");
}

public static function invalidMappingFile($entityName, $fileName)
{
return new self("Invalid mapping file '$fileName' for class '$entityName'.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testFindMappingFile()

$locator = new DefaultFileLocator(array($path), ".yml");

$this->assertEquals(__DIR__ . '/_files/stdClass.yml', $locator->findMappingFile('stdClass'));
$this->assertEquals(__DIR__ . '/_files' . DIRECTORY_SEPARATOR . 'stdClass.yml', $locator->findMappingFile('stdClass'));
}

public function testFindMappingFileNotFound()
Expand Down

0 comments on commit e02873e

Please sign in to comment.