Anton Medvedev 29a643b623 v7
2020-05-16 18:02:17 +03:00

97 lines
2.5 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* 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__);
define('DEPLOYER_VERSION', '7.0.0-master');
// Check for php7
if (!defined('PHP_MAJOR_VERSION') || PHP_MAJOR_VERSION < 7) {
fwrite(
STDERR,
'Upgrade to php7' . PHP_EOL .
'Deployer 5.x supports only php7 and above.' . PHP_EOL .
'If you want to use older php version use Deployer 4.x' . PHP_EOL
);
exit(1);
}
// Errors to exception
set_error_handler(function ($severity, $message, $filename, $lineno) {
if (error_reporting() == 0) {
return;
}
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $filename, $lineno);
}
});
// Detect deploy.php script
$deployFile = null;
if (preg_match('/(^|\s) --? (f|file) (=|\s) (?<file>.+?) (\s|$)/x', implode(' ', $argv), $match)) {
$deployFile = $match['file'];
}
if (empty($deployFile)) {
$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 = ($deployFile[0] === '/' ? '' : getcwd() . '/') . $deployFile;
}
// Detect autoload location
$autoload = [
dirname($deployFile) . '/vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../vendor/autoload.php'
];
$includes = [
dirname($deployFile) . '/vendor/deployer/deployer',
__DIR__ . '/../../../deployer/deployer',
__DIR__ . '/../'
];
$includePath = false;
for ($i = 0; $i < count($autoload); $i++) {
if (file_exists($autoload[$i]) && file_exists($includes[$i])) {
require $autoload[$i];
$includePath = $includes[$i];
goto run;
}
}
fwrite(
STDERR,
'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
);
exit(1);
run:
set_include_path($includePath . PATH_SEPARATOR . get_include_path());
define('DEPLOYER_ROOT', dirname($deployFile));
\Deployer\Deployer::run(DEPLOYER_VERSION, $deployFile);