dreadlabs/kunstmaan-content-api-bundle
This bundle configures a Kunstmaan CMS instance in order to easily provide your content through a custom API format.
It uses willdurand/negotation in order to inject a Request attribute media_type which is
used to delegate to a serialization of a Page entity (Node) into a specific response format.
composer install dreadlabs/kunstmaan-content-api-bundle
Load the bundle in your AppKernel
// snip
new DreadLabs\KunstmaanContentApiBundle\DreadLabsKunstmaanContentApiBundle()
// snap
Implement the Kunstmaan\NodeBundle\Controller\SlugActionInterface in your Page entities,
implement the getControllerAction and point to the Bundle's ApiController:
// src/Acme/WebsiteBundle/Entity/Pages/HomePage.php
<?php
class HomePage implements [...], SlugActionInterface
{
// snip
/**
* @return string
*
*/
public function getControllerAction()
{
return 'dreadlabs_kunstmaan_content_api.controller:getAction';
}
// snap
}
Important: Make sure, you are using the Controllers as Service notation.
Implement the Bundle's DreadLabs\KunstmaanContentApiBundle\Api\SerializableInterface in order to point the
Kunstmaan Node entity to the API representation:
// src/Acme/WebsiteBundle/Entity/Pages/HomePage.php
<?php
use Acme\WebsiteBundle\Api\Page\Home as ApiType;
class HomePage implements [...], SerializableInterface
{
// snip
/**
* Returns the name of the API type (class).
*
* @return string
*/
public function getApiType()
{
return ApiType::class;
}
// snap
}
Implement an API type for serialization:
// src/Acme/WebsiteBundle/Api/Page/Home.php
<?php
class Home
{
/**
* @var string
*/
public $title;
public function __construct($title)
{
$this->title = $title;
}
}
Read the Serializer documentation and the Serializer cookbook to learn more about serialization of your API types.
priorities argument of DreadLabs\KunstmaanContentApiBundle\EventListener\MediaTypeListenermediaType in DreadLabs\KunstmaanContentApiBundle\Api\Factoryprod and dev environments in DreadLabs/KunstmaanContentApiBundle/DependencyInjection/DreadLabsKunstmaanContentApiExtensionframework.serializer.cache setting in DreadLabs/KunstmaanContentApiBundle/DependencyInjection/DreadLabsKunstmaanContentApiExtension
app/config/config.yml?How can I help you explore Laravel packages today?