-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpho
More file actions
executable file
·81 lines (64 loc) · 3.17 KB
/
pho
File metadata and controls
executable file
·81 lines (64 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/php
<?php
/**
* Pho ... undation!
*
* This is the standard phoundation command execution script.
*
* With this script you can execute all Phoundation scripts. It supports auto complete so please try and use <TAB> to
* find sub commands, but also use <TAB> in sub commands as most support auto complete with nearly all parameters.
*
* This script will also ensure that all required PHP modules and all vendor directories are installed using PHP
* composer (included in your Phoundation installation in ROOT/data/bin)
*
* @author Sven Olaf Oostenbrink <so.oostenbrink@gmail.com>
* @license http://opensource.org/licenses/GPL-2.0 GNU Public License, Version 2
* @copyright Copyright (c) 2022 Sven Olaf Oostenbrink <so.oostenbrink@gmail.com>
* @category Scripts
* @package Phoundation\Cli
*/
use Phoundation\Cli\CliCommand;
use Phoundation\Cli\Exception\CliCommandNotExistsException;
use Phoundation\Cli\Exception\CliCommandNotFoundException;
use Phoundation\Core\Core;
use Phoundation\Exception\PhoException;
try {
// Load the PHP autoloader and execute the static Script::execute() method that will execute the requested command
define('PHO_DIRECTORY', __DIR__ . '/');
if (!@include(PHO_DIRECTORY . '/vendor/autoload.php')) {
throw new Exception('Failed opening required \'./vendor/autoload.php\'');
}
CliCommand::execute();
} catch (Throwable $e) {
if (($e instanceof CliCommandNotExistsException) or ($e instanceof CliCommandNotFoundException)) {
throw $e;
}
$message = $e->getMessage();
if (str_starts_with($message, 'Failed opening required \'./vendor/autoload.php\'')) {
// Whoops, no vendor libraries available. Run composer to fix
echo 'WARNING: Autoloader or vendor libraries could not be found, attempting to fix with composer' . PHP_EOL;
if (file_exists(PHO_DIRECTORY . '/data/bin/composer.phar')) {
passthru('php ' . PHO_DIRECTORY . '/data/bin/composer.phar update', $exit_code);
if ($exit_code) {
throw new Exception('Composer failed to execute, see composer output for more information');
}
}else {
echo 'WARNING: Included composer.phar file missing, attempting to run system composer' . PHP_EOL;
$output = exec('which composer');
if ($output) {
passthru($output . ' update', $exit_code);
if ($exit_code) {
throw new Exception('Composer failed to execute, see composer output for more information');
}
} else {
echo 'ERROR: Autoloader and or vendor libraries are missing and failed to find local (./composer.phar) or system composer to try and fix this issue. Please recover the local composer file ./composer.phar or install composer (sudo apt install composer, for example) on your system to retry.' . PHP_EOL;
exit(1);
}
}
echo 'WARNING: Libraries successfully installed, retrying execution of PHO script' . PHP_EOL;
include('./vendor/autoload.php');
CliCommand::execute();
}
// Some other issue occurred, continue throwing exception
throw $e;
}