2021-10-12 21:20:05 +00:00

106 lines
2.8 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 min. php version requirement
if (PHP_VERSION_ID < 70300) {
fwrite(
STDERR,
'Upgrade to php 7.3' . PHP_EOL .
'Deployer supports only php 7.3 and above.' . PHP_EOL .
'If you want to use older php versions you should use older Deployer versions' . 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;
foreach ($argv as $i => $arg) {
if (preg_match('/^(-f|--file)$/', $arg, $match) && $i + 1 < count($argv)) {
$deployFile = $argv[$i + 1];
}
if (preg_match('/^(-f|--file)=(?<file>.+?)$/', $arg, $match)) {
$deployFile = $match['file'];
}
if (!empty($deployFile)) {
$deployFile = ($deployFile[0] === '/' ? '' : getcwd() . '/') . $deployFile;
}
}
$lookUp = function (string $name): ?string
{
$dir = getcwd();
for ($i = 0; $i < 10; $i++) {
$path = "$dir/$name";
if (is_readable($path)) {
return $path;
}
$dir = dirname($dir);
}
return null;
};
if (empty($deployFile)) {
$deployFile = $lookUp('deploy.php');
}
if (empty($deployFile)) {
$deployFile = $lookUp('deploy.yaml');
}
// 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_DEPLOY_FILE', $deployFile);
define('DEPLOYER_ROOT', getenv('DEPLOYER_ROOT') !== false ? getenv('DEPLOYER_ROOT') : dirname($deployFile));
\Deployer\Deployer::run(DEPLOYER_VERSION, $deployFile);