parameters:
    ezpublish_rest.routing.options_loader.class: eZ\Bundle\EzPublishRestBundle\Routing\OptionsLoader
    ezpublish_rest.routing.options_loader.route_collection_mapper.class: eZ\Bundle\EzPublishRestBundle\Routing\OptionsLoader\RouteCollectionMapper
    ezpublish_rest.routing.options_loader.mapper.class: eZ\Bundle\EzPublishRestBundle\Routing\OptionsLoader\Mapper

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

    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
    ezpublish_rest.controller.content_type.class: eZ\Publish\Core\REST\Server\Controller\ContentType
    ezpublish_rest.controller.location.class: eZ\Publish\Core\REST\Server\Controller\Location
    ezpublish_rest.controller.object_state.class: eZ\Publish\Core\REST\Server\Controller\ObjectState
    ezpublish_rest.controller.role.class: eZ\Publish\Core\REST\Server\Controller\Role
    ezpublish_rest.controller.root.class: eZ\Publish\Core\REST\Server\Controller\Root
    ezpublish_rest.controller.section.class: eZ\Publish\Core\REST\Server\Controller\Section
    ezpublish_rest.controller.trash.class: eZ\Publish\Core\REST\Server\Controller\Trash
    ezpublish_rest.controller.user.class: eZ\Publish\Core\REST\Server\Controller\User
    ezpublish_rest.controller.url_wildcard.class: eZ\Publish\Core\REST\Server\Controller\URLWildcard
    ezpublish_rest.controller.url_alias.class: eZ\Publish\Core\REST\Server\Controller\URLAlias
    ezpublish_rest.controller.options.class: eZ\Publish\Core\REST\Server\Controller\Options
    ezpublish_rest.controller.services.class: eZ\Publish\Core\REST\Server\Controller\Services

    ezpublish_rest.factory.class: eZ\Bundle\EzPublishRestBundle\ApiLoader\Factory
    ezpublish_rest.request_parser.class: eZ\Bundle\EzPublishRestBundle\RequestParser\Router
    ezpublish_rest.parser_tools.class: eZ\Publish\Core\REST\Common\Input\ParserTools
    ezpublish_rest.field_type_parser.class: eZ\Publish\Core\REST\Common\Input\FieldTypeParser
    ezpublish_rest.field_type_serializer.class: eZ\Publish\Core\REST\Common\Output\FieldTypeSerializer

    ezpublish_rest.request_listener.class: eZ\Bundle\EzPublishRestBundle\EventListener\RequestListener
    ezpublish_rest.csrf_listener.class: eZ\Bundle\EzPublishRestBundle\EventListener\CsrfListener
    ezpublish_rest.response_listener.class: eZ\Bundle\EzPublishRestBundle\EventListener\ResponseListener

    ezpublish_rest.field_type_processor_registry.class: eZ\Publish\Core\REST\Common\FieldTypeProcessorRegistry
    ezpublish_rest.field_type_processor.ezimage.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor
    ezpublish_rest.field_type_processor.ezdatetime.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\DateAndTimeProcessor
    ezpublish_rest.field_type_processor.ezdate.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\DateProcessor
    ezpublish_rest.field_type_processor.ezmedia.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\MediaProcessor
    ezpublish_rest.field_type_processor.ezobjectrelationlist.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\RelationListProcessor
    ezpublish_rest.field_type_processor.ezobjectrelation.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\RelationProcessor
    ezpublish_rest.field_type_processor.eztime.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\TimeProcessor
    ezpublish_rest.field_type_processor.ezrichtext.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\RichTextProcessor
    ezpublish_rest.field_type_processor.ezxmltext.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\XmlTextProcessor
    ezpublish_rest.field_type_processor.ezbinaryfile.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\BinaryProcessor
    ezpublish_rest.field_type_processor.ezpage.class: eZ\Publish\Core\REST\Common\FieldTypeProcessor\PageProcessor

    ezpublish_rest.output.visitor.dispatcher.class: eZ\Publish\Core\REST\Server\View\AcceptHeaderVisitorDispatcher
    ezpublish_rest.output.visitor.class: eZ\Publish\Core\REST\Common\Output\Visitor
    ezpublish_rest.output.generator.json.class: eZ\Publish\Core\REST\Common\Output\Generator\Json
    ezpublish_rest.output.generator.json.field_type_hash_generator.class: eZ\Publish\Core\REST\Common\Output\Generator\Json\FieldTypeHashGenerator
    ezpublish_rest.output.generator.xml.class: eZ\Publish\Core\REST\Common\Output\Generator\Xml
    ezpublish_rest.output.generator.xml.field_type_hash_generator.class: eZ\Publish\Core\REST\Common\Output\Generator\Xml\FieldTypeHashGenerator
    ezpublish_rest.output.visitor.json.regexps:
        - '(^application/vnd\.ez\.api\.[A-Za-z]+\+json$)'
        - '(^application/json$)'
    ezpublish_rest.output.visitor.xml.regexps:
        - '(^application/vnd\.ez\.api\.[A-Za-z]+\+xml$)'
        - '(^application/xml$)'
        - '(^.*/.*$)'

    ezpublish_rest.output.value_object_visitor.dispatcher.class: eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher
    ezpublish_rest.output.value_object_visitor.Exception.InvalidArgumentException.class: eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\InvalidArgumentException

    ezpublish_rest.input.dispatcher.class: eZ\Publish\Core\REST\Common\Input\Dispatcher
    ezpublish_rest.input.parsing_dispatcher.class: eZ\Publish\Core\REST\Common\Input\ParsingDispatcher

    ezpublish_rest.input.handler.json.class: eZ\Publish\Core\REST\Common\Input\Handler\Json
    ezpublish_rest.input.handler.xml.class: eZ\Publish\Core\REST\Common\Input\Handler\Xml

    ezpublish_rest.templated_router.class: %router.class%

