#!/usr/bin/env php * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ // Deployer constants define('DEPLOYER', true); define('DEPLOYER_BIN', __FILE__); // Detect deploy.php script $options = getopt('f::', ['file::']); $userSpecifiedFile = null; if (isset($options['f'])) { $userSpecifiedFile = $options['f']; } elseif (isset($options['file'])) { $userSpecifiedFile = $options['file']; } if (empty($userSpecifiedFile)) { $deployFile = getcwd() . '/deploy.php'; if (!is_readable($deployFile)) { $currentDir = getcwd(); $count = 0; do { $currentDir = dirname($currentDir); $deployFile = $currentDir . '/deploy.php'; $count++; } while (!is_readable($deployFile) && $count < 100); } } else { $deployFile = ($userSpecifiedFile[0] === '/' ? '' : getcwd() . '/') . $userSpecifiedFile; } $deployFilePath = dirname($deployFile); // Detect source location $autoload = [ $deployFilePath . '/vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php' ]; $includes = [ $deployFilePath . '/vendor/deployer/deployer', __DIR__ . '/../../../deployer/deployer', __DIR__ . '/../' ]; $loaded = false; $includePath = false; for ($i = 0; $i < count($autoload); $i++) { if (file_exists($autoload[$i]) && file_exists($includes[$i])) { require $autoload[$i]; $includePath = $includes[$i]; $loaded = true; break; } } if (!$loaded) { die( 'You need to set up the project dependencies using the following commands:' . PHP_EOL . 'wget http://getcomposer.org/composer.phar' . PHP_EOL . 'php composer.phar install' . PHP_EOL ); } // Setup include path set_include_path($includePath . PATH_SEPARATOR . get_include_path()); // Detect version $version = 'master'; $composerLockFile = $deployFilePath . '/composer.lock'; if (is_readable($composerLockFile)) { $lock = json_decode(file_get_contents($composerLockFile), true); foreach ($lock['packages'] as $package) { if ($package['name'] === 'deployer/deployer') { $version = $package['version']; } } foreach ($lock['packages-dev'] as $package) { if ($package['name'] === 'deployer/deployer') { $version = $package['version']; } } } $method = new ReflectionMethod('Deployer\Deployer', 'run'); if (!$method->isStatic()) { die( 'You need to update Deployer to latest version:' . PHP_EOL . PHP_EOL . ' curl -LO https://deployer.org/deployer.phar' . PHP_EOL . ' mv deployer.phar /usr/local/bin/dep' . PHP_EOL . ' chmod +x /usr/local/bin/dep' . PHP_EOL . PHP_EOL . 'Or use composer installed version:' . PHP_EOL . PHP_EOL . ' php vendor/bin/dep' . PHP_EOL . PHP_EOL ); } \Deployer\Deployer::run($version, $deployFile);