Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-25613 Add a way to register resources with the rest root #1619

Merged
merged 4 commits into from Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't "rest" redundant ? Could be root_resources alone, since it is namespaced below ez_publish_rest ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these end up under ezsettings.rest_root_resources I thought it would be best to clarify they belong to rest. Not that there would be other root_resources there.

Just confirm and I will change it..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, don't touch anything :)

->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