Skip to content

Commit

Permalink
Add in warning to upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
midnite81 committed Apr 26, 2020
1 parent 9c5eea9 commit 5687b17
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"require": {
"php": ">=5.5.9",
"kylekatarnls/update-helper": "^1.1",
"laravel/framework": "^5.0|^6.0|^7.0",
"guzzlehttp/guzzle": "^6.2",
"mockery/mockery": "^1.0"
Expand All @@ -33,13 +34,19 @@
"Midnite81\\GeoLocation\\Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"UpdateHelper\\UpdateHelper::check"
]
},
"extra": {
"component": "package",
"frameworks": [
"Laravel 5",
"Laravel 6",
"Laravel 7"
]
],
"update-helper": "Midnite81\\GeoLocation\\Upgrade"
},
"minimum-stability": "stable"
}
68 changes: 68 additions & 0 deletions src/Upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Midnite81\GeoLocation;

use RuntimeException;
use UpdateHelper\UpdateHelper;
use UpdateHelper\UpdateHelperInterface;

class Upgrade implements UpdateHelperInterface
{
/**
* @var string
*/
protected $packageName = 'midnite81/geolocation';

/**
* @var UpdateHelper
*/
protected $helper;

public function check(UpdateHelper $helper)
{
$this->helper = $helper;
$dependencies = $helper->getProdDependencies();

if (array_key_exists($this->packageName, $dependencies)) {
$version = $dependencies[$this->packageName];
$helper->write($this->packageName . ' is installed as version '
. $version);
if ($this->version1($version)) {
$this->yellow('****');
$this->yellow("Please considering {$this->packageName} to version 2 or greater. Version 1 has been depreciated because of an issue with PSR-4 and composer v2");
$this->yellow('****');
}
}
}

private function version1($version)
{
return preg_match('/^[\^~>]?1\./', $version);
}

private function yellow($string)
{
$colour = $this->colour('yellow');
$reset = $this->colour('reset');

$this->helper->write($colour . $string . $reset);
}

private function colour($colour)
{
$colours = [
'reset' => "[0m",
'yellow' => "[33m"
];

if (!array_key_exists($colour, $colours)) {
throw new RuntimeException("Colour '$colour' not found");
}

if (PHP_OS == 'Darwin') {
return "\e" . $colours[$colour];
}

return "\u001b" . $colours[$colour];
}
}

0 comments on commit 5687b17

Please sign in to comment.