Permalink
Browse files

Fix - relative paths are persisted in XML and respected in Namespacer

  • Loading branch information...
1 parent a367b7d commit d232cb3e4f1448daccefc74882da1862cda7656f Ralph Schindler committed Mar 26, 2010
Showing with 15 additions and 6 deletions.
  1. +5 −0 library/PHPTools/Namespacer/CLIRunner.php
  2. +10 −6 library/PHPTools/Namespacer/Namespacer.php
@@ -7,6 +7,11 @@ class CLIRunner
public static function main()
{
+ if (($cwd = getenv('CURRENT_WORKING_DIRECTORY'))) {
+ if (!file_exists($cwd)) exit('Invalid CURRENT_WORKING_DIRECTORY');
+ chdir($cwd);
+ }
+
$cliRunner = new self();
$cliRunner->run();
}
@@ -7,6 +7,7 @@ class Namespacer
{
protected $_libraryDirectory = null;
+ protected $_libraryDirectoryOriginal = null;
protected $_filePath = null;
protected $_directoryFilter = null;
protected $_outputPath = null;
@@ -34,7 +35,8 @@ public function setOption($optionName, $optionValue = true)
{
switch ($optionName) {
case 'libraryDirectory':
- $this->_libraryDirectory = realpath($optionValue);
+ $this->_libraryDirectoryOriginal = $optionValue;
+ $this->_libraryDirectory = realpath($this->_libraryDirectoryOriginal);
if (!file_exists($this->_libraryDirectory)) {
throw new \InvalidArgumentException('Library directory provided does not exist (' . $this->_libraryDirectory . ')');
}
@@ -112,7 +114,7 @@ public function convert()
$xmlWriter->setIndentString(' ');
$xmlWriter->startDocument('1.0');
$xmlWriter->startElement('mappedClasses');
- $xmlWriter->writeAttribute('libraryDirectory', $this->_libraryDirectory);
+ $xmlWriter->writeAttribute('libraryDirectory', $this->_libraryDirectoryOriginal);
}
}
@@ -149,9 +151,10 @@ public function convert()
if ($this->_outputPath) {
- foreach (new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST) as $realFilePath => $fileinfo) {
- if ($fileinfo->isFile()) {
- $fileNameProc = $this->_fileRegistry->findByOriginalFilePath($realFilePath);
+ foreach (new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST) as $realFilePath => $fileInfo) {
+ if ($fileInfo->isFile()) {
+ $relativeFilePath = substr($realFilePath, strlen($this->_libraryDirectory)+1);
+ $fileNameProc = $this->_fileRegistry->findByOriginalRelativeFilePath($relativeFilePath);
if ($fileNameProc) {
$fileContentProcessor = new FileContentProcessor($fileNameProc, $this->_prefixes, $this->_fileRegistry);
$this->_fileRegistry->registerFileContentProcessor($fileContentProcessor);
@@ -195,7 +198,8 @@ protected function _loadMapFile($mapFile)
while ($reader->read()) {
if ($reader->name == 'mappedClasses' && $reader->nodeType == XMLReader::ELEMENT) {
$libraryDirectory = $reader->getAttribute('libraryDirectory');
- if ($libraryDirectory != $this->_libraryDirectory) {
+ $realLibraryDirectory = realpath($libraryDirectory);
+ if ($realLibraryDirectory != $this->_libraryDirectory) {
throw new \UnexpectedValueException('The libraryDirectory located in the map file is not the same as the one provided for execution.');
}
continue;

0 comments on commit d232cb3

Please sign in to comment.