services:
    ezpublish_rest.routing.options_loader:
        class: %ezpublish_rest.routing.options_loader.class%
        arguments:
            - @ezpublish_rest.routing.options_loader.route_collection_mapper
            - @ezpublish_rest.templated_router
        tags:
            - { name: routing.loader }

    ezpublish_rest.routing.options_loader.route_collection_mapper:
        class: %ezpublish_rest.routing.options_loader.route_collection_mapper.class%
        arguments:
            - @ezpublish_rest.routing.options_loader.mapper

    ezpublish_rest.routing.options_loader.mapper:
        class: %ezpublish_rest.routing.options_loader.mapper.class%

    ezpublish_rest.cors_option_provider:
        class: %ezpublish_rest.cors_options_provider.class%
        arguments: [@router.default]
        tags:
            - { name: nelmio_cors.options_provider }

    ezpublish_rest.field_type_serializer:
        class: %ezpublish_rest.field_type_serializer.class%
        arguments:
            - @ezpublish.api.service.field_type
            - @ezpublish_rest.field_type_processor_registry

    ezpublish_rest.request_parser:
        class: %ezpublish_rest.request_parser.class%
        arguments:
            - %ezpublish_rest.path_prefix%
            - @router

    ezpublish_rest.parser_tools:
        class: %ezpublish_rest.parser_tools.class%

    ezpublish_rest.field_type_parser:
        class: %ezpublish_rest.field_type_parser.class%
        arguments:
            - @ezpublish.api.service.content
            - @ezpublish.api.service.content_type
            - @ezpublish.api.service.field_type
            - @ezpublish_rest.field_type_processor_registry

    ezpublish_rest.factory:
        class: %ezpublish_rest.factory.class%
        arguments: [@ezpublish.config.resolver, @ezpublish.api.repository]
        calls:
            - [setRequest, [@?request=]]

    ezpublish_rest.controller.base:
        class: %ezpublish_rest.controller.base.class%
        calls:
            - [ setContainer, [@service_container] ]
            - [ setInputDispatcher, [@ezpublish_rest.input.dispatcher] ]
            - [ setRouter, [@router] ]
            - [ setRequestParser, [@ezpublish_rest.request_parser] ]
            - [ setRequest, [@?request=] ]
            - [ setRepository, [@ezpublish.api.repository] ]

    ezpublish_rest.controller.root:
        class: %ezpublish_rest.controller.root.class%
        parent: ezpublish_rest.controller.base

    ezpublish_rest.controller.section:
        class: %ezpublish_rest.controller.section.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.section

    ezpublish_rest.controller.binary_content:
        class: %ezpublish_rest.controller.binary_content.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.fieldType.ezimage.variation_service

    ezpublish_rest.controller.content:
        class: %ezpublish_rest.controller.content.class%
        parent: ezpublish_rest.controller.base

    ezpublish_rest.controller.content_type:
        class: %ezpublish_rest.controller.content_type.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.content_type

    ezpublish_rest.controller.role:
        class: %ezpublish_rest.controller.role.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.role
            - @ezpublish.api.service.user
            - @ezpublish.api.service.location

    ezpublish_rest.controller.location:
        class: %ezpublish_rest.controller.location.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.location
            - @ezpublish.api.service.content
            - @ezpublish.api.service.trash

    ezpublish_rest.controller.object_state:
        class: %ezpublish_rest.controller.object_state.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.object_state
            - @ezpublish.api.service.content

    ezpublish_rest.controller.trash:
        class: %ezpublish_rest.controller.trash.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.trash
            - @ezpublish.api.service.location

    ezpublish_rest.controller.user:
        class: %ezpublish_rest.controller.user.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.user
            - @ezpublish.api.service.role
            - @ezpublish.api.service.content
            - @ezpublish.api.service.content_type
            - @ezpublish.api.service.location
            - @ezpublish.api.service.section
            - @ezpublish.api.repository

    ezpublish_rest.controller.url_wildcard:
        class: %ezpublish_rest.controller.url_wildcard.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.url_wildcard

    ezpublish_rest.controller.url_alias:
        class: %ezpublish_rest.controller.url_alias.class%
        parent: ezpublish_rest.controller.base
        arguments:
            - @ezpublish.api.service.url_alias
            - @ezpublish.api.service.location

    ezpublish_rest.request_listener:
        class: %ezpublish_rest.request_listener.class%
        arguments:
            - %ezpublish_rest.path_prefix%
        tags:
            - { name: kernel.event_subscriber }

    ezpublish_rest.response_listener:
        class: %ezpublish_rest.response_listener.class%
        arguments:
            - @ezpublish_rest.output.visitor.dispatcher
        tags:
            - { name: kernel.event_subscriber }

    ezpublish_rest.csrf_listener:
        class: %ezpublish_rest.csrf_listener.class%
        arguments:
            - @event_dispatcher
            - %form.type_extension.csrf.enabled%
            - %ezpublish_rest.csrf_token_intention%
            - @?form.csrf_provider
        tags:
            - { name: kernel.event_subscriber }

    ezpublish_rest.controller.options:
        class: %ezpublish_rest.controller.options.class%
        parent: ezpublish_rest.controller.base

    ezpublish_rest.controller.services:
        class: %ezpublish_rest.controller.services.class%
        arguments: [%ezpublish.fieldType.ezcountry.data%]

    ezpublish_rest.field_type_processor_registry:
        class: %ezpublish_rest.field_type_processor_registry.class%

    ezpublish_rest.field_type_processor.ezimage:
        class: %ezpublish_rest.field_type_processor.ezimage.class%
        factory_service: ezpublish_rest.factory
        factory_method: getImageFieldTypeProcessor
        arguments:
            - @router
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezimage }

    ezpublish_rest.field_type_processor.ezdatetime:
        class: %ezpublish_rest.field_type_processor.ezdatetime.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezdatetime }

    ezpublish_rest.field_type_processor.ezdate:
        class: %ezpublish_rest.field_type_processor.ezdate.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezdate }

    ezpublish_rest.field_type_processor.ezmedia:
        class: %ezpublish_rest.field_type_processor.ezmedia.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezmedia }

    ezpublish_rest.field_type_processor.ezobjectrelationlist:
        class: %ezpublish_rest.field_type_processor.ezobjectrelationlist.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezobjectrelationlist }

    ezpublish_rest.field_type_processor.ezobjectrelation:
        class: %ezpublish_rest.field_type_processor.ezobjectrelation.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezobjectrelation }

    ezpublish_rest.field_type_processor.eztime:
        class: %ezpublish_rest.field_type_processor.eztime.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: eztime }

    ezpublish_rest.field_type_processor.ezrichtext:
        class: %ezpublish_rest.field_type_processor.ezrichtext.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezrichtext }

    ezpublish_rest.field_type_processor.ezxmltext:
        class: %ezpublish_rest.field_type_processor.ezxmltext.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezxmltext }

    ezpublish_rest.field_type_processor.ezbinaryfile:
        class: %ezpublish_rest.field_type_processor.ezbinaryfile.class%
        factory_service: ezpublish_rest.factory
        factory_method: getBinaryFileFieldTypeProcessor
        arguments:
            - @ezpublish.core.io.default_url_decorator
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezbinaryfile }

    ezpublish_rest.field_type_processor.ezpage:
        class: %ezpublish_rest.field_type_processor.ezpage.class%
        tags:
            - { name: ezpublish_rest.field_type_processor, alias: ezpage }

    ### OUTPUT

    # Main REST output dispatcher
    # Gets a <requestMatch> => output.visitor mapping with the ezpublish_rest.output.visitor tag.
    ezpublish_rest.output.visitor.dispatcher:
        class: %ezpublish_rest.output.visitor.dispatcher.class%

    # format output visitors
    ezpublish_rest.output.visitor.json:
        class: %ezpublish_rest.output.visitor.class%
        arguments:
            - @ezpublish_rest.output.generator.json
            - @ezpublish_rest.output.value_object_visitor.dispatcher
        tags:
            - { name: ezpublish_rest.output.visitor, regexps: ezpublish_rest.output.visitor.json.regexps }

    ezpublish_rest.output.visitor.xml:
        class: %ezpublish_rest.output.visitor.class%
        arguments:
            - @ezpublish_rest.output.generator.xml
            - @ezpublish_rest.output.value_object_visitor.dispatcher
        tags:
            - { name: ezpublish_rest.output.visitor, regexps: ezpublish_rest.output.visitor.xml.regexps }

    # format output generators
    ezpublish_rest.output.generator.xml:
        class: %ezpublish_rest.output.generator.xml.class%
        arguments:
            - @ezpublish_rest.output.generator.xml.field_type_hash_generator
        calls:
            - [ setFormatOutput, [ %kernel.debug% ] ]

    ezpublish_rest.output.generator.xml.field_type_hash_generator:
        class: %ezpublish_rest.output.generator.xml.field_type_hash_generator.class%

    ezpublish_rest.output.generator.json:
        class: %ezpublish_rest.output.generator.json.class%
        arguments:
            - @ezpublish_rest.output.generator.json.field_type_hash_generator
        calls:
            - [ setFormatOutput, [ %kernel.debug% ] ]

    ezpublish_rest.output.generator.json.field_type_hash_generator:
        class: %ezpublish_rest.output.generator.json.field_type_hash_generator.class%

    # value objects visitors
    ezpublish_rest.output.value_object_visitor.dispatcher:
        class: %ezpublish_rest.output.value_object_visitor.dispatcher.class%

    ezpublish_rest.output.value_object_visitor.Exception.InvalidArgumentException:
        class: %ezpublish_rest.output.value_object_visitor.Exception.InvalidArgumentException.class%
        tags:
            - { name: ezpublish_rest.output.value_object_visitor, type: \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException }

    ezpublish_rest.input.dispatcher:
        class: %ezpublish_rest.input.dispatcher.class%
        factory_service: ezpublish_rest.factory
        arguments:
            - @ezpublish_rest.input.parsing_dispatcher
            - []
            - @ezpublish_rest.request_parser
            - @ezpublish_rest.parser_tools
            - @ezpublish_rest.field_type_parser

    ezpublish_rest.input.parsing_dispatcher:
        class: %ezpublish_rest.input.parsing_dispatcher.class%

    ezpublish_rest.input.handler.json:
        class: %ezpublish_rest.input.handler.json.class%
        tags:
            - { name: ezpublish_rest.input.handler, format: json }

    ezpublish_rest.input.handler.xml:
        class: %ezpublish_rest.input.handler.xml.class%
        tags:
            - { name: ezpublish_rest.input.handler, format: xml }

    ezpublish_rest.templated_router:
        class: %ezpublish_rest.templated_router.class%
        parent: hautelook.router.template
        calls:
            - [ setOption, [ strict_requirements, ~ ] ]
