-
Notifications
You must be signed in to change notification settings - Fork 19
Cache combined puli.json files of all installed packages #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the puli/manager package. | ||
* | ||
* (c) Bernhard Schussek <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Puli\Manager\Api\Cache; | ||
|
||
use InvalidArgumentException; | ||
use Puli\Manager\Api\Module\InstallInfo; | ||
use Puli\Manager\Api\Module\ModuleFile; | ||
use Puli\Manager\Assert\Assert; | ||
|
||
/** | ||
* Stores combined Modules configuration. | ||
* | ||
* @since 1.0 | ||
* | ||
* @author Mateusz Sojda <[email protected]> | ||
*/ | ||
class CacheFile | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private $path; | ||
|
||
/** | ||
* @var ModuleFile[] | ||
*/ | ||
private $moduleFiles = array(); | ||
|
||
/** | ||
* @var InstallInfo[] | ||
*/ | ||
private $installInfos = array(); | ||
|
||
/** | ||
* Creates new CacheFile. | ||
* | ||
* @param string|null $path The path where the cache file is stored. | ||
*/ | ||
public function __construct($path = null) | ||
{ | ||
Assert::nullOrAbsoluteSystemPath($path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we allow the path to be null? For in-memory caching? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if you create a cache file that is not persisted anywhere. I think this is fine, we're doing the same in PackageFile. |
||
|
||
$this->path = $path; | ||
} | ||
|
||
/** | ||
* Returns the path to the cache file. | ||
* | ||
* @return string|null The path or `null` if this file is not stored on the | ||
* file system. | ||
*/ | ||
public function getPath() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
/** | ||
* Sets the module files. | ||
* | ||
* @param ModuleFile[] $moduleFiles The module files. | ||
*/ | ||
public function setModuleFiles(array $moduleFiles) | ||
{ | ||
$this->moduleFiles = array(); | ||
|
||
foreach ($moduleFiles as $moduleFile) { | ||
$this->addModuleFile($moduleFile); | ||
} | ||
} | ||
|
||
/** | ||
* Adds a module to the cache file. | ||
* | ||
* @param ModuleFile $moduleFile The added module file. | ||
*/ | ||
public function addModuleFile(ModuleFile $moduleFile) | ||
{ | ||
$this->moduleFiles[$moduleFile->getModuleName()] = $moduleFile; | ||
|
||
ksort($this->moduleFiles); | ||
} | ||
|
||
/** | ||
* Removes a module file from the cache file. | ||
* | ||
* @param string $moduleName The module name. | ||
*/ | ||
public function removeModuleFile($moduleName) | ||
{ | ||
unset($this->moduleFiles[$moduleName]); | ||
} | ||
|
||
/** | ||
* Removes all module files from the cache file. | ||
*/ | ||
public function clearModuleFiles() | ||
{ | ||
$this->moduleFiles = array(); | ||
} | ||
|
||
/** | ||
* Returns the module file with the given name. | ||
* | ||
* @param string $moduleName The module name. | ||
* | ||
* @return ModuleFile The module with the passed name. | ||
* | ||
* @throws InvalidArgumentException If the module was not found. | ||
*/ | ||
public function getModuleFile($moduleName) | ||
{ | ||
Assert::moduleName($moduleName); | ||
|
||
if (!isset($this->moduleFiles[$moduleName])) { | ||
throw new InvalidArgumentException(sprintf('Could not find a module named %s.', $moduleName)); | ||
} | ||
|
||
return $this->moduleFiles[$moduleName]; | ||
} | ||
|
||
/** | ||
* Returns the module files in the cache file. | ||
* | ||
* @return ModuleFile[] The module files in the cache file. | ||
*/ | ||
public function getModuleFiles() | ||
{ | ||
return $this->moduleFiles; | ||
} | ||
|
||
/** | ||
* Returns whether a module with the given name exists. | ||
* | ||
* @param string $moduleName The module name. | ||
* | ||
* @return bool Whether a module with this name exists. | ||
*/ | ||
public function hasModuleFile($moduleName) | ||
{ | ||
return isset($this->moduleFiles[$moduleName]); | ||
} | ||
|
||
/** | ||
* Returns whether a cache file contains any module files. | ||
* | ||
* @return bool Whether a cache file contains any module files. | ||
*/ | ||
public function hasModuleFiles() | ||
{ | ||
return count($this->moduleFiles) > 0; | ||
} | ||
|
||
/** | ||
* Adds install info to the cache file. | ||
* | ||
* @param InstallInfo $installInfo The module install info. | ||
*/ | ||
public function addInstallInfo(InstallInfo $installInfo) | ||
{ | ||
$this->installInfos[$installInfo->getModuleName()] = $installInfo; | ||
|
||
ksort($this->installInfos); | ||
} | ||
|
||
/** | ||
* Removes install info file from the cache file. | ||
* | ||
* @param string $moduleName The module name. | ||
*/ | ||
public function removeInstallInfo($moduleName) | ||
{ | ||
unset($this->installInfos[$moduleName]); | ||
} | ||
|
||
/** | ||
* Removes all module install info from the cache file. | ||
*/ | ||
public function clearInstallInfo() | ||
{ | ||
$this->installInfos = array(); | ||
} | ||
|
||
/** | ||
* Returns the install info with the given module name. | ||
* | ||
* @param string $moduleName The module name. | ||
* | ||
* @return InstallInfo The module install info with the passed name. | ||
* | ||
* @throws InvalidArgumentException If the install info was not found. | ||
*/ | ||
public function getInstallInfo($moduleName) | ||
{ | ||
Assert::moduleName($moduleName); | ||
|
||
if (!isset($this->installInfos[$moduleName])) { | ||
throw new InvalidArgumentException(sprintf('Could not find a module named %s.', $moduleName)); | ||
} | ||
|
||
return $this->installInfos[$moduleName]; | ||
} | ||
|
||
/** | ||
* Returns the install info for all Modules in the cache file. | ||
* | ||
* @return InstallInfo[] The install info for all Modules in the cache file. | ||
*/ | ||
public function getInstallInfos() | ||
{ | ||
return $this->installInfos; | ||
} | ||
|
||
/** | ||
* Returns whether install info for a module with the given name exists. | ||
* | ||
* @param string $moduleName The module name. | ||
* | ||
* @return bool Whether install info for a module with this name exists. | ||
*/ | ||
public function hasInstallInfo($moduleName) | ||
{ | ||
return isset($this->installInfos[$moduleName]); | ||
} | ||
|
||
/** | ||
* Returns whether a cache file contains any module install info. | ||
* | ||
* @return bool Whether a cache file contains any module install info. | ||
*/ | ||
public function hasInstallInfos() | ||
{ | ||
return count($this->installInfos) > 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the puli/manager package. | ||
* | ||
* (c) Bernhard Schussek <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Puli\Manager\Api\Cache; | ||
|
||
use Puli\Manager\Api\Context\ProjectContext; | ||
use Puli\Manager\Api\Module\ModuleProvider; | ||
|
||
/** | ||
* Manages cached packages information. | ||
* | ||
* @since 1.0 | ||
* | ||
* @author Mateusz Sojda <[email protected]> | ||
*/ | ||
interface CacheManager extends ModuleProvider | ||
{ | ||
/** | ||
* Returns the manager's context. | ||
* | ||
* @return ProjectContext The project context. | ||
*/ | ||
public function getContext(); | ||
|
||
/** | ||
* Reads and returns cache file. | ||
* | ||
* @return CacheFile The cache file. | ||
*/ | ||
public function getCacheFile(); | ||
|
||
/** | ||
* Refreshes the cache file if it contains outdated informations or cache file doesn't exist. | ||
*/ | ||
public function refreshCacheFile(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can add a small description about the class (and a author tag for you if you want :) ). In other classes as well.