Added GPM docs

This commit is contained in:
Djamil Legato
2014-09-11 12:40:29 -07:00
parent b26d938147
commit 88c9436df9

View File

@@ -3,48 +3,119 @@ namespace Grav\Common\GPM;
use Grav\Common\Iterator;
class GPM extends Iterator {
private $installed, $repository;
class GPM extends Iterator
{
/**
* Local installed Packages
* @var Packages
*/
private $installed;
/**
* Remote available Packages
* @var Packages
*/
private $repository;
/**
* Internal cache
* @var Iterator
*/
protected $cache;
public function __construct($refresh = false, $callback = null) {
/**
* Creates a new GPM instance with Local and Remote packages available
* @param boolean $refresh Applies to Remote Packages only and forces a refetch of data
* @param callable $callback Either a function or callback in array notation
*/
public function __construct($refresh = false, $callback = null)
{
$this->installed = new Local\Packages();
$this->repository = new Remote\Packages($refresh, $callback);
}
public function getInstalled() {
/**
* Returns the Locally installed packages
* @return Iterator The installed packages
*/
public function getInstalled()
{
return $this->installed;
}
public function countInstalled() {
/**
* Returns the amount of locally installed packages
* @return integer Amount of installed packages
*/
public function countInstalled()
{
return count($this->getInstalled());
}
public function getInstalledPlugin($slug) {
/**
* Return the instance of a specific Plugin
* @param string $slug The slug of the Plugin
* @return Package The instance of the Plugin
*/
public function getInstalledPlugin($slug)
{
return $this->installed['plugins'][$slug];
}
public function getInstalledPlugins() {
/**
* Returns the Locally installed plugins
* @return Iterator The installed plugins
*/
public function getInstalledPlugins()
{
return $this->installed['plugins'];
}
public function isPluginInstalled($slug) {
/**
* Checks if a Plugin is installed
* @param string $slug The slug of the Plugin
* @return boolean True if the Plugin has been installed. False otherwise
*/
public function isPluginInstalled($slug)
{
return isset($this->installed['plugins'][$slug]);
}
public function getInstalledTheme($slug) {
/**
* Return the instance of a specific Theme
* @param string $slug The slug of the Theme
* @return Package The instance of the Theme
*/
public function getInstalledTheme($slug)
{
return $this->installed['themes'][$slug];
}
public function getInstalledThemes() {
/**
* Returns the Locally installed themes
* @return Iterator The installed themes
*/
public function getInstalledThemes()
{
return $this->installed['themes'];
}
public function isThemeInstalled($slug) {
/**
* Checks if a Theme is installed
* @param string $slug The slug of the Theme
* @return boolean True if the Theme has been installed. False otherwise
*/
public function isThemeInstalled($slug)
{
return isset($this->installed['themes'][$slug]);
}
public function countUpdates() {
/**
* Returns the amount of updates available
* @return integer Amount of available updates
*/
public function countUpdates()
{
$count = 0;
$count += count($this->getUpdatablePlugins());
@@ -53,12 +124,19 @@ class GPM extends Iterator {
return $count;
}
public function getUpdatable() {
/**
* Returns an array of Plugins and Themes that can be updated.
* Plugins and Themes are extended with the `available` property that relies to the remote version
* @return array Array of updatable Plugins and Themes.
* Format: ['total' => int, 'plugins' => array, 'themes' => array]
*/
public function getUpdatable()
{
$plugins = $this->getUpdatablePlugins();
$themes = $this->getUpdatableThemes();
$items = [
'total' => count($plugins) + count($themes),
'total' => count($plugins)+count($themes),
'plugins' => $plugins,
'themes' => $themes
];
@@ -66,7 +144,13 @@ class GPM extends Iterator {
return $items;
}
public function getUpdatablePlugins() {
/**
* Returns an array of Plugins that can be updated.
* The Plugins are extended with the `available` property that relies to the remote version
* @return Iterator Array of updatable Plugins
*/
public function getUpdatablePlugins()
{
$items = [];
$repository = $this->repository['plugins'];
@@ -91,14 +175,27 @@ class GPM extends Iterator {
}
$this->cache[__METHOD__] = $items;
return $items;
}
public function isPluginUpdatable($plugin) {
/**
* Checks if a Plugin is Updatable
* @param string $plugin The slug of the Plugin
* @return boolean True if the Plugin is updatable. False otherwise
*/
public function isPluginUpdatable($plugin)
{
return array_key_exists($plugin, $this->getUpdatablePlugins());
}
public function getUpdatableThemes() {
/**
* Returns an array of Themes that can be updated.
* The Themes are extended with the `available` property that relies to the remote version
* @return Iterator Array of updatable Themes
*/
public function getUpdatableThemes()
{
$items = [];
$repository = $this->repository['themes'];
@@ -123,34 +220,75 @@ class GPM extends Iterator {
}
$this->cache[__METHOD__] = $items;
return $items;
}
public function isThemeUpdatable($theme) {
/**
* Checks if a Theme is Updatable
* @param string $theme The slug of the Theme
* @return boolean True if the Theme is updatable. False otherwise
*/
public function isThemeUpdatable($theme)
{
return array_key_exists($theme, $this->getUpdatableThemes());
}
public function getRepositoryPlugin($slug) {
/**
* Returns a Plugin from the repository
* @param string $slug The slug of the Plugin
* @return mixed Package if found, NULL if not
*/
public function getRepositoryPlugin($slug)
{
return @$this->repository['plugins'][$slug];
}
public function getRepositoryPlugins() {
/**
* Returns the list of Plugins available in the repository
* @return Iterator The Plugins remotely available
*/
public function getRepositoryPlugins()
{
return $this->repository['plugins'];
}
public function getRepositoryTheme($slug) {
/**
* Returns a Theme from the repository
* @param string $slug The slug of the Theme
* @return mixed Package if found, NULL if not
*/
public function getRepositoryTheme($slug)
{
return @$this->repository['themes'][$slug];
}
public function getRepositoryThemes() {
/**
* Returns the list of Themes available in the repository
* @return Iterator The Themes remotely available
*/
public function getRepositoryThemes()
{
return $this->repository['themes'];
}
public function getRepository() {
/**
* Returns the list of Plugins and Themes available in the repository
* @return array Array of available Plugins and Themes
* Format: ['plugins' => array, 'themes' => array]
*/
public function getRepository()
{
return $this->repository;
}
public function findPackage($search) {
/**
* Searches for a Package in the repository
* @param string $search Can be either the slug or the name
* @return Package Package if found, FALSE if not
*/
public function findPackage($search)
{
$search = strtolower($search);
if ($found = $this->getRepositoryTheme($search)) {
return $found;
@@ -175,7 +313,19 @@ class GPM extends Iterator {
return false;
}
public function findPackages($searches = []) {
/**
* Returns the list of Plugins and Themes available in the repository
* @return array Array of available Plugins and Themes
* Format: ['plugins' => array, 'themes' => array]
*/
/**
* Searches for a list of Packages in the repository
* @param array $searches An array of either slugs or names
* @return array Array of found Packages
* Format: ['total' => int, 'not_found' => array, <found-slugs>]
*/
public function findPackages($searches = [])
{
$packages = ['total' => 0, 'not_found' => []];
foreach ($searches as $search) {