Skip to content

Commit

Permalink
Refactor: Extract a method
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke committed Nov 19, 2016
1 parent a4adb59 commit cce74f0
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/Composer/StudioPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class StudioPlugin implements PluginInterface, EventSubscriberInterface
*/
protected $io;

/**
* @var string|null
*/
protected $targetDir;

public function activate(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
Expand All @@ -42,24 +37,38 @@ public static function getSubscribedEvents()
];
}

/**
* Register all managed paths with Composer.
*
* This function configures Composer to treat all Studio-managed paths as local path repositories, so that packages
* therein will be symlinked directly.
*/
public function registerStudioPackages()
{
$this->targetDir = realpath($this->composer->getPackage()->getTargetDir());

$config = Config::make("{$this->targetDir}/studio.json");
$repoManager = $this->composer->getRepositoryManager();
$composerConfig = $this->composer->getConfig();

if ($config->hasPackages()) {
$repoManager = $this->composer->getRepositoryManager();
$composerConfig = $this->composer->getConfig();
foreach ($this->getManagedPaths() as $path) {
$this->io->writeError("[Studio] Loading path $path");

foreach ($config->getPaths() as $path) {
$this->io->writeError("[Studio] Loading path $path");
$repoManager->prependRepository(new PathRepository(
['url' => $path],
$this->io,
$composerConfig
));
}
$repoManager->prependRepository(new PathRepository(
['url' => $path],
$this->io,
$composerConfig
));
}
}

/**
* Get the list of paths that are being managed by Studio.
*
* @return array
*/
private function getManagedPaths()
{
$targetDir = realpath($this->composer->getPackage()->getTargetDir());
$config = Config::make("{$targetDir}/studio.json");

return $config->getPaths();
}
}

0 comments on commit cce74f0

Please sign in to comment.