services:
    packagist.twig.extension:
        class: Packagist\WebBundle\Twig\PackagistExtension
        arguments: [ '@packagist.provider_manager' ]
        tags:
            - { name: twig.extension }

    twig.extension.text:
        class: Twig_Extensions_Extension_Text
        tags:
            - { name: twig.extension }

    packagist.cache_listener:
        class: Packagist\WebBundle\EventListener\CacheListener
        tags:
            - { name: kernel.event_listener, event: kernel.response, method: onResponse }

    packagist.logged_in_user_cannot_register_listener:
        class: Packagist\WebBundle\EventListener\LoggedInUserCannotRegisterListener
        arguments:
            - '@security.authorization_checker'
            - '@router'
        tags:
            - { name: kernel.event_subscriber }

    packagist.registration_listener:
        class: Packagist\WebBundle\EventListener\RegistrationListener
        arguments: [ '@fos_user.util.token_generator' ]
        tags:
            - { name: kernel.event_subscriber }

    packagist.package_dumper:
        class: Packagist\WebBundle\Package\SymlinkDumper
        arguments: [ '@doctrine', '@filesystem', '@router', '%kernel.root_dir%/../web/', '%packagist_metadata_dir%', '%packagist_dumper_compress%' ]

    packagist.user_provider:
        class: Packagist\WebBundle\Security\Provider\UserProvider
        public: false
        arguments: ['@fos_user.user_manager', '@fos_user.user_provider.username_email']

    packagist.user_repository:
        class: Packagist\WebBundle\Entity\UserRepository
        factory: ['@doctrine', getRepository]
        arguments: ['PackagistWebBundle:User']

    packagist.package_repository:
        class: Packagist\WebBundle\Entity\PackageRepository
        factory: ['@doctrine', getRepository]
        arguments: ['PackagistWebBundle:Package']

    packagist.version_repository:
        class: Packagist\WebBundle\Entity\VersionRepository
        factory: ['@doctrine', getRepository]
        arguments: ['PackagistWebBundle:Version']
        calls:
            - [ setRedis, [ '@snc_redis.cache_client' ]]

    packagist.package_updater:
        class: Packagist\WebBundle\Package\Updater
        arguments: ['@doctrine']

    fos_user.util.user_manipulator:
        class: Packagist\WebBundle\Util\UserManipulator
        arguments:
            - '@fos_user.user_manager'
            - '@fos_user.util.token_generator'
            - '@event_dispatcher'
            - '@service_container'

    packagist.oauth.registration_form_handler:
        class: Packagist\WebBundle\Form\Handler\OAuthRegistrationFormHandler
        arguments: ['@fos_user.user_manager', '@fos_user.util.token_generator']

    packagist.oauth.registration_form_type:
        class: Packagist\WebBundle\Form\Type\OAuthRegistrationFormType
        tags:
            - { name: form.type, alias: packagist_oauth_user_registration }

    packagist.oauth.registration_form:
        factory: ['@form.factory', create]
        class: Symfony\Component\Form\Form
        arguments:
            - 'packagist_oauth_user_registration'

    packagist.download_manager:
        class: Packagist\WebBundle\Model\DownloadManager
        arguments:
            - '@snc_redis.default_client'

    packagist.provider_manager:
        class: Packagist\WebBundle\Model\ProviderManager
        arguments:
            - '@snc_redis.default_client'
            - '@packagist.package_repository'

    packagist.favorite_manager:
        class: Packagist\WebBundle\Model\FavoriteManager
        arguments:
            - '@snc_redis.default_client'
            - '@packagist.package_repository'
            - '@packagist.user_repository'

    packagist.package_manager:
        class: Packagist\WebBundle\Model\PackageManager
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@mailer'
            - '@twig'
            - '@logger'
            - { from: '%mailer_from_email%', fromName: '%mailer_from_name%' }

    packagist.profile.form.type:
        class: Packagist\WebBundle\Form\Type\ProfileFormType
        arguments: ['%fos_user.model.user.class%']
        tags:
            - { name: form.type, alias: packagist_user_profile }

    packagist.menu_builder:
        class: Packagist\WebBundle\Menu\MenuBuilder
        arguments: ['@knp_menu.factory', '@security.token_storage', '@translator']

    packagist.menu.user:
        class: Knp\Menu\MenuItem
        factory: ['@packagist.menu_builder', createUserMenu]
        tags:
            - { name: knp_menu.menu, alias: user_menu }

    packagist.menu.profile:
        class: Knp\Menu\MenuItem
        factory: ['@packagist.menu_builder', createProfileMenu]
        tags:
            - { name: knp_menu.menu, alias: profile_menu }

parameters:
    security.exception_listener.class: Packagist\WebBundle\Security\ExceptionListener
