PHP code example of bolzer / symfony-typescript-routes

1. Go to this page and download the library: Download bolzer/symfony-typescript-routes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bolzer / symfony-typescript-routes example snippets


// bundles.php


return [
    Bolzer\SymfonyTypescriptRoutes\Bundle\TypescriptPathBundle::class => ['all' => true],
];


// some_command.php


use Bolzer\SymfonyTypescriptRoutes\Service\GeneratorService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Bolzer\SymfonyTypescriptRoutes\Dto\GeneratorConfig;

class GenerationCommand extends Command
{
    public function __construct(
        private GeneratorService $generatorService,
    ){}

      protected function configure(): void
    {
        $this->setName('generate_paths');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
       // Typescript routes containing relative and absolute urls.
       $routes = $this->generatorService->generate(GeneratorConfig::generateEverything());
       
       // Typescript routes containing absolute urls.
       $routes = $this->generatorService->generate(GeneratorConfig::generateOnlyAbsoluteUrls());
       
       // Typescript routes containing absolute urls.
       $routes = $this->generatorService->generate(GeneratorConfig::generateOnlyRelativeUrls());
    
       file_put_contents(__DIR__ . '../../../paths.ts', implode("\n", $routes));
       $output->writeln('<comment>Generation of paths done.</comment>');
       
       return Command::SUCCESS;
    }
}