Skip to content

Commit

Permalink
rewrite install and update process
Browse files Browse the repository at this point in the history
fixes #96: phive.xml will only be touched if the installed version or the version constraint changes
fixes #87: add --prefer-offline option to phive update (phive install will alway prefer offline for now)
  • Loading branch information
sebastianheuer committed Mar 18, 2017
1 parent bc09e41 commit c83269b
Show file tree
Hide file tree
Showing 26 changed files with 737 additions and 1,146 deletions.
157 changes: 81 additions & 76 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,28 @@ public function getInstallCommand() {
$this->getPhiveXmlConfig(),
$this->getTargetDirectoryLocator()
),
$this->getPharService(),
$this->getPhiveXmlConfig(),
$this->getEnvironment()
$this->getInstallService(),
$this->getEnvironment(),
$this->getRequestedPharResolverBuilder()->build($this->getLocalFirstResolvingStrategy())
);
}

/**
* @return UpdateCommand
*/
public function getUpdateCommand() {
$config = new UpdateCommandConfig(
$this->request->parse(new UpdateContext()),
$this->getPhiveXmlConfig(),
$this->getTargetDirectoryLocator()
);

$resolvingStrategy = $config->preferOffline() ? $this->getLocalFirstResolvingStrategy() : $this->getRemoteFirstResolvingStrategy();

return new UpdateCommand(
new UpdateCommandConfig(
$this->request->parse(new UpdateContext()),
$this->getPhiveXmlConfig(),
$this->getTargetDirectoryLocator()
),
$this->getPharService(),
$config,
$this->getInstallService(),
$this->getRequestedPharResolverBuilder()->build($resolvingStrategy),
$this->getPhiveXmlConfig()
);
}
Expand Down Expand Up @@ -170,10 +175,11 @@ public function getComposerCommand() {
$this->getEnvironment()->getWorkingDirectory()
),
$this->getComposerService(),
$this->getPharService(),
$this->getInstallService(),
$this->getPhiveXmlConfig(),
$this->getEnvironment(),
$this->getConsoleInput()
$this->getConsoleInput(),
$this->getRequestedPharResolverBuilder()->build($this->getLocalFirstResolvingStrategy())
);
}

