docker-compose.yml
version: "3"
services:
nginx:
image: nginx:1.23.3
ports:
- "8084:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
php:
build: .
volumes:
- ./api:/var/www/html/
nginx.conf
events {}
http {
server {
root /var/www/html/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
I installed Symfony Console "symfony/console": "^6.2"
.
composer.json
{
"require": {
"symfony/runtime": "^6.2",
"symfony/http-kernel": "^6.2",
"symfony/framework-bundle": "^6.2",
"symfony/dotenv": "^6.2",
"doctrine/doctrine-bundle": "^2.8"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/console": "^6.2"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"symfony/runtime": true
}
}
}
I added a src/cli.php
<?php
require __DIR__.'/../vendor/autoload.php';
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new \App\Commands\ExtractAuthorPortraitsCommand());
$application->run();
I added a command
<?php declare(strict_types=1);
namespace App\Commands;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExtractAuthorPortraitsCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
return Command::SUCCESS;
}
}
As soon as I add a name to the command
#[AsCommand(name: 'app:extract-author-portraits')]
class ExtractAuthorPortraitsCommand extends Command
a request to the Symfony app (http://localhost:8084) then gives me an empty response.
And the PHP log shows Console Tool stuff which does not come in the log when Command has no name.
Console Tool
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
completion Dump the shell completion script
help Display help for a command
list List commands
app
app:extract-author-portraits
172.21.0.3 - 18/Jan/2023:07:28:25 +0000 "GET /index.php" 200
Any ideas?
//Registering the Command //In PHP 8 and newer versions, you can register the command by adding the AsCommand //attribute to it. example: