"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "system/src/Grav/Common/GPM/GPM.php" between
grav-v1.7.17.zip and grav-v1.7.18.zip

About: Grav is a fast, simple, and flexible flat-file based CMS platform (using YAML and PHP). Contents are just simple markdown files in folders with optional extensions via API and hooks.

GPM.php  (grav-v1.7.17):GPM.php  (grav-v1.7.18)
skipping to change at line 38 skipping to change at line 38
* Class GPM * Class GPM
* @package Grav\Common\GPM * @package Grav\Common\GPM
*/ */
class GPM extends Iterator class GPM extends Iterator
{ {
/** @var Local\Packages Local installed Packages */ /** @var Local\Packages Local installed Packages */
private $installed; private $installed;
/** @var Remote\Packages|null Remote available Packages */ /** @var Remote\Packages|null Remote available Packages */
private $repository; private $repository;
/** @var Remote\GravCore|null Remove Grav Packages */ /** @var Remote\GravCore|null Remove Grav Packages */
public $grav; private $grav;
/** @var bool */
private $refresh;
/** @var callable|null */
private $callback;
/** @var array Internal cache */ /** @var array Internal cache */
protected $cache; protected $cache;
/** @var array */ /** @var array */
protected $install_paths = [ protected $install_paths = [
'plugins' => 'user/plugins/%name%', 'plugins' => 'user/plugins/%name%',
'themes' => 'user/themes/%name%', 'themes' => 'user/themes/%name%',
'skeletons' => 'user/' 'skeletons' => 'user/'
]; ];
/** /**
* Creates a new GPM instance with Local and Remote packages available * Creates a new GPM instance with Local and Remote packages available
* *
* @param bool $refresh Applies to Remote Packages only and forces a refetch of data * @param bool $refresh Applies to Remote Packages only and forces a refetch of data
* @param callable|null $callback Either a function or callback in array not ation * @param callable|null $callback Either a function or callback in array not ation
*/ */
public function __construct($refresh = false, $callback = null) public function __construct($refresh = false, $callback = null)
{ {
parent::__construct(); parent::__construct();
Folder::create(GRAV_ROOT . '/cache/gpm');
$this->cache = []; $this->cache = [];
$this->installed = new Local\Packages(); $this->installed = new Local\Packages();
try { $this->refresh = $refresh;
$this->repository = new Remote\Packages($refresh, $callback); $this->callback = $callback;
$this->grav = new Remote\GravCore($refresh, $callback); }
} catch (Exception $e) {
/**
* Magic getter method
*
* @param string $offset Asset name value
* @return mixed Asset value
*/
public function __get($offset)
{
switch ($offset) {
case 'grav':
return $this->getGrav();
}
return parent::__get($offset);
}
/**
* Magic method to determine if the attribute is set
*
* @param string $offset Asset name value
* @return bool True if the value is set
*/
public function __isset($offset)
{
switch ($offset) {
case 'grav':
return $this->getGrav() !== null;
} }
return parent::__isset($offset);
} }
/** /**
* Return the locally installed packages * Return the locally installed packages
* *
* @return Local\Packages * @return Local\Packages
*/ */
public function getInstalled() public function getInstalled()
{ {
return $this->installed; return $this->installed;
skipping to change at line 268 skipping to change at line 304
/** /**
* Returns an array of Plugins that can be updated. * Returns an array of Plugins that can be updated.
* The Plugins are extended with the `available` property that relies to the remote version * The Plugins are extended with the `available` property that relies to the remote version
* *
* @return array Array of updatable Plugins * @return array Array of updatable Plugins
*/ */
public function getUpdatablePlugins() public function getUpdatablePlugins()
{ {
$items = []; $items = [];
if (null === $this->repository) { $repository = $this->getRepository();
if (null === $repository) {
return $items; return $items;
} }
$repository = $this->repository['plugins']; $plugins = $repository['plugins'];
// local cache to speed things up // local cache to speed things up
if (isset($this->cache[__METHOD__])) { if (isset($this->cache[__METHOD__])) {
return $this->cache[__METHOD__]; return $this->cache[__METHOD__];
} }
foreach ($this->installed['plugins'] as $slug => $plugin) { foreach ($this->installed['plugins'] as $slug => $plugin) {
if (!isset($repository[$slug]) || $plugin->symlink || !$plugin->vers ion || $plugin->gpm === false) { if (!isset($plugins[$slug]) || $plugin->symlink || !$plugin->version || $plugin->gpm === false) {
continue; continue;
} }
$local_version = $plugin->version ?? 'Unknown'; $local_version = $plugin->version ?? 'Unknown';
$remote_version = $repository[$slug]->version; $remote_version = $plugins[$slug]->version;
if (version_compare($local_version, $remote_version) < 0) { if (version_compare($local_version, $remote_version) < 0) {
$repository[$slug]->available = $remote_version; $plugins[$slug]->available = $remote_version;
$repository[$slug]->version = $local_version; $plugins[$slug]->version = $local_version;
$repository[$slug]->type = $repository[$slug]->release_type; $plugins[$slug]->type = $plugins[$slug]->release_type;
$items[$slug] = $repository[$slug]; $items[$slug] = $plugins[$slug];
} }
} }
$this->cache[__METHOD__] = $items; $this->cache[__METHOD__] = $items;
return $items; return $items;
} }
/** /**
* Get the latest release of a package from the GPM * Get the latest release of a package from the GPM
* *
* @param string $package_name * @param string $package_name
* @return string|null * @return string|null
*/ */
public function getLatestVersionOfPackage($package_name) public function getLatestVersionOfPackage($package_name)
{ {
if (null === $this->repository) { $repository = $this->getRepository();
if (null === $repository) {
return null; return null;
} }
$repository = $this->repository['plugins']; $plugins = $repository['plugins'];
if (isset($repository[$package_name])) { if (isset($plugins[$package_name])) {
return $repository[$package_name]->available ?: $repository[$package return $plugins[$package_name]->available ?: $plugins[$package_name]
_name]->version; ->version;
} }
//Not a plugin, it's a theme? //Not a plugin, it's a theme?
$repository = $this->repository['themes']; $themes = $repository['themes'];
if (isset($repository[$package_name])) { if (isset($themes[$package_name])) {
return $repository[$package_name]->available ?: $repository[$package return $themes[$package_name]->available ?: $themes[$package_name]->
_name]->version; version;
} }
return null; return null;
} }
/** /**
* Check if a Plugin or Theme is updatable * Check if a Plugin or Theme is updatable
* *
* @param string $slug The slug of the package * @param string $slug The slug of the package
* @return bool True if updatable. False otherwise or if not found * @return bool True if updatable. False otherwise or if not found
skipping to change at line 358 skipping to change at line 396
/** /**
* Returns an array of Themes that can be updated. * Returns an array of Themes that can be updated.
* The Themes are extended with the `available` property that relies to the remote version * The Themes are extended with the `available` property that relies to the remote version
* *
* @return array Array of updatable Themes * @return array Array of updatable Themes
*/ */
public function getUpdatableThemes() public function getUpdatableThemes()
{ {
$items = []; $items = [];
if (null === $this->repository) { $repository = $this->getRepository();
if (null === $repository) {
return $items; return $items;
} }
$repository = $this->repository['themes']; $themes = $repository['themes'];
// local cache to speed things up // local cache to speed things up
if (isset($this->cache[__METHOD__])) { if (isset($this->cache[__METHOD__])) {
return $this->cache[__METHOD__]; return $this->cache[__METHOD__];
} }
foreach ($this->installed['themes'] as $slug => $plugin) { foreach ($this->installed['themes'] as $slug => $plugin) {
if (!isset($repository[$slug]) || $plugin->symlink || !$plugin->vers ion || $plugin->gpm === false) { if (!isset($themes[$slug]) || $plugin->symlink || !$plugin->version || $plugin->gpm === false) {
continue; continue;
} }
$local_version = $plugin->version ?? 'Unknown'; $local_version = $plugin->version ?? 'Unknown';
$remote_version = $repository[$slug]->version; $remote_version = $themes[$slug]->version;
if (version_compare($local_version, $remote_version) < 0) { if (version_compare($local_version, $remote_version) < 0) {
$repository[$slug]->available = $remote_version; $themes[$slug]->available = $remote_version;
$repository[$slug]->version = $local_version; $themes[$slug]->version = $local_version;
$repository[$slug]->type = $repository[$slug]->release_type; $themes[$slug]->type = $themes[$slug]->release_type;
$items[$slug] = $repository[$slug]; $items[$slug] = $themes[$slug];
} }
} }
$this->cache[__METHOD__] = $items; $this->cache[__METHOD__] = $items;
return $items; return $items;
} }
/** /**
* Checks if a Theme is Updatable * Checks if a Theme is Updatable
skipping to change at line 409 skipping to change at line 448
} }
/** /**
* Get the release type of a package (stable / testing) * Get the release type of a package (stable / testing)
* *
* @param string $package_name * @param string $package_name
* @return string|null * @return string|null
*/ */
public function getReleaseType($package_name) public function getReleaseType($package_name)
{ {
if (null === $this->repository) { $repository = $this->getRepository();
if (null === $repository) {
return null; return null;
} }
$repository = $this->repository['plugins']; $plugins = $repository['plugins'];
if (isset($repository[$package_name])) { if (isset($plugins[$package_name])) {
return $repository[$package_name]->release_type; return $plugins[$package_name]->release_type;
} }
//Not a plugin, it's a theme? //Not a plugin, it's a theme?
$repository = $this->repository['themes']; $themes = $repository['themes'];
if (isset($repository[$package_name])) { if (isset($themes[$package_name])) {
return $repository[$package_name]->release_type; return $themes[$package_name]->release_type;
} }
return null; return null;
} }
/** /**
* Returns true if the package latest release is stable * Returns true if the package latest release is stable
* *
* @param string $package_name * @param string $package_name
* @return bool * @return bool
skipping to change at line 472 skipping to change at line 512
return $packages ? ($packages[$slug] ?? null) : null; return $packages ? ($packages[$slug] ?? null) : null;
} }
/** /**
* Returns the list of Plugins available in the repository * Returns the list of Plugins available in the repository
* *
* @return Iterator|null The Plugins remotely available * @return Iterator|null The Plugins remotely available
*/ */
public function getRepositoryPlugins() public function getRepositoryPlugins()
{ {
return $this->repository['plugins'] ?? null; return $this->getRepository()['plugins'] ?? null;
} }
/** /**
* Returns a Theme from the repository * Returns a Theme from the repository
* *
* @param string $slug The slug of the Theme * @param string $slug The slug of the Theme
* @return Remote\Package|null Package if found, NULL if not * @return Remote\Package|null Package if found, NULL if not
*/ */
public function getRepositoryTheme($slug) public function getRepositoryTheme($slug)
{ {
skipping to change at line 495 skipping to change at line 535
return $packages ? ($packages[$slug] ?? null) : null; return $packages ? ($packages[$slug] ?? null) : null;
} }
/** /**
* Returns the list of Themes available in the repository * Returns the list of Themes available in the repository
* *
* @return Iterator|null The Themes remotely available * @return Iterator|null The Themes remotely available
*/ */
public function getRepositoryThemes() public function getRepositoryThemes()
{ {
return $this->repository['themes'] ?? null; return $this->getRepository()['themes'] ?? null;
} }
/** /**
* Returns the list of Plugins and Themes available in the repository * Returns the list of Plugins and Themes available in the repository
* *
* @return Remote\Packages|null Available Plugins and Themes * @return Remote\Packages|null Available Plugins and Themes
* Format: ['plugins' => array, 'themes' => array] * Format: ['plugins' => array, 'themes' => array]
*/ */
public function getRepository() public function getRepository()
{ {
if (null === $this->repository) {
try {
$this->repository = new Remote\Packages($this->refresh, $this->c
allback);
} catch (Exception $e) {}
}
return $this->repository; return $this->repository;
} }
/** /**
* Returns Grav version available in the repository
*
* @return Remote\GravCore|null
*/
public function getGrav()
{
if (null === $this->grav) {
try {
$this->grav = new Remote\GravCore($this->refresh, $this->callbac
k);
} catch (Exception $e) {}
}
return $this->grav;
}
/**
* Searches for a Package in the repository * Searches for a Package in the repository
* *
* @param string $search Can be either the slug or the name * @param string $search Can be either the slug or the name
* @param bool $ignore_exception True if should not fire an exception (for use in Twig) * @param bool $ignore_exception True if should not fire an exception (for use in Twig)
* @return Remote\Package|false Package if found, FALSE if not * @return Remote\Package|false Package if found, FALSE if not
*/ */
public function findPackage($search, $ignore_exception = false) public function findPackage($search, $ignore_exception = false)
{ {
$search = strtolower($search); $search = strtolower($search);
 End of changes. 24 change blocks. 
39 lines changed or deleted 103 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)