PHP code example of fdevs / export-routing

1. Go to this page and download the library: Download fdevs/export-routing 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/ */

    

fdevs / export-routing example snippets



use FDevs\ExportRouting\Normalizer\RouteCollectionNormalizer;
use FDevs\ExportRouting\Normalizer\RouteNormalizer;
use FDevs\ExportRouting\Normalizer\RouteExtractorNormalizer;
use FDevs\ExportRouting\Encoder\JsCallbackEncoder;
use FDevs\ExportRouting\RoutesExtractor;
use FDevs\ExportRouting\Extractor\ChainExposed;
use FDevs\ExportRouting\Extractor\OptionExposed;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;

$router = ;//get your routes Symfony\Component\Routing\RouterInterface
$exposed = new ChainExposed([new OptionExposed()]);
$extractor = new RoutesExtractor($router,$exposed);

$normalizers = [
  new RouteCollectionNormalizer(),
  new RouteNormalizer(),
  new RouteExtractorNormalizer(),
  //your normalizers
];
$encoders = [
  new JsCallbackEncoder(),
  new JsonEncoder(),
  //your encoders
];

$serializer = new Serializer(normalizers, encoders);

echo $serializer->serialize(extractor,'js',['callback' => 'initRouting']);//js with callback
echo $serializer->serialize(extractor,'json');//json

 // ...
$serializer = new Serializer(\**\);//init serializer
$extractor = new RoutesExtractor(\**\);//init extractor
$application->add(new DumpCommand($serializer,$extractor,'fdevs:dump-routing:dump'));