Expand Down Expand Up @@ -217,7 +223,7 @@ private function getCommandLocator() {
/**
* @return Cli\Output
*/
private function getOutput() {
public function getOutput() {
return (new Cli\OutputLocator(new Cli\OutputFactory()))->getOutput($this->getEnvironment());
}

Expand All @@ -232,6 +238,18 @@ private function getPhiveVersion() {
return $this->version;
}

/**
* @return InstallService
*/
private function getInstallService() {
return new InstallService(
$this->getPhiveXmlConfig(),
$this->getPharInstaller(),
$this->getPharRegistry(),
$this->getPharService()
);
}

/**
* @return Git
*/
Expand All @@ -254,7 +272,7 @@ private function getEnvironment() {
/**
* @return RemoteSourcesListFileLoader
*/
private function getRemoteSourcesListFileLoader() {
public function getRemoteSourcesListFileLoader() {
return new RemoteSourcesListFileLoader(
$this->getConfig()->getSourcesListUrl(),
$this->getConfig()->getHomeDirectory()->file('repositories.xml'),
Expand All @@ -266,7 +284,7 @@ private function getRemoteSourcesListFileLoader() {
/**
* @return LocalSourcesListFileLoader
*/
private function getLocalSourcesListFileLoader() {
public function getLocalSourcesListFileLoader() {
return new LocalSourcesListFileLoader(
$this->getConfig()->getHomeDirectory()->file('local.xml')
);
Expand All @@ -275,7 +293,7 @@ private function getLocalSourcesListFileLoader() {
/**
* @return Config
*/
protected function getConfig() {
public function getConfig() {
return new Config(
$this->getEnvironment(),
$this->request->getOptions()
Expand All @@ -285,7 +303,7 @@ protected function getConfig() {
/**
* @return FileDownloader
*/
private function getFileDownloader() {
public function getFileDownloader() {
return new FileDownloader(
$this->getCurl(),
$this->getFileStorageCacheBackend()
Expand Down Expand Up @@ -323,7 +341,7 @@ private function getHttpProgressRenderer() {
/**
* @return PharRegistry
*/
private function getPharRegistry() {
public function getPharRegistry() {
return new PharRegistry(
new XmlFile(
$this->getConfig()->getHomeDirectory()->file('/phars.xml'),
Expand All @@ -339,11 +357,8 @@ private function getPharRegistry() {
*/
private function getPharService() {
return new PharService(
$this->getPharDownloader(),
$this->getPharInstaller(),
$this->getPharRegistry(),
$this->getRequestedPharResolverService(),
$this->getOutput()
$this->getPharDownloader()
);
}

Expand Down Expand Up @@ -445,38 +460,7 @@ private function getPharInstaller() {
);
}

/**
* @param SourcesListFileLoader $sourcesListFileLoader
*
* @return PharIoAliasResolver
*/
private function getPharIoAliasResolver(SourcesListFileLoader $sourcesListFileLoader) {
return new PharIoAliasResolver(
$sourcesListFileLoader,
$this->getFileDownloader()
);
}

/**
* @return DirectUrlResolver
*/
private function getUrlResolver() {
return new DirectUrlResolver();
}

/**
* @return SourcesList
*/
private function getSourcesList() {
return $this->getRemoteSourcesListFileLoader()->load();
}

/**
* @return SourcesList
*/
private function getLocalSourcesList() {
return $this->getLocalSourcesListFileLoader()->load();
}

/**
* @return PhiveXmlConfig
Expand All @@ -502,35 +486,14 @@ private function getComposerService() {
/**
* @return RequestedPharResolverService
*/
private function getRequestedPharResolverService() {
$service = new RequestedPharResolverService();

$service->addResolver(
$this->getGithubAliasResolver()
);

// local
$service->addResolver(
$this->getPharIoAliasResolver($this->getLocalSourcesListFileLoader())
);

// phar.io
$service->addResolver(
$this->getPharIoAliasResolver($this->getRemoteSourcesListFileLoader())
);

// direct URLs
$service->addResolver(
$this->getUrlResolver()
);

return $service;
public function getRequestedPharResolverService() {
return new RequestedPharResolverService();
}

/**
* @return GithubAliasResolver
*/
private function getGithubAliasResolver() {
public function getGithubAliasResolver() {
return new GithubAliasResolver($this->getFileDownloader());
}

Expand All @@ -554,4 +517,46 @@ private function getFileLinkerLocator() {
private function getFileStorageCacheBackend() {
return new FileStorageCacheBackend($this->getConfig()->getHomeDirectory()->child('http-cache'));
}

/**
* @return RequestedPharResolverServiceBuilder
*/
private function getRequestedPharResolverBuilder() {
return new RequestedPharResolverServiceBuilder($this);
}

/**
* @return SourcesList
*/
private function getSourcesList() {
return $this->getRemoteSourcesListFileLoader()->load();
}

/**
* @return SourcesList
*/
private function getLocalSourcesList() {
return $this->getLocalSourcesListFileLoader()->load();
}

/**
* @return LocalFirstResolvingStrategy
*/
private function getLocalFirstResolvingStrategy() {
return new LocalFirstResolvingStrategy($this->getRequestedPharResolverFactory());
}

/**
* @return RemoteFirstResolvingStrategy
*/
private function getRemoteFirstResolvingStrategy() {
return new RemoteFirstResolvingStrategy($this->getRequestedPharResolverFactory());
}

/**
* @return RequestedPharResolverFactory
*/
private function getRequestedPharResolverFactory() {
return new RequestedPharResolverFactory($this);
}
}
10 changes: 9 additions & 1 deletion src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function($class) {
if ($classes === null) {
$classes = array(
'phario\\phive\\abstractrequestedpharresolver' => '/services/resolver/AbstractRequestedPharResolver.php',
'phario\\phive\\abstractresolvingstrategy' => '/services/resolver/strategy/AbstractResolvingStrategy.php',
'phario\\phive\\batpharactivator' => '/shared/file/BatPharActivator.php',
'phario\\phive\\cachebackend' => '/shared/http/CacheBackend.php',
'phario\\phive\\checksumservice' => '/services/checksum/ChecksumService.php',
Expand Down Expand Up @@ -88,6 +89,7 @@ function($class) {
'phario\\phive\\installcommandconfigexception' => '/commands/install/InstallCommandConfigException.php',
'phario\\phive\\installcontext' => '/commands/install/InstallContext.php',
'phario\\phive\\installedphar' => '/shared/phar/InstalledPhar.php',
'phario\\phive\\installservice' => '/services/phar/InstallService.php',
'phario\\phive\\invalidhashexception' => '/shared/exceptions/InvalidHashException.php',
'phario\\phive\\ioexception' => '/shared/exceptions/IOException.php',
'phario\\phive\\jsondata' => '/shared/JsonData.php',
Expand All @@ -97,6 +99,9 @@ function($class) {
'phario\\phive\\keyimportresult' => '/services/key/KeyImportResult.php',
'phario\\phive\\keyservice' => '/services/key/KeyService.php',
'phario\\phive\\listcommand' => '/commands/list/ListCommand.php',
'phario\\phive\\localaliasresolver' => '/services/resolver/LocalAliasResolver.php',
'phario\\phive\\localfirstresolvingstrategy' => '/services/resolver/strategy/LocalFirstResolvingStrategy.php',
'phario\\phive\\localrepository' => '/shared/repository/LocalRepository.php',
'phario\\phive\\localsourceslistfileloader' => '/shared/sources/LocalSourcesListFileLoader.php',
'phario\\phive\\localsslcertificate' => '/shared/http/LocalSslCertificate.php',
'phario\\phive\\nogpgbinaryfoundexception' => '/shared/exceptions/NoGPGBinaryFoundException.php',
Expand All @@ -118,24 +123,27 @@ function($class) {
'phario\\phive\\phivecontext' => '/PhiveContext.php',
'phario\\phive\\phiveversion' => '/shared/version/PhiveVersion.php',
'phario\\phive\\phivexmlconfig' => '/shared/config/PhiveXmlConfig.php',
'phario\\phive\\pipeio' => '/shared/PipeIO.php',
'phario\\phive\\publickey' => '/services/key/PublicKey.php',
'phario\\phive\\purgecommand' => '/commands/purge/PurgeCommand.php',
'phario\\phive\\purgecontext' => '/commands/purge/PurgeContext.php',
'phario\\phive\\release' => '/shared/phar/Release.php',
'phario\\phive\\releasecollection' => '/shared/phar/ReleaseCollection.php',
'phario\\phive\\releaseexception' => '/shared/exceptions/ReleaseException.php',
'phario\\phive\\remotefirstresolvingstrategy' => '/services/resolver/strategy/RemoteFirstResolvingStrategy.php',
'phario\\phive\\remotesourceslistfileloader' => '/shared/sources/RemoteSourcesListFileLoader.php',
'phario\\phive\\removecommand' => '/commands/remove/RemoveCommand.php',
'phario\\phive\\removecommandconfig' => '/commands/remove/RemoveCommandConfig.php',
'phario\\phive\\removecontext' => '/commands/remove/RemoveContext.php',
'phario\\phive\\requestedphar' => '/shared/phar/RequestedPhar.php',
'phario\\phive\\requestedpharresolver' => '/services/resolver/RequestedPharResolver.php',
'phario\\phive\\requestedpharresolverfactory' => '/services/resolver/RequestedPharResolverFactory.php',
'phario\\phive\\requestedpharresolverservice' => '/services/resolver/RequestedPharResolverService.php',
'phario\\phive\\requestedpharresolverservicebuilder' => '/services/resolver/RequestedPharResolverServiceBuilder.php',
'phario\\phive\\resetcommand' => '/commands/reset/ResetCommand.php',
'phario\\phive\\resetcommandconfig' => '/commands/reset/ResetCommandConfig.php',
'phario\\phive\\resetcontext' => '/commands/reset/ResetContext.php',
'phario\\phive\\resolveexception' => '/shared/exceptions/ResolveException.php',
'phario\\phive\\resolvingstrategy' => '/services/resolver/strategy/ResolvingStrategy.php',
'phario\\phive\\selfupdatecommand' => '/commands/selfupdate/SelfupdateCommand.php',
'phario\\phive\\sha1hash' => '/shared/hash/sha/Sha1Hash.php',
'phario\\phive\\sha256hash' => '/shared/hash/sha/Sha256Hash.php',
Expand Down
20 changes: 11 additions & 9 deletions src/commands/composer/ComposerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ class ComposerCommand extends InstallCommand {

/**
* @param ComposerCommandConfig $config
* @param ComposerService $composerService
* @param PharService $pharService
* @param PhiveXmlConfig $phiveXmlConfig
* @param Environment $environment
* @param Cli\Input $input
* @param ComposerService $composerService
* @param InstallService $installService
* @param PhiveXmlConfig $phiveXmlConfig
* @param Environment $environment
* @param Cli\Input $input
* @param RequestedPharResolverService $pharResolver
*/
public function __construct(
ComposerCommandConfig $config,
ComposerService $composerService,
PharService $pharService,
InstallService $installService,
PhiveXmlConfig $phiveXmlConfig,
Environment $environment,
Cli\Input $input
Cli\Input $input,
RequestedPharResolverService $pharResolver
) {
parent::__construct($config, $pharService, $phiveXmlConfig, $environment);
parent::__construct($config, $installService, $environment, $pharResolver);
$this->composerService = $composerService;
$this->input = $input;
}
Expand All @@ -48,7 +50,7 @@ public function execute() {
}

/**
* @return InstallCommandConfig
* @return InstallCommandConfig|ComposerCommandConfig
*/
protected function getConfig() {
return parent::getConfig();
Expand Down
Loading

0 comments on commit c83269b

Please sign in to comment.