PHP code example of macedigital / silex-jms-serializer
1. Go to this page and download the library: Download macedigital/silex-jms-serializer 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/ */
macedigital / silex-jms-serializer example snippets
$loader = re using class annotations
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$app = new Silex\Application();
// optional: whether to stat cached files or not, defaults to $app['debug']
$app['serializer.debug'] = true;
// optional: defaults to system's default temporary folder
$app['serializer.cache_dir'] = '/some/writable/folder';
$app->register(new Macedigital\Silex\Provider\SerializerProvider);
// only accept content types supported by the serializer via the assert method.
$app->get("/pages/{id}.{_format}", function ($id) use ($app) {
// assume a page_repository service exists that returns a Page object
$page = $app['page_repository']->find($id);
$format = $app['request']->getRequestFormat();
if (!$page instanceof Page) {
$app->abort("No page found for id: $id");
}
return new Response($app['serializer']->serialize($page, $format), 200, array(
"Content-Type" => $app['request']->getMimeType($format)
));
})->assert("_format", "xml|json|yml")
->assert("id", "\d+");
$app->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.