dreadlabs/kunstmaan-content-api-bundle

此包已被弃用且不再维护。未建议替代包。

将媒体类型监听器和内容API层集成到Kunstmaan CMS实例中。

0.1.2 2016-10-26 12:51 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:19:11 UTC


README

这是什么?

此包配置Kunstmaan CMS实例,以便通过自定义API格式轻松提供内容。

它使用 willdurand/negotation 注入一个 media_typeRequest 属性,用于将 Page 实体(Node)序列化到特定的响应格式。

安装

composer install dreadlabs/kunstmaan-content-api-bundle

如何使用?

  1. 在您的 AppKernel 中加载此包

    // snip
    new DreadLabs\KunstmaanContentApiBundle\DreadLabsKunstmaanContentApiBundle()
    // snap
    
  2. 在您的 Page 实体中实现 Kunstmaan\NodeBundle\Controller\SlugActionInterface,实现 getControllerAction 并指向包的 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
    }
    

    重要:请确保您使用的是 将控制器作为服务 的表示法。

  3. 为了将Kunstmaan的 Node 实体指向API表示,实现包的 DreadLabs\KunstmaanContentApiBundle\Api\SerializableInterface

    // 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
    }
    
  4. 实现API类型的序列化

    // src/Acme/WebsiteBundle/Api/Page/Home.php
    <?php
    class Home
    {
        /**
         * @var string
         */
        public $title;
        
        public function __construct($title)
        {
           $this->title = $title;
        }
    }
    

    阅读 序列化文档序列化食谱 了解更多关于API类型序列化的信息。

待办事项

  • DreadLabs\KunstmaanContentApiBundle\EventListener\MediaTypeListenerpriorities 参数添加配置选项
  • DreadLabs\KunstmaanContentApiBundle\Api\Factory 中配置预期的 mediaType
  • DreadLabs/KunstmaanContentApiBundle/DependencyInjection/DreadLabsKunstmaanContentApiExtension 中添加在 proddev 环境之间分支的可能性
  • DreadLabs/KunstmaanContentApiBundle/DependencyInjection/DreadLabsKunstmaanContentApiExtension 中添加覆盖/配置 framework.serializer.cache 设置的可能性
    • 问:这难道不是通过在 app/config/config.yml 中设置/取消设置配置键就可以实现吗?