PHP code example of dlinsmeyer / api-response-bundle
1. Go to this page and download the library: Download dlinsmeyer/api-response-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');
/* Start to develop here. Best regards https://php-download.com/ */
dlinsmeyer / api-response-bundle example snippets
// in AppKernel::registerBundles()
$bundles = array(
// ...
new DLinsmeyer\Bundle\ApiBundle\DLinsmeyerApiBundle(),
// ...
);
/**
* since we can't load bundles proper, we need to register
* the custom types that would be handled via our serializer service here
*/
$callable = Pimple::protect(
function(\JMS\Serializer\Handler\HandlerRegistry $handlerRegistry) {
$handlerRegistry->registerSubscribingHandler(new \DLinsmeyer\Bundle\ApiBundle\Serializer\Handler\MixedTypeHandler());
}
);
$application->register(
new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(),
array(
"serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
"serializer.configureHandlers" => $callable,
)
);
namespace YourVendor\YourBundle\Serializer\Handler;
use DLinsmeyer\Bundle\ApiBundle\Serializer\Handler\MixedTypeHandler as BaseMixedTypeHandler;
/**
* Overrides the default Mixed type to
* do something custom
*/
class MixedTypeHandler extends BaseMixedTypeHandler
{
/**
* Overrides the core type determinance to point some of our Document/Entity files
* to their models
*
* @inheritdoc
*/
protected function determineType($value)
{
$calcualtedType = parent::determineType($value);
//do some custom logic
return $calcualtedType;
}
}
bash
$ php composer.phar update
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.