Last active
June 10, 2020 07:23
-
-
Save Matts/528c249a82e5844164039c4f6c0db046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// framework.yaml | |
parameters: | |
router.request_context.host: test.host #you can also use %env(HOST) and then set the HOST variable in your .env file | |
router.request_context.scheme: http | |
router.request_context.base_url: /api/ep | |
router.request_context.port: 49100 | |
framework: | |
... | |
// MyCommand.php | |
namespace App\Command; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Command\LockableTrait; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |
use Symfony\Component\Routing\RouterInterface; | |
class MyCommand extends Command | |
{ | |
use LockableTrait; | |
private $router; | |
// the name of the command (the part after "bin/console") | |
protected static $defaultName = 'app:deliver'; | |
public function __construct(RouterInterface $router) | |
{ | |
parent::__construct(); | |
$this->router = $router; | |
} | |
protected function configure() | |
{ | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$url = $this->router->generate('ep', ['MessageId' => ['message']], UrlGeneratorInterface::ABSOLUTE_URL); | |
dump($url); //route not found for me, I would guess you set 'ep' as a correct route in the routes.yaml or in @Route | |
return Command::SUCCESS; | |
// or return this if some error happened during the execution | |
// (it's equivalent to returning int(1)) | |
// return Command::FAILURE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment