Skip to content

Commit

Permalink
Use DIRECTORY_SEPARATOR for Windows
Browse files Browse the repository at this point in the history
Issue #43
  • Loading branch information
BrianHenryIE committed Aug 7, 2020
1 parent 00da9e0 commit 989c2fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Composer/Autoload/Psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public function getSearchNamespace()

public function getNamespacePath()
{
return str_replace('\\', '/', $this->namespace);
return str_replace('\\', DIRECTORY_SEPARATOR, $this->namespace);
}
}
5 changes: 3 additions & 2 deletions src/Console/Commands/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$workingDir = getcwd();
$this->workingDir = $workingDir;

$composerFile = $workingDir . '/composer.json';
$composerFile = $workingDir . DIRECTORY_SEPARATOR. 'composer.json';
if (!file_exists($composerFile)) {
$output->write('No composer.json found at current directory: ' . $workingDir);
return 1;
Expand Down Expand Up @@ -148,7 +148,8 @@ private function findPackages($slugs)
$packages = [];

foreach ($slugs as $package_slug) {
$packageDir = $this->workingDir . '/vendor/' . $package_slug .'/';
$packageDir = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor'
. DIRECTORY_SEPARATOR . $package_slug . DIRECTORY_SEPARATOR;

if (! is_dir($packageDir)) {
continue;
Expand Down
19 changes: 12 additions & 7 deletions src/Mover.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public function movePackage(Package $package)
$finder = new Finder();

foreach ($autoloader->paths as $path) {
$source_path = $this->workingDir . '/vendor/' . $package->config->name . '/' . $path;
$source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor'
. DIRECTORY_SEPARATOR . $package->config->name . DIRECTORY_SEPARATOR . $path;

$finder->files()->in($source_path);

Expand All @@ -110,7 +111,8 @@ public function movePackage(Package $package)
$finder = new Finder();

foreach ($autoloader->files as $file) {
$source_path = $this->workingDir . '/vendor/' . $package->config->name;
$source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor'
. DIRECTORY_SEPARATOR . $package->config->name;
$finder->files()->name($file)->in($source_path);

foreach ($finder as $foundFile) {
Expand All @@ -121,7 +123,8 @@ public function movePackage(Package $package)
$finder = new Finder();

foreach ($autoloader->paths as $path) {
$source_path = $this->workingDir . '/vendor/' . $package->config->name . '/' . $path;
$source_path = $this->workingDir . DIRECTORY_SEPARATOR . 'vendor'
. DIRECTORY_SEPARATOR . $package->config->name . DIRECTORY_SEPARATOR . $path;

$finder->files()->in($source_path);

Expand Down Expand Up @@ -153,15 +156,17 @@ public function moveFile(Package $package, $autoloader, $file, $path = '')
$replaceWith = $this->config->dep_directory . $namespacePath;
$targetFile = str_replace($this->workingDir, $replaceWith, $file->getPathname());

$packageVendorPath = '/vendor/' . $package->config->name . '/' . $path;
$packageVendorPath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->config->name
. DIRECTORY_SEPARATOR . $path;
$packageVendorPath = str_replace('/', DIRECTORY_SEPARATOR, $packageVendorPath);
$targetFile = str_replace($packageVendorPath, '', $targetFile);
} else {
$namespacePath = $package->config->name;
$replaceWith = $this->config->classmap_directory . '/' . $namespacePath;
$replaceWith = $this->config->classmap_directory . DIRECTORY_SEPARATOR . $namespacePath;
$targetFile = str_replace($this->workingDir, $replaceWith, $file->getPathname());

$packageVendorPath = '/vendor/' . $package->config->name . '/';
$packageVendorPath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->config->name
. DIRECTORY_SEPARATOR;
$packageVendorPath = str_replace('/', DIRECTORY_SEPARATOR, $packageVendorPath);
$targetFile = str_replace($packageVendorPath, DIRECTORY_SEPARATOR, $targetFile);
}
Expand All @@ -182,7 +187,7 @@ public function moveFile(Package $package, $autoloader, $file, $path = '')
protected function deletePackageVendorDirectories()
{
foreach ($this->movedPackages as $movedPackage) {
$packageDir = '/vendor/' . $movedPackage;
$packageDir = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $movedPackage;
if (is_link($packageDir)) {
continue;
}
Expand Down
12 changes: 8 additions & 4 deletions src/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ public function replaceInFile($targetFile, $autoloader)
public function replacePackageByAutoloader(Package $package, $autoloader)
{
if ($autoloader instanceof NamespaceAutoloader) {
$source_path = $this->workingDir . $this->targetDir . str_replace('\\', '/', $autoloader->namespace) . '/';
$source_path = $this->workingDir . $this->targetDir
. str_replace('\\', DIRECTORY_SEPARATOR, $autoloader->namespace)
. DIRECTORY_SEPARATOR;
$this->replaceInDirectory($autoloader, $source_path);
} elseif ($autoloader instanceof Classmap) {
$finder = new Finder();
$source_path = $this->workingDir . $this->config->classmap_directory . '/' . $package->config->name;
$source_path = $this->workingDir . $this->config->classmap_directory . DIRECTORY_SEPARATOR
. $package->config->name;
$finder->files()->in($source_path);

foreach ($finder as $foundFile) {
Expand Down Expand Up @@ -156,8 +159,9 @@ public function replaceParentPackage(Package $package, $parent)
foreach ($parent->autoloaders as $parentAutoloader) {
foreach ($package->autoloaders as $autoloader) {
if ($parentAutoloader instanceof NamespaceAutoloader) {
$namespace = str_replace('\\', '/', $parentAutoloader->namespace);
$directory = $this->workingDir . $this->config->dep_directory . $namespace . '/';
$namespace = str_replace('\\', DIRECTORY_SEPARATOR, $parentAutoloader->namespace);
$directory = $this->workingDir . $this->config->dep_directory . $namespace
. DIRECTORY_SEPARATOR;

if ($autoloader instanceof NamespaceAutoloader) {
$this->replaceInDirectory($autoloader, $directory);
Expand Down

0 comments on commit 989c2fd

Please sign in to comment.