Created
April 23, 2016 06:15
-
-
Save gwagroves/62401bc9500e041acef37c49ba861445 to your computer and use it in GitHub Desktop.
Rocketeer PHP check strategy replacement
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
<?php | |
/** | |
* This is a drop-in replacement for the default PhpStrategy. | |
* | |
* Instead of checking for `mcrypt` as a required extension, it checks for PHP extensions required in composer.json | |
* (e.g. `ext-mcrypt`) | |
* | |
* - Save the file as `.rocketeer/strategies/PhpCheckStrategy.php` | |
* - Change your strategy setting from 'Php' to `PhpExtensionCheck` | |
* | |
* @link https://getcomposer.org/doc/02-libraries.md | |
* @link https://github.com/rocketeers/rocketeer/issues/602 | |
*/ | |
namespace Rocketeer\Strategies\Check; | |
use Illuminate\Container\Container; | |
use Rocketeer\Abstracts\Strategies\AbstractCheckStrategy; | |
use Rocketeer\Interfaces\Strategies\CheckStrategyInterface; | |
use Rocketeer\Strategies\Check\PhpStrategy; | |
class PhpExtensionCheckStrategy extends PhpStrategy implements CheckStrategyInterface | |
{ | |
/** | |
* Check for the required extensions. | |
* | |
* @return array | |
*/ | |
public function extensions() | |
{ | |
$extensions = [ | |
'database' => ['checkDatabaseDriver', $this->app['config']->get('database.default')], | |
'cache' => ['checkCacheDriver', $this->app['config']->get('cache.driver')], | |
'session' => ['checkCacheDriver', $this->app['config']->get('session.driver')], | |
]; | |
foreach ($this->getRequiredExtensionsFromComposer() as $extension) { | |
$extensions[$extension] = ['checkPhpExtension', $extension]; | |
} | |
// Check PHP extensions | |
$errors = []; | |
foreach ($extensions as $check) { | |
list($method, $extension) = $check; | |
if (!$this->$method($extension)) { | |
$errors[] = $extension; | |
} | |
} | |
return $errors; | |
} | |
/** | |
* @return array | |
*/ | |
private function getRequiredExtensionsFromComposer() | |
{ | |
$extensions = []; | |
if (!$manifest = $this->manager->getManifestContents()) { | |
return $extensions; | |
} | |
$data = json_decode($manifest, true); | |
if (!array_key_exists('require', $data)) { | |
return $extensions; | |
} | |
foreach ($data['require'] as $package => $version) { | |
if ('ext-' === substr($package, 0, 4)) { | |
$extensions[] = substr($package, 4); | |
} | |
} | |
return $extensions; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment