parameters:
    jms_serializer.json_deserialization_visitor.class: Lemon\RestBundle\Serializer\LazyJsonDeserializationVisitor
services:
    lemon_doctrine:
        alias: doctrine

    lemon_rest.resource_controller:
        class: Lemon\RestBundle\Controller\ResourceController
        arguments:
            - @lemon_rest.handler
            - @lemon_rest.object_criteria_factory
            - @router

    lemon_rest.index_controller:
        class: Lemon\RestBundle\Controller\IndexController
        arguments:
            - @lemon_rest.format_negotiator
            - @jms_serializer
            - @lemon_rest.object_registry
            - @router

    lemon_rest.handler:
        class: Lemon\RestBundle\Request\Handler
        arguments:
            - @lemon_rest.object_manager_factory
            - @lemon_rest.object_envelope_factory
            - @lemon_rest.serializer.constructor_factory
            - @lemon_rest.format_negotiator
            - @logger

    lemon_rest.format_negotiator:
        class: Negotiation\FormatNegotiator

    lemon_rest.event_dispatcher:
        class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher
        arguments:
            - @service_container

    lemon_rest.event.processor_subscriber:
        class: Lemon\RestBundle\Event\ProcessorSubscriber
        arguments:
            - @lemon_rest.object_processor
        tags:
            - { name: lemon_rest.event_subscriber }

    lemon_rest.event.validator_subscriber:
        class: Lemon\RestBundle\Event\ValidatorSubscriber
        arguments:
            - @lemon_rest.object_validator
        tags:
            - { name: lemon_rest.event_subscriber }


    lemon_rest.object_manager_factory:
        class: Lemon\RestBundle\Object\ManagerFactory
        arguments:
            - @lemon_rest.object_registry
            - @lemon_doctrine
            - @lemon_rest.event_dispatcher

    lemon_rest.object_processor:
        class: Lemon\RestBundle\Object\Processor
        arguments:
            - @lemon_doctrine
            - @jms_serializer.metadata_factory

    lemon_rest.object_validator:
        class: Lemon\RestBundle\Object\Validator
        arguments:
            - @validator

    lemon_rest.object_registry:
        class: Lemon\RestBundle\Object\Registry

    lemon_rest.object_envelope_factory:
        class: Lemon\RestBundle\Object\Envelope\EnvelopeFactory
        arguments:
            - %lemon_rest_object_envelope_class%

    lemon_rest.object_criteria_factory:
        class: Lemon\RestBundle\Object\Criteria\CriteriaFactory
        arguments:
            - %lemon_rest_object_criteria_class%

    lemon_rest.serializer.id_collection.handler:
        class: Lemon\RestBundle\Serializer\IdCollectionHandler
        arguments:
            - @lemon_doctrine
        tags:
            - { name: jms_serializer.subscribing_handler }


    lemon_rest.serializer.collection:
        class: PhpCollection\Map
        scope: prototype

    lemon_rest.serializer.doctrine_object_constructor:
        class: JMS\Serializer\Construction\DoctrineObjectConstructor
        arguments:
            - @lemon_doctrine
            - @jms_serializer.unserialize_object_constructor

    lemon_rest.serializer.object_constructor:
        class: Lemon\RestBundle\Serializer\Construction\ToggleDoctrineObjectConstructor
        arguments:
            - @lemon_rest.serializer.doctrine_object_constructor
            - @jms_serializer.unserialize_object_constructor

    lemon_rest.serializer.constructor_factory:
        class: Lemon\RestBundle\Serializer\ConstructorFactory
        arguments:
            - @jms_serializer.metadata_factory
            - @jms_serializer.handler_registry
            - @lemon_rest.serializer.collection
            - @lemon_rest.serializer.collection
            - @jms_serializer.event_dispatcher
        calls:
            - [ addObjectConstructor, ['default', @lemon_rest.serializer.object_constructor] ]
            - [ addObjectConstructor, ['doctrine', @lemon_rest.serializer.doctrine_object_constructor] ]
