2021-10-14 21:57:34 +02:00

107 lines
3.1 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.
*/
// Detect deploy.php location
$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');
}
// Find project-local Deployer installation
$binaries = [
dirname($deployFile) . '/vendor/bin/dep',
dirname($deployFile) . '/deployer.phar',
getcwd() . '/vendor/bin/dep',
getcwd() . '/deployer.phar',
];
foreach ($binaries as $binary) {
if (file_exists($binary)) {
if (realpath($binary) === __FILE__) {
break; // Already required this binary
}
require $binary;
exit;
}
}
// Detect autoload location
$autoload = [
__DIR__ . '/../vendor/autoload.php', // The dep located at "deployer.phar/bin" or in development.
__DIR__ . '/../../../autoload.php', // The dep located at "vendor/deployer/deployer/bin".
];
$includes = [
__DIR__ . '/..',
__DIR__ . '/../../../deployer/deployer',
];
$includePath = false;
for ($i = 0; $i < count($autoload); $i++) {
if (file_exists($autoload[$i]) && is_dir($includes[$i])) {
require $autoload[$i];
$includePath = $includes[$i];
break;
}
}
if (empty($includePath)) {
fwrite(STDERR, "Error: The `autoload.php` file not found in:\n");
for ($i = 0; $i < count($autoload); $i++) {
$a = file_exists($autoload[$i]) ? 'true' : 'false';
$b = is_dir($includes[$i]) ? 'true' : 'false';
fwrite(STDERR, " - file_exists($autoload[$i]) = $a\n");
fwrite(STDERR, " is_dir($includes[$i]) = $b\n");
}
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);
}
});
// Enable recipe loading
set_include_path($includePath . PATH_SEPARATOR . get_include_path());
// Deployer constants
define('DEPLOYER', true);
define('DEPLOYER_BIN', __FILE__);
define('DEPLOYER_VERSION', '7.0.0-master');
define('DEPLOYER_DEPLOY_FILE', $deployFile);
define('DEPLOYER_ROOT', getenv('DEPLOYER_ROOT') !== false ? getenv('DEPLOYER_ROOT') : dirname($deployFile));
Deployer\Deployer::run(DEPLOYER_VERSION, $deployFile);