Skip to content

Commit

Permalink
Added support for php dependencies in GPM blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 17, 2018
1 parent 79e580a commit ccf0f9c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#new)
* Added `Grav\Framework\Uri` classes extending PSR-7 `HTTP message UriInterface` implementation
* Added ability to have `php` version dependencies in GPM assets

# v1.4.0-rc.2
## 02/15/2018
Expand Down
22 changes: 18 additions & 4 deletions system/src/Grav/Common/GPM/GPM.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ public function getPackagesThatDependOnPackage($slug)
foreach ($packages as $package_name => $package) {
if (isset($package['dependencies'])) {
foreach ($package['dependencies'] as $dependency) {
if (is_array($dependency)) {
$dependency = array_keys($dependency)[0];
if (is_array($dependency) && isset($dependency['name'])) {
$dependency = $dependency['name'];
}

if ($dependency == $slug) {
Expand Down Expand Up @@ -835,6 +835,20 @@ public function getDependencies($packages)
continue;
}

// Check PHP version
if ($dependency_slug == 'php') {
$current_php_version = phpversion();
if (version_compare($this->calculateVersionNumberFromDependencyVersion($dependencyVersionWithOperator),
$current_php_version) === 1
) {
//Needs a Grav update first
throw new \Exception("<red>One of the packages require PHP " . $dependencies['php'] . ". Please update PHP to resolve this");
} else {
unset($dependencies[$dependency_slug]);
continue;
}
}

//First, check for Grav dependency. If a dependency requires Grav > the current version, abort and tell.
if ($dependency_slug == 'grav') {
if (version_compare($this->calculateVersionNumberFromDependencyVersion($dependencyVersionWithOperator),
Expand Down Expand Up @@ -1062,9 +1076,9 @@ public function calculateVersionNumberFromDependencyVersion($version)
} elseif ($version == '') {
return null;
} elseif ($this->versionFormatIsNextSignificantRelease($version)) {
return substr($version, 1);
return trim(substr($version, 1));
} elseif ($this->versionFormatIsEqualOrHigher($version)) {
return substr($version, 2);
return trim(substr($version, 2));
} else {
return $version;
}
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Console/Gpm/UninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function uninstallPackage($slug, $package, $is_dependency = false)
if (is_array($dependency)) {
$dependency = $dependency['name'];
}
if ($dependency === 'grav') {
if ($dependency === 'grav' || $dependency === 'php') {
continue;
}

Expand Down

0 comments on commit ccf0f9c

Please sign in to comment.