Skip to content

Commit

Permalink
Added Plugin::addFile() and used in loadDotEnv to prevent dublicating
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Dec 20, 2018
1 parent 959c971 commit 0c8c821
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function loadDotEnv(Package $package)
{
$path = $package->preparePath('.env');
if (file_exists($path) && class_exists('Dotenv\Dotenv')) {
array_push($this->files['dotenv'], $path);
$this->addFile($package, 'dotenv', $path);
}
}

Expand All @@ -174,22 +174,27 @@ protected function addFiles(Package $package, array $files)
$paths = array_reverse($paths);
}
foreach ($paths as $path) {
if (!isset($this->files[$name])) {
$this->files[$name] = [];
}
$path = $package->preparePath($path);
if (in_array($path, $this->files[$name], true)) {
continue;
}
if ('defines' === $name) {
array_unshift($this->files[$name], $path);
} else {
array_push($this->files[$name], $path);
}
$this->addFile($package, $name, $path);
}
}
}

protected function addFile(Package $package, string $name, string $path)
{
$path = $package->preparePath($path);
if (!isset($this->files[$name])) {
$this->files[$name] = [];
}
if (in_array($path, $this->files[$name], true)) {
return;
}
if ('defines' === $name) {
array_unshift($this->files[$name], $path);
} else {
array_push($this->files[$name], $path);
}
}

/**
* Sets [[packages]].
* @param Package[] $packages
Expand Down

0 comments on commit 0c8c821

Please sign in to comment.