Skip to content
Browse files

Fixed tool to run in win32 environment

  • Loading branch information...
1 parent 4763cfa commit ca88d376c66872abb6c960221b1a61f9786f2b88 Ralph Schindler committed
View
2 bin/php-namespacer.php
@@ -13,4 +13,4 @@
}
$loader->register();
-$cliRunner = \PHPTools\Namespacer\CLIRunner::main();
+\PHPTools\Namespacer\CLIRunner::main();
View
103 library/PHPTools/Namespacer/CLIRunner.php
@@ -4,7 +4,7 @@
class CLIRunner
{
-
+
public static function main()
{
$cliRunner = new self();
@@ -18,61 +18,64 @@ public function __construct()
}
}
- public function run()
+ public function run($options = array())
{
$namespacer = new Namespacer();
- $this->_parseOptions($namespacer);
+ $this->_parseOptions($namespacer, $options);
}
- protected function _parseOptions(Namespacer $namespacer)
+ protected function _parseOptions(Namespacer $namespacer, array $options = array())
{
- $usersOptions = getopt(
- 'h::l::d::o::p::s::m::',
- array(
- 'help::',
- 'lib::',
- 'library-directory::',
- 'dir::',
- 'directory-filter::',
- 'out::',
- 'output-path::',
- 'prefix::',
- 'prefixes::',
- 'stats::',
- 'show-statistics::',
- 'map::',
- 'map-path::'
- )
- );
-
- $userToOfficialNames = array(
- 'h' => 'help',
- 'help' => 'help',
- 'l' => 'libraryDirectory',
- 'lib' => 'libraryDirectory',
- 'library-directory' => 'libraryDirectory',
- 'd' => 'directoryFilter',
- 'dir' => 'directoryFilter',
- 'directory-filter' => 'directoryFilter',
- 'o' => 'outputPath',
- 'out' => 'outputPath',
- 'output-path' => 'outputPath',
- 'p' => 'prefixes',
- 'prefix' => 'prefixes',
- 'prefixes' => 'prefixes',
- 's' => 'showStatistics',
- 'stats' => 'showStatistics',
- 'show-statistics' => 'showStatistics',
- 'm' => 'mapPath',
- 'map' => 'mapPath',
- 'map-path' => 'mapPath'
- );
+ if (!$options) {
- $options = array();
-
- foreach ($userToOfficialNames as $userOptionName => $officialName) {
- if (isset($usersOptions[$userOptionName])) {
- $options[$officialName] = $usersOptions[$userOptionName];
+ $usersOptions = getopt(
+ 'h::l::d::o::p::s::m::',
+ array(
+ 'help::',
+ 'lib::',
+ 'library-directory::',
+ 'dir::',
+ 'directory-filter::',
+ 'out::',
+ 'output-path::',
+ 'prefix::',
+ 'prefixes::',
+ 'stats::',
+ 'show-statistics::',
+ 'map::',
+ 'map-path::'
+ )
+ );
+
+ $userToOfficialNames = array(
+ 'h' => 'help',
+ 'help' => 'help',
+ 'l' => 'libraryDirectory',
+ 'lib' => 'libraryDirectory',
+ 'library-directory' => 'libraryDirectory',
+ 'd' => 'directoryFilter',
+ 'dir' => 'directoryFilter',
+ 'directory-filter' => 'directoryFilter',
+ 'o' => 'outputPath',
+ 'out' => 'outputPath',
+ 'output-path' => 'outputPath',
+ 'p' => 'prefixes',
+ 'prefix' => 'prefixes',
+ 'prefixes' => 'prefixes',
+ 's' => 'showStatistics',
+ 'stats' => 'showStatistics',
+ 'show-statistics' => 'showStatistics',
+ 'm' => 'mapPath',
+ 'map' => 'mapPath',
+ 'map-path' => 'mapPath'
+ );
+
+ $options = array();
+
+ foreach ($userToOfficialNames as $userOptionName => $officialName) {
+ if (isset($usersOptions[$userOptionName])) {
+ $options[$officialName] = $usersOptions[$userOptionName];
+ }
}
}
View
2 library/PHPTools/Namespacer/FileNameProcessor.php
@@ -24,7 +24,7 @@ public function __construct($relativeFilePath, $libraryPath)
public function getOriginalFilePath()
{
- return rtrim($this->_libraryPath, '/') . '/' . $this->_originalRelativeFilePath;
+ return rtrim($this->_libraryPath, '/\\') . DIRECTORY_SEPARATOR . $this->_originalRelativeFilePath;
}
public function getOriginalRelativeFilePath()
View
7 library/PHPTools/Namespacer/Namespacer.php
@@ -106,8 +106,11 @@ public function convert()
$xmlWriter->writeAttribute('libraryPath', $this->_libraryDirectory);
}
- foreach (new \RecursiveIteratorIterator($rdi) as $realFilePath => $fileInfo) {
+ foreach (new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::SELF_FIRST) as $realFilePath => $fileInfo) {
$relativeFilePath = substr($realFilePath, strlen($this->_libraryDirectory)+1);
+ if (preg_match('#(\.svn|_svn|\.git)#', $relativeFilePath)) {
+ continue;
+ }
$fileNameProcessor = new FileNameProcessor($relativeFilePath, $this->_libraryDirectory);
// add only classes that contain a matching prefix
if (!$this->_prefixes || preg_match('#^' . implode('|', $this->_prefixes) . '#', $fileNameProcessor->getOriginalClassName())) {
@@ -125,7 +128,7 @@ public function convert()
}
}
- foreach (new \RecursiveIteratorIterator($it) as $realFilePath => $fileinfo) {
+ foreach (new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST) as $realFilePath => $fileinfo) {
if ($fileinfo->isFile()) {
$fileNameProc = $this->_fileRegistry->findByOriginalFilePath($realFilePath);
if ($fileNameProc) {
View
9 library/PHPTools/Namespacer/RecursiveFilterIterator.php
@@ -16,7 +16,7 @@ class RecursiveFilterIterator extends \RecursiveFilterIterator
*/
public function __construct(\RecursiveIterator $iterator, $filter, $topDirectory = null)
{
- $this->_filter = $filter;
+ $this->_filter = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $filter);
if ($topDirectory == null) {
$iterator->rewind();
$this->_topDirectory = (string) $iterator->current()->getPath();
@@ -29,15 +29,16 @@ public function __construct(\RecursiveIterator $iterator, $filter, $topDirectory
public function accept()
{
- if ($this->isDot()) {
+ $relativeFileName = substr($this->current()->getRealPath(), strlen($this->_topDirectory)+1);
+
+ if ($this->isDot() || preg_match('#(\.svn|_svn|\.git)#', $relativeFileName)) {
return false;
}
if ($this->isDir()) {
return true;
}
-
- $relativeFileName = substr($this->current()->getRealPath(), strlen($this->_topDirectory)+1);
+
if (preg_match('#^' . preg_quote($this->_filter) . '#', $relativeFileName)) {
return true;
} else {

0 comments on commit ca88d37

Please sign in to comment.
Something went wrong with that request. Please try again.