bluzphp /
skeleton
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Bluz Framework Component |
||
| 5 | * |
||
| 6 | * @copyright Bluz PHP Team |
||
| 7 | * @link https://github.com/bluzphp/framework |
||
| 8 | */ |
||
| 9 | |||
| 10 | declare(strict_types=1); |
||
| 11 | |||
| 12 | namespace Application; |
||
| 13 | |||
| 14 | use Application\Users\Table; |
||
| 15 | use Bluz\Application\Application; |
||
|
0 ignored issues
–
show
|
|||
| 16 | use Bluz\Controller\Controller; |
||
|
0 ignored issues
–
show
The type
Bluz\Controller\Controller was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 17 | use Bluz\Db\Exception\DbException; |
||
|
0 ignored issues
–
show
The type
Bluz\Db\Exception\DbException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 18 | use Bluz\Proxy\Auth; |
||
|
0 ignored issues
–
show
The type
Bluz\Proxy\Auth was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 19 | use Bluz\Proxy\Logger; |
||
|
0 ignored issues
–
show
The type
Bluz\Proxy\Logger was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 20 | use Bluz\Proxy\Request; |
||
|
0 ignored issues
–
show
The type
Bluz\Proxy\Request was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 21 | use Bluz\Proxy\Response; |
||
|
0 ignored issues
–
show
The type
Bluz\Proxy\Response was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 22 | use Bluz\Proxy\Router; |
||
|
0 ignored issues
–
show
The type
Bluz\Proxy\Router was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 23 | use Bluz\Request\RequestFactory; |
||
|
0 ignored issues
–
show
The type
Bluz\Request\RequestFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 24 | use Symfony\Component\Console\Input\InputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 25 | use Symfony\Component\Console\Output\OutputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 26 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Style\SymfonyStyle was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 27 | |||
| 28 | /** |
||
| 29 | * Bootstrap for CLI |
||
| 30 | * |
||
| 31 | * @category Application |
||
| 32 | * @package Bootstrap |
||
| 33 | */ |
||
| 34 | class CliBootstrap extends Application |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * Layout flag |
||
| 38 | * |
||
| 39 | * @var boolean |
||
| 40 | */ |
||
| 41 | protected $layoutFlag = false; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var InputInterface |
||
| 45 | */ |
||
| 46 | protected $input; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var OutputInterface |
||
| 50 | */ |
||
| 51 | protected $output; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param InputInterface $input |
||
| 55 | */ |
||
| 56 | public function setInput(InputInterface $input): void |
||
| 57 | { |
||
| 58 | $this->input = $input; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return InputInterface |
||
| 63 | */ |
||
| 64 | public function getInput() |
||
| 65 | { |
||
| 66 | return $this->input; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param OutputInterface $output |
||
| 71 | */ |
||
| 72 | public function setOutput(OutputInterface $output): void |
||
| 73 | { |
||
| 74 | $this->output = $output; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @return OutputInterface |
||
| 79 | */ |
||
| 80 | public function getOutput() |
||
| 81 | { |
||
| 82 | return $this->output; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * get CLI Request |
||
| 87 | * |
||
| 88 | * @return void |
||
| 89 | * @throws \InvalidArgumentException |
||
| 90 | */ |
||
| 91 | public function initRequest(): void |
||
| 92 | { |
||
| 93 | $uri = $this->getInput()->getArgument('uri'); |
||
| 94 | |||
| 95 | $parsedQuery = parse_url($uri, PHP_URL_QUERY); |
||
| 96 | if (false !== $parsedQuery && null !== $parsedQuery) { |
||
| 97 | parse_str($parsedQuery, $query); |
||
| 98 | } else { |
||
| 99 | $query = []; |
||
| 100 | } |
||
| 101 | |||
| 102 | $request = RequestFactory::fromGlobals(['REQUEST_URI' => $uri, 'REQUEST_METHOD' => 'CLI'], $query); |
||
| 103 | |||
| 104 | Request::setInstance($request); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Pre process |
||
| 109 | * |
||
| 110 | * @return void |
||
| 111 | */ |
||
| 112 | protected function preProcess(): void |
||
| 113 | { |
||
| 114 | Router::process(); |
||
| 115 | Response::setType('CLI'); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * {@inheritdoc} |
||
| 120 | * |
||
| 121 | * @param Controller $controller |
||
| 122 | * |
||
| 123 | * @return void |
||
| 124 | * @throws DbException |
||
| 125 | */ |
||
| 126 | protected function preDispatch($controller): void |
||
| 127 | { |
||
| 128 | // auth as CLI user |
||
| 129 | if ($cliUser = Table::findRowWhere(['login' => 'system'])) { |
||
| 130 | Auth::setIdentity($cliUser); |
||
| 131 | } |
||
| 132 | |||
| 133 | parent::preDispatch($controller); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Render, is send Response |
||
| 138 | * |
||
| 139 | * @return void |
||
| 140 | */ |
||
| 141 | public function render(): void |
||
| 142 | { |
||
| 143 | $io = new SymfonyStyle($this->getInput(), $this->getOutput()); |
||
| 144 | $io->title('Bluz CLI'); |
||
| 145 | |||
| 146 | if ($params = Request::getParams()) { |
||
| 147 | foreach ($params as $key => $value) { |
||
| 148 | $key = \is_int($key) ? "<comment>$key</comment>" : "<info>$key</info>"; |
||
| 149 | $io->writeln("$key: $value"); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $io->writeln(''); |
||
| 154 | $io->writeln('========'); |
||
| 155 | $io->writeln(''); |
||
| 156 | $io->writeln(json_encode(Response::getBody())); |
||
| 157 | $io->writeln(''); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Finish it |
||
| 162 | * |
||
| 163 | * @return void |
||
| 164 | */ |
||
| 165 | public function end(): void |
||
| 166 | { |
||
| 167 | if ($errors = Logger::get('error')) { |
||
| 168 | $this->sendErrors($errors); |
||
| 169 | } |
||
| 170 | // return code 1 for invalid behaviour of application |
||
| 171 | // if ($exception = $this->getException()) { |
||
| 172 | // echo $exception->getMessage(); |
||
| 173 | // exit(1); |
||
| 174 | // } |
||
| 175 | exit; |
||
|
0 ignored issues
–
show
|
|||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Send errors to logger |
||
| 180 | * |
||
| 181 | * @param array $errors |
||
| 182 | * |
||
| 183 | * @return void |
||
| 184 | */ |
||
| 185 | protected function sendErrors($errors): void |
||
| 186 | { |
||
| 187 | foreach ($errors as $message) { |
||
| 188 | errorLog(new \ErrorException($message, 0, E_USER_ERROR)); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
||
| 192 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths