Skip to content

Commit

Permalink
EZP-25613: Add a way to register resources with the rest root (#1619)
Browse files Browse the repository at this point in the history
  • Loading branch information
wizhippo authored and bdunogier committed Apr 29, 2016
1 parent 13a267b commit c6b896d
Show file tree
Hide file tree
Showing 12 changed files with 1,322 additions and 953 deletions.
@@ -0,0 +1,38 @@
<?php
/**
* This file is part of the eZ Publish Kernel package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishRestBundle\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class Configuration extends SiteAccessConfiguration
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('ez_publish_rest');

$this->addRestRootResourcesSection($rootNode);

return $treeBuilder;
}

public function addRestRootResourcesSection($rootNode)
{
$systemNode = $this->generateScopeBaseNode($rootNode);
$systemNode
->arrayNode('rest_root_resources')
->prototype('array')
->children()
->scalarNode('mediaType')->isRequired()->end()
->scalarNode('href')->isRequired()->end()
->end()
->end()
->end();
}
}
@@ -1,13 +1,19 @@
<?php

/**
* This file is part of the eZ Publish Kernel package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishRestBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Yaml\Yaml;

/**
Expand All @@ -22,12 +28,18 @@ class EzPublishRestExtension extends Extension implements PrependExtensionInterf
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('value_object_visitors.yml');
$loader->load('input_parsers.yml');
$loader->load('security.yml');
$loader->load('default_settings.yml');

$processor = new ConfigurationProcessor($container, 'ezsettings');
$processor->mapConfigArray('rest_root_resources', $config);
}

public function prepend(ContainerBuilder $container)
Expand Down
Expand Up @@ -4,3 +4,83 @@ parameters:

# URI part that all REST routes begin with. By this a REST request is recognized.
ezpublish_rest.path_prefix: /api/ezp/v2

ezsettings.default.rest_root_resources:
content:
mediaType: ''
href: 'router.generate("ezpublish_rest_createContent")'
contentByRemoteId:
mediaType: ''
href: 'templateRouter.generate("ezpublish_rest_redirectContent", {remoteId: "{remoteId}"})'
contentTypes:
mediaType: 'ContentTypeInfoList'
href: 'router.generate("ezpublish_rest_listContentTypes")'
contentTypeByIdentifier:
mediaType: ''
href: 'templateRouter.generate("ezpublish_rest_listContentTypes", {identifier: "{identifier}"})'
contentTypeGroups:
mediaType: 'ContentTypeGroupList'
href: 'router.generate("ezpublish_rest_createContentTypeGroup")'
contentTypeGroupByIdentifier:
mediaType: ''
href: 'templateRouter.generate("ezpublish_rest_loadContentTypeGroupList", {identifier: "{identifier}"})'
users:
mediaType: 'UserRefList'
href: 'router.generate("ezpublish_rest_loadUsers")'
usersByRoleId:
mediaType: 'UserRefList'
href: 'templateRouter.generate("ezpublish_rest_loadUsers", {roleId: "{roleId}"})'
usersByRemoteId:
mediaType: 'UserRefList'
href: 'templateRouter.generate("ezpublish_rest_loadUsers", {remoteId: "{remoteId}"})'
usersByEmail:
mediaType: 'UserRefList'
href: 'templateRouter.generate("ezpublish_rest_loadUsers", {email: "{email}"})'
usersByLogin:
mediaType: 'UserRefList'
href: 'templateRouter.generate("ezpublish_rest_loadUsers", {login: "{login}"})'
roles:
mediaType: 'RoleList'
href: 'router.generate("ezpublish_rest_listRoles")'
rootLocation:
mediaType: 'Location'
href: 'router.generate("ezpublish_rest_loadLocation", {locationPath: "1/2"})'
rootUserGroup:
mediaType: 'UserGroup'
href: 'router.generate("ezpublish_rest_loadUserGroup", {groupPath: "1/5"})'
rootMediaFolder:
mediaType: 'Location'
href: 'router.generate("ezpublish_rest_loadLocation", {locationPath: "1/43"})'
locationByRemoteId:
mediaType: ''
href: 'templateRouter.generate("ezpublish_rest_redirectLocation", {remoteId: "{remoteId}"})'
locationByPath:
mediaType: ''
href: 'templateRouter.generate("ezpublish_rest_redirectLocation", {locationPath: "{locationPath}"})'
trash:
mediaType: 'Trash'
href: 'router.generate("ezpublish_rest_loadTrashItems")'
sections:
mediaType: 'SectionList'
href: 'router.generate("ezpublish_rest_listSections")'
views:
mediaType: 'RefList'
href: 'router.generate("ezpublish_rest_views_create")'
objectStateGroups:
mediaType: 'ObjectStateGroupList'
href: 'router.generate("ezpublish_rest_loadObjectStateGroups")'
objectStates:
mediaType: 'ObjectStateList'
href: 'templateRouter.generate("ezpublish_rest_loadObjectStates", {objectStateGroupId: "{objectStateGroupId}"})'
globalUrlAliases:
mediaType: 'UrlAliasRefList'
href: 'router.generate("ezpublish_rest_listGlobalURLAliases")'
urlWildcards:
mediaType: 'UrlWildcardList'
href: 'router.generate("ezpublish_rest_listURLWildcards")'
createSession:
mediaType: 'UserSession'
href: 'router.generate("ezpublish_rest_createSession")'
refreshSession:
mediaType: 'UserSession'
href: 'templateRouter.generate("ezpublish_rest_refreshSession", {sessionId: "{sessionId}"})'
7 changes: 7 additions & 0 deletions eZ/Bundle/EzPublishRestBundle/Resources/config/services.yml
Expand Up @@ -5,6 +5,8 @@ parameters:

ezpublish_rest.cors_options_provider.class: eZ\Bundle\EzPublishRestBundle\CorsOptions\RestProvider

ezpublish_rest.root_resource_builder.class: eZ\Publish\Core\REST\Server\Service\ExpressionRouterRootResourceBuilder

ezpublish_rest.controller.base.class: eZ\Publish\Core\REST\Server\Controller
ezpublish_rest.controller.binary_content.class: eZ\Publish\Core\REST\Server\Controller\BinaryContent
ezpublish_rest.controller.content.class: eZ\Publish\Core\REST\Server\Controller\Content
Expand Down Expand Up @@ -121,6 +123,10 @@ services:
calls:
- [setRequestStack, [@request_stack]]

ezpublish_rest.root_resource_builder:
class: %ezpublish_rest.root_resource_builder.class%
arguments: [@router, @ezpublish_rest.templated_router, "$rest_root_resources$"]

ezpublish_rest.controller.base:
class: %ezpublish_rest.controller.base.class%
calls:
Expand All @@ -133,6 +139,7 @@ services:
ezpublish_rest.controller.root:
class: %ezpublish_rest.controller.root.class%
parent: ezpublish_rest.controller.base
arguments: [@ezpublish_rest.root_resource_builder]

ezpublish_rest.controller.section:
class: %ezpublish_rest.controller.section.class%
Expand Down

0 comments on commit c6b896d

Please sign in to comment.