From 663d98b9b196b8962ab9c15ce9bf08f7a99f11e5 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 5 Apr 2016 20:37:50 +0900 Subject: [PATCH 01/18] Alias new branch to 0.11 branch --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c0337d..2a1ccea 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ }, "extra": { "branch-alias": { - "dev-master": "0.10.x-dev" + "dev-master": "0.10.x-dev", + "dev-next": "0.11.x-dev" }, "class": "Studio\\Composer\\StudioPlugin" }, From dc6eb3d446a4020ac8eacc6941b5ef1cbc229a29 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 5 Apr 2016 21:40:58 +0900 Subject: [PATCH 02/18] Plugin: Load paths, not packages In preparation for #54. --- src/Composer/StudioPlugin.php | 4 ++-- src/Config/Config.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Composer/StudioPlugin.php b/src/Composer/StudioPlugin.php index 482fe92..00c22d7 100644 --- a/src/Composer/StudioPlugin.php +++ b/src/Composer/StudioPlugin.php @@ -55,8 +55,8 @@ public function registerStudioPackages(Event $event) $repoManager = $event->getComposer()->getRepositoryManager(); $composerConfig = $event->getComposer()->getConfig(); - foreach ($config->getPackages() as $package => $path) { - $io->writeError("[Studio] Registering package $package with $path"); + foreach ($config->getPaths() as $path) { + $io->writeError("[Studio] Loading path $path"); $repoManager->prependRepository(new PathRepository( ['url' => $path], $io, diff --git a/src/Config/Config.php b/src/Config/Config.php index 8e1aed9..e11b155 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -31,6 +31,11 @@ public function getPackages() return $this->packages; } + public function getPaths() + { + return array_values($this->getPackages()); + } + public function addPackage(Package $package) { // Ensure our packages are loaded From 60e130378d5e573409416b70406ea0543e908699 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 5 Apr 2016 21:46:23 +0900 Subject: [PATCH 03/18] Make method private --- src/Config/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index e11b155..1480207 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -21,7 +21,7 @@ public function __construct(StorageInterface $storage) $this->storage = $storage; } - public function getPackages() + private function getPackages() { if (! $this->loaded) { $this->packages = $this->storage->load(); From 9c59cb1b09d4695b83cd634882b356fb95c164df Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 5 Apr 2016 22:11:06 +0900 Subject: [PATCH 04/18] Change Config to deal with paths instead of packages Refs #54. --- bin/studio | 3 +- src/Composer/StudioPlugin.php | 14 +------ src/Config/Config.php | 42 +++++++++++-------- src/Config/Storage.php | 10 +++++ .../{FileStorage.php => Version1Storage.php} | 16 +++++-- 5 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 src/Config/Storage.php rename src/Config/{FileStorage.php => Version1Storage.php} (72%) diff --git a/bin/studio b/bin/studio index 8ece4be..e234dc7 100755 --- a/bin/studio +++ b/bin/studio @@ -20,8 +20,7 @@ use Studio\Console\LoadCommand; use Studio\Console\ScrapCommand; use Symfony\Component\Console\Application; -$studioFile = getcwd().'/studio.json'; -$config = new Config(new FileStorage($studioFile)); +$config = Config::make(); $application = new Application('studio', '0.10.0'); $application->add(new CreateCommand($config)); diff --git a/src/Composer/StudioPlugin.php b/src/Composer/StudioPlugin.php index 00c22d7..cb3f362 100644 --- a/src/Composer/StudioPlugin.php +++ b/src/Composer/StudioPlugin.php @@ -46,9 +46,8 @@ public static function getSubscribedEvents() public function registerStudioPackages(Event $event) { $this->targetDir = realpath($event->getComposer()->getPackage()->getTargetDir()); - $studioFile = "{$this->targetDir}/studio.json"; - $config = $this->getConfig($studioFile); + $config = Config::make("{$this->targetDir}/studio.json"); if ($config->hasPackages()) { $io = $event->getIO(); @@ -65,15 +64,4 @@ public function registerStudioPackages(Event $event) } } } - - /** - * Instantiate and return the config object. - * - * @param string $file - * @return Config - */ - protected function getConfig($file) - { - return new Config(new FileStorage($file)); - } } diff --git a/src/Config/Config.php b/src/Config/Config.php index 1480207..550ad9b 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -7,61 +7,67 @@ class Config { /** - * @var StorageInterface + * @var Storage */ protected $storage; - protected $packages; + protected $paths; protected $loaded = false; - public function __construct(StorageInterface $storage) + public function __construct(Storage $storage) { $this->storage = $storage; } - private function getPackages() + public static function make($file = null) { - if (! $this->loaded) { - $this->packages = $this->storage->load(); - $this->loaded = true; + if (is_null($file)) { + $file = getcwd().'/studio.json'; } - return $this->packages; + return new static( + new Version1Storage($file) + ); } public function getPaths() { - return array_values($this->getPackages()); + if (! $this->loaded) { + $this->paths = $this->storage->readPaths(); + $this->loaded = true; + } + + return $this->paths; } public function addPackage(Package $package) { // Ensure our packages are loaded - $this->getPackages(); + $this->getPaths(); - $this->packages[$package->getComposerId()] = $package->getPath(); - $this->storage->store($this->packages); + $this->paths[] = $package->getPath(); + $this->storage->writePaths($this->paths); } public function hasPackages() { // Ensure our packages are loaded - $this->getPackages(); + $this->getPaths(); - return ! empty($this->packages); + return ! empty($this->paths); } public function removePackage(Package $package) { // Ensure our packages are loaded - $this->getPackages(); + $this->getPaths(); - $key = $package->getComposerId(); + $path = $package->getPath(); - if (isset($this->packages[$key])) { - unset($this->packages[$key]); + if (($key = array_search($path, $this->paths)) !== false) { + unset($this->paths[$key]); $this->storage->store($this->packages); } } diff --git a/src/Config/Storage.php b/src/Config/Storage.php new file mode 100644 index 0000000..34b97cf --- /dev/null +++ b/src/Config/Storage.php @@ -0,0 +1,10 @@ +file = $file; } - public function store($packages) + public function readPaths() + { + return array_values($this->load()); + } + + public function writePaths($paths) + { + $this->store($paths); + } + + protected function store($packages) { $this->writeToFile(['packages' => $packages]); } - public function load() + protected function load() { if (!file_exists($this->file)) return []; From 562a4a704794abfc9d69cc863b66df7f440adb7b Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 5 Apr 2016 22:14:32 +0900 Subject: [PATCH 05/18] Remove old interface --- src/Config/StorageInterface.php | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/Config/StorageInterface.php diff --git a/src/Config/StorageInterface.php b/src/Config/StorageInterface.php deleted file mode 100644 index 1133744..0000000 --- a/src/Config/StorageInterface.php +++ /dev/null @@ -1,10 +0,0 @@ - Date: Tue, 5 Apr 2016 22:33:54 +0900 Subject: [PATCH 06/18] Storage -> Serializer, move file writing and reading to config class Refs #54. --- src/Config/Config.php | 48 +++++++++++++++++++++++----- src/Config/Serializer.php | 10 ++++++ src/Config/Storage.php | 10 ------ src/Config/Version1Serializer.php | 16 ++++++++++ src/Config/Version1Storage.php | 53 ------------------------------- 5 files changed, 66 insertions(+), 71 deletions(-) create mode 100644 src/Config/Serializer.php delete mode 100644 src/Config/Storage.php create mode 100644 src/Config/Version1Serializer.php delete mode 100644 src/Config/Version1Storage.php diff --git a/src/Config/Config.php b/src/Config/Config.php index 550ad9b..23c69fa 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -7,18 +7,21 @@ class Config { /** - * @var Storage + * @var Serializer */ - protected $storage; + protected $serializer; protected $paths; protected $loaded = false; + protected $file; - public function __construct(Storage $storage) + + public function __construct($file, Serializer $serializer) { - $this->storage = $storage; + $this->file = $file; + $this->serializer = $serializer; } public static function make($file = null) @@ -28,14 +31,23 @@ public static function make($file = null) } return new static( - new Version1Storage($file) + $file, + new Version1Serializer() ); } + protected function readPaths() + { + if (!file_exists($this->file)) return []; + + $data = $this->readFromFile(); + return $this->serializer->deserializePaths($data); + } + public function getPaths() { if (! $this->loaded) { - $this->paths = $this->storage->readPaths(); + $this->paths = $this->readPaths(); $this->loaded = true; } @@ -48,7 +60,9 @@ public function addPackage(Package $package) $this->getPaths(); $this->paths[] = $package->getPath(); - $this->storage->writePaths($this->paths); + $this->writeToFile( + $this->serializer->serializePaths($this->paths) + ); } public function hasPackages() @@ -68,7 +82,25 @@ public function removePackage(Package $package) if (($key = array_search($path, $this->paths)) !== false) { unset($this->paths[$key]); - $this->storage->store($this->packages); + $this->writeToFile( + $this->serializer->serializePaths($this->paths) + ); } } + + protected function writeToFile(array $data) + { + file_put_contents( + $this->file, + json_encode( + $data, + JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE + )."\n" + ); + } + + protected function readFromFile() + { + return json_decode(file_get_contents($this->file), true); + } } \ No newline at end of file diff --git a/src/Config/Serializer.php b/src/Config/Serializer.php new file mode 100644 index 0000000..0ccd297 --- /dev/null +++ b/src/Config/Serializer.php @@ -0,0 +1,10 @@ + $paths]; + } +} diff --git a/src/Config/Version1Storage.php b/src/Config/Version1Storage.php deleted file mode 100644 index 940be86..0000000 --- a/src/Config/Version1Storage.php +++ /dev/null @@ -1,53 +0,0 @@ -file = $file; - } - - public function readPaths() - { - return array_values($this->load()); - } - - public function writePaths($paths) - { - $this->store($paths); - } - - protected function store($packages) - { - $this->writeToFile(['packages' => $packages]); - } - - protected function load() - { - if (!file_exists($this->file)) return []; - - $contents = $this->readFromFile(); - return $contents['packages']; - } - - protected function writeToFile(array $data) - { - file_put_contents( - $this->file, - json_encode( - $data, - JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE - )."\n" - ); - } - - protected function readFromFile() - { - return json_decode(file_get_contents($this->file), true); - } -} From e89657fc1483ce338864eac641dabbdb5f9d269e Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 21:20:46 +0900 Subject: [PATCH 07/18] Implement a VersionedSerializer class to support reading/writing different config versions In preparation for #54. --- src/Config/VersionedSerializer.php | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/Config/VersionedSerializer.php diff --git a/src/Config/VersionedSerializer.php b/src/Config/VersionedSerializer.php new file mode 100644 index 0000000..953e836 --- /dev/null +++ b/src/Config/VersionedSerializer.php @@ -0,0 +1,59 @@ + $serializer], $version); + } + + public function __construct(array $serializers, $defaultVersion) + { + $this->serializers = $serializers; + $this->defaultVersion = $defaultVersion; + } + + public function version($version, Serializer $serializer) + { + $this->serializers[$version] = $serializer; + + return $this; + } + + public function deserializePaths($obj) + { + if (!isset($obj['version'])) { + $serializer = $this->serializers[$this->default]; + } else if (array_key_exists(intval($obj['version']), $this->serializers)) { + $serializer = $this->serializers[$obj['version']]; + } else { + throw new \InvalidArgumentException('Invalid version'); + } + + return $serializer->deserializePaths($obj); + } + + public function serializePaths($paths) + { + $lastSerializer = $this->serializers[max(array_keys($this->serializers))]; + + return $lastSerializer->serializePaths($paths); + } +} From 0540c43a97382773c696b8da49c52bb91fd03693 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 21:28:07 +0900 Subject: [PATCH 08/18] Write the version field in the VersionedSerializer --- src/Config/VersionedSerializer.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Config/VersionedSerializer.php b/src/Config/VersionedSerializer.php index 953e836..99c6d97 100644 --- a/src/Config/VersionedSerializer.php +++ b/src/Config/VersionedSerializer.php @@ -52,8 +52,9 @@ public function deserializePaths($obj) public function serializePaths($paths) { - $lastSerializer = $this->serializers[max(array_keys($this->serializers))]; + $lastVersion = max(array_keys($this->serializers)); + $serializer = $this->serializers[$lastVersion]; - return $lastSerializer->serializePaths($paths); + return ['version' => $lastVersion] + $serializer->serializePaths($paths); } } From 13ee7604ae5428dd8e8829f4718a2ad051b0a4a4 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 21:30:33 +0900 Subject: [PATCH 09/18] Fix variable name --- src/Config/VersionedSerializer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/VersionedSerializer.php b/src/Config/VersionedSerializer.php index 99c6d97..9a4311d 100644 --- a/src/Config/VersionedSerializer.php +++ b/src/Config/VersionedSerializer.php @@ -40,7 +40,7 @@ public function version($version, Serializer $serializer) public function deserializePaths($obj) { if (!isset($obj['version'])) { - $serializer = $this->serializers[$this->default]; + $serializer = $this->serializers[$this->defaultVersion]; } else if (array_key_exists(intval($obj['version']), $this->serializers)) { $serializer = $this->serializers[$obj['version']]; } else { From 7cca50bf81b935e6e1e21d834dcba2c9734cd482 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 21:33:44 +0900 Subject: [PATCH 10/18] Use new VersionedSerializer in Config --- src/Config/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index 23c69fa..73f9a7a 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -32,7 +32,7 @@ public static function make($file = null) return new static( $file, - new Version1Serializer() + VersionedSerializer::withDefault(1, new Version1Serializer) ); } From 880d2c7088b4489d7eceedca4603726236d28ca1 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 21:37:28 +0900 Subject: [PATCH 11/18] Use typehint in interface signature --- src/Config/Serializer.php | 2 +- src/Config/Version1Serializer.php | 2 +- src/Config/VersionedSerializer.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Config/Serializer.php b/src/Config/Serializer.php index 0ccd297..e178610 100644 --- a/src/Config/Serializer.php +++ b/src/Config/Serializer.php @@ -6,5 +6,5 @@ interface Serializer { public function deserializePaths($obj); - public function serializePaths($paths); + public function serializePaths(array $paths); } diff --git a/src/Config/Version1Serializer.php b/src/Config/Version1Serializer.php index 0e5f6e2..66f3d5b 100644 --- a/src/Config/Version1Serializer.php +++ b/src/Config/Version1Serializer.php @@ -9,7 +9,7 @@ public function deserializePaths($obj) return array_values($obj['packages']); } - public function serializePaths($paths) + public function serializePaths(array $paths) { return ['packages' => $paths]; } diff --git a/src/Config/VersionedSerializer.php b/src/Config/VersionedSerializer.php index 9a4311d..62f64b8 100644 --- a/src/Config/VersionedSerializer.php +++ b/src/Config/VersionedSerializer.php @@ -50,7 +50,7 @@ public function deserializePaths($obj) return $serializer->deserializePaths($obj); } - public function serializePaths($paths) + public function serializePaths(array $paths) { $lastVersion = max(array_keys($this->serializers)); $serializer = $this->serializers[$lastVersion]; From 549578a7f28d2cf2379705dc6649964f528b9ec9 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 22:01:09 +0900 Subject: [PATCH 12/18] Backwards-compatible implementation of the Version1Serializer --- src/Config/Version1Serializer.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Config/Version1Serializer.php b/src/Config/Version1Serializer.php index 66f3d5b..662f3e5 100644 --- a/src/Config/Version1Serializer.php +++ b/src/Config/Version1Serializer.php @@ -2,6 +2,8 @@ namespace Studio\Config; +use Studio\Package; + class Version1Serializer implements Serializer { public function deserializePaths($obj) @@ -11,6 +13,32 @@ public function deserializePaths($obj) public function serializePaths(array $paths) { - return ['packages' => $paths]; + $globbedPaths = array_map(function ($path) { + return glob($path, GLOB_MARK | GLOB_ONLYDIR); + }, $paths); + + $allPaths = array_reduce($globbedPaths, function ($collect, $pathOrPaths) { + if (is_array($pathOrPaths)) { + return array_merge($collect, $pathOrPaths); + } else { + $collect[] = $pathOrPaths; + return $collect; + } + }, []); + + $allPaths = array_filter($allPaths, function ($path) { + return is_dir($path) && file_exists("$path/composer.json"); + }); + + $packages = array_map(function ($path) { + return Package::fromFolder(rtrim($path, '/')); + }, $allPaths); + + $packagePaths = array_reduce($packages, function ($collect, Package $package) { + $collect[$package->getComposerId()] = $package->getPath(); + return $collect; + }, []); + + return ['packages' => $packagePaths]; } } From e5b5ba778130e1065aa483579872aaf268750380 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 22:03:48 +0900 Subject: [PATCH 13/18] Do not pass Config object to CreateCommand --- bin/studio | 2 +- src/Console/CreateCommand.php | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/bin/studio b/bin/studio index e234dc7..a0c5fbd 100755 --- a/bin/studio +++ b/bin/studio @@ -23,7 +23,7 @@ use Symfony\Component\Console\Application; $config = Config::make(); $application = new Application('studio', '0.10.0'); -$application->add(new CreateCommand($config)); +$application->add(new CreateCommand); $application->add(new LoadCommand($config)); $application->add(new ScrapCommand($config)); $application->run(); diff --git a/src/Console/CreateCommand.php b/src/Console/CreateCommand.php index 0c36e0e..88cbbaa 100644 --- a/src/Console/CreateCommand.php +++ b/src/Console/CreateCommand.php @@ -17,8 +17,6 @@ class CreateCommand extends BaseCommand { - protected $config; - protected $partClasses = [ 'Studio\Parts\Base\Part', 'Studio\Parts\Composer\Part', @@ -33,13 +31,6 @@ class CreateCommand extends BaseCommand protected $partInput; - public function __construct(Config $config) - { - parent::__construct(); - - $this->config = $config; - } - protected function configure() { $this From a450b89f04af20c6d3849f72503a3426a1029362 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 22:08:59 +0900 Subject: [PATCH 14/18] Document the VersionedSerializer class --- src/Config/VersionedSerializer.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Config/VersionedSerializer.php b/src/Config/VersionedSerializer.php index 62f64b8..90c5991 100644 --- a/src/Config/VersionedSerializer.php +++ b/src/Config/VersionedSerializer.php @@ -2,6 +2,20 @@ namespace Studio\Config; +/** + * A decorator for serializing from/to multiple versions + * + * We support several versions of the Studio config file. + * + * This serializer class uses the serializer according to + * the "version" field or the default one if no "version" + * is provided for reading. + * + * For writing, the serializer with the highest version + * number is used. + * + * @package Studio\Config + */ class VersionedSerializer implements Serializer { /** From a4563f09fee4a16ad33d12817a43ea31ad1ee738 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 22:17:56 +0900 Subject: [PATCH 15/18] Implement a config serializer for the new version, storing only paths to be loaded Closes #54. --- src/Config/Version2Serializer.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/Config/Version2Serializer.php diff --git a/src/Config/Version2Serializer.php b/src/Config/Version2Serializer.php new file mode 100644 index 0000000..9345b4b --- /dev/null +++ b/src/Config/Version2Serializer.php @@ -0,0 +1,16 @@ + array_values($paths)]; + } +} From c51e914ae07fc08e0705b0a48b3f5eb1a52ec963 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 22:18:19 +0900 Subject: [PATCH 16/18] Config: Support both the old and the new studio.json format Refs #54. --- src/Config/Config.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index 73f9a7a..d549dc7 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -32,7 +32,9 @@ public static function make($file = null) return new static( $file, - VersionedSerializer::withDefault(1, new Version1Serializer) + VersionedSerializer + ::withDefault(1, new Version1Serializer) + ->version(2, new Version2Serializer) ); } From ed749c671e0394c43eacdb12b27772d0e71b3833 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 22:22:30 +0900 Subject: [PATCH 17/18] load command: Load paths, not packages --- src/Config/Config.php | 6 +++--- src/Console/LoadCommand.php | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index d549dc7..53a5513 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -56,12 +56,12 @@ public function getPaths() return $this->paths; } - public function addPackage(Package $package) + public function addPath($path) { - // Ensure our packages are loaded + // ensure paths are loaded $this->getPaths(); - $this->paths[] = $package->getPath(); + $this->paths[] = $path; $this->writeToFile( $this->serializer->serializePaths($this->paths) ); diff --git a/src/Console/LoadCommand.php b/src/Console/LoadCommand.php index a5eebcb..cba2d74 100644 --- a/src/Console/LoadCommand.php +++ b/src/Console/LoadCommand.php @@ -2,7 +2,6 @@ namespace Studio\Console; -use Studio\Package; use Studio\Config\Config; use Symfony\Component\Console\Input\InputArgument; @@ -23,7 +22,7 @@ protected function configure() { $this ->setName('load') - ->setDescription('Load a package to be managed with Studio') + ->setDescription('Load a path to be managed with Studio') ->addArgument( 'path', InputArgument::REQUIRED, @@ -33,10 +32,11 @@ protected function configure() protected function fire() { - $package = Package::fromFolder($this->input->getArgument('path')); - $this->config->addPackage($package); + $this->config->addPath( + $path = $this->input->getArgument('path') + ); - $this->io->success('Package loaded successfully.'); + $this->io->success("Packages matching the path $path will now be loaded by Composer."); } } From 9b173ffa17ffecfa80a3d857d45821cbb3494a27 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 6 Apr 2016 22:24:32 +0900 Subject: [PATCH 18/18] Extract dumping of config into separate method --- src/Config/Config.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index 53a5513..2519762 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -58,18 +58,16 @@ public function getPaths() public function addPath($path) { - // ensure paths are loaded + // Ensure paths are loaded $this->getPaths(); $this->paths[] = $path; - $this->writeToFile( - $this->serializer->serializePaths($this->paths) - ); + $this->dump(); } public function hasPackages() { - // Ensure our packages are loaded + // Ensure paths are loaded $this->getPaths(); return ! empty($this->paths); @@ -77,19 +75,24 @@ public function hasPackages() public function removePackage(Package $package) { - // Ensure our packages are loaded + // Ensure paths are loaded $this->getPaths(); $path = $package->getPath(); if (($key = array_search($path, $this->paths)) !== false) { unset($this->paths[$key]); - $this->writeToFile( - $this->serializer->serializePaths($this->paths) - ); + $this->dump(); } } + protected function dump() + { + $this->writeToFile( + $this->serializer->serializePaths($this->paths) + ); + } + protected function writeToFile(array $data) { file_put_contents(