-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache combined puli.json files of all installed packages
- Loading branch information
Showing
21 changed files
with
1,874 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the puli/manager Module. | ||
* | ||
* (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); | ||
|
||
$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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.