PHP code example of draw / swagger-bundle
1. Go to this page and download the library: Download draw/swagger-bundle 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' );
draw / swagger-bundle example snippets
namespace App \Listener ;
use Draw \SwaggerBundle \View \View ;
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
use Symfony \Component \HttpKernel \Event \ViewEvent ;
use Symfony \Component \HttpKernel \KernelEvents ;
class VersionListener implements EventSubscriberInterface
{
public static function getSubscribedEvents ()
{
return [
KernelEvents::VIEW => ['onKernelView' , 31 ]
];
}
public function onKernelView (ViewEvent $event)
{
$request = $event->getRequest();
$pathInfo = $request->getPathInfo();
$sections = explode('/' , $pathInfo, 4 );
if (!isset ($sections[2 ])) {
return ;
}
$version = trim($sections[2 ], 'v' );
if ($sections[2 ] != ('v' . $version)) {
return ;
}
$view = $request->attributes->get('_template' , new View([]));
if ($view instanceof View && is_null($view->getSerializerVersion())) {
$view->setSerializerVersion($version);
}
$request->attributes->set('_template' , $view);
}
}
public function defaultAction ()
{
}
public function defaultAction ()
{
}
public function createAction ($param1 = 'default' )
{
}