services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false
        bind:
            # services
            $redis: '@snc_redis.default_client'
            $redisCache: '@snc_redis.cache_client'
            #$instantMailer: '@swiftmailer.mailer.instant'

            # params
            $awsMetadata: '%aws_metadata%'
            $databaseHost: '%database_host%'
            $databaseName: '%database_name%'
            $databaseUser: '%database_user%'
            $databasePassword: '%database_password%'
            $webDir: '%kernel.root_dir%/../web/'
            $metadataDir: '%packagist_metadata_dir%'

    Packagist\WebBundle\Command\:
        resource: '../../Command/*'
        tags: ['console.command']

    Packagist\WebBundle\Controller\:
        resource: '../../Controller/*'
        tags: ['controller.service_arguments']

    Packagist\WebBundle\Entity\:
        resource: '../../Entity/*Repository.php'

    Packagist\WebBundle\SecurityAdvisory\:
        resource: '../../SecurityAdvisory/*.php'

    packagist.twig.extension:
        public: true
        class: Packagist\WebBundle\Twig\PackagistExtension
        arguments: [ '@packagist.provider_manager', '@security.csrf.token_manager' ]
        tags:
            - { name: twig.extension }

    Graze\DogStatsD\Client:
        public: true

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

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

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

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

    guzzle_client:
        public: true
        class: GuzzleHttp\Client
        arguments: [{timeout: 3}]

    packagist.package_dumper:
        public: true
        class: Packagist\WebBundle\Package\SymlinkDumper
        arguments: [ '@doctrine', '@filesystem', '@router', '@snc_redis.default_client', '%kernel.root_dir%/../web/', '%packagist_metadata_dir%', '%packagist_dumper_compress%', '%aws_metadata%', '@Graze\DogStatsD\Client' ]

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

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

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

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

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

    packagist.oauth.registration_form:
        public: true
        factory: ['@form.factory', create]
        class: Symfony\Component\Form\Form
        arguments:
            - 'Packagist\WebBundle\Form\Type\OAuthRegistrationFormType'

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

    packagist.provider_manager:
        public: true
        class: Packagist\WebBundle\Model\ProviderManager

    packagist.favorite_manager:
        public: true
        class: Packagist\WebBundle\Model\FavoriteManager

    packagist.package_manager:
        public: true
        class: Packagist\WebBundle\Model\PackageManager
        arguments:
            - '@doctrine'
            - '@mailer'
            - '@swiftmailer.mailer.instant'
            - '@twig'
            - '@logger'
            - { from: '%mailer_from_email%', fromName: '%mailer_from_name%' }
            - '@packagist.provider_manager'
            - '@packagist.algolia.client'
            - '%algolia.index_name%'
            - '@github_user_migration_worker'
            - '%packagist_metadata_dir%'
            - '@snc_redis.default_client'

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

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

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

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

    packagist.algolia.client:
        public: true
        class: Algolia\AlgoliaSearch\SearchClient
        arguments: ['%algolia.app_id%', '%algolia.admin_key%']
        factory: ['Algolia\AlgoliaSearch\SearchClient', create]

    Packagist\WebBundle\Service\QueueWorker:
        arguments:
            - "@snc_redis.default_client"
            - "@doctrine"
            - "@logger"
            - 'package:updates': '@updater_worker'
              'githubuser:migrate': '@github_user_migration_worker'
              'security:advisory': '@security_advisory_worker'

    Packagist\WebBundle\Security\TwoFactorAuthManager:
        public: true
        class: Packagist\WebBundle\Security\TwoFactorAuthManager
        arguments:
            - '@doctrine'
            - '@mailer'
            - '@twig'
            - '@logger'
            - '@session.flash_bag'
            - { from: '%mailer_from_email%', fromName: '%mailer_from_name%' }

    Packagist\WebBundle\Security\TwoFactorAuthRateLimiter:
        class: Packagist\WebBundle\Security\TwoFactorAuthRateLimiter
        arguments:
            - "@snc_redis.cache_client"
        tags:
            - { name: kernel.event_subscriber }

    Packagist\WebBundle\SecurityAdvisory\FriendsOfPhpSecurityAdvisoriesSource:
        class: Packagist\WebBundle\SecurityAdvisory\FriendsOfPhpSecurityAdvisoriesSource
        arguments: ["@doctrine"]

    scheduler:
        public: true
        class: Packagist\WebBundle\Service\Scheduler
        arguments: ["@snc_redis.default_client", "@doctrine"]

    locker:
        public: true
        class: Packagist\WebBundle\Service\Locker
        arguments: ["@doctrine"]

    updater_worker:
        public: true
        class: Packagist\WebBundle\Service\UpdaterWorker
        arguments: ["@logger", "@doctrine", "@packagist.package_updater", "@locker", "@scheduler", "@packagist.package_manager", "@packagist.download_manager"]

    github_user_migration_worker:
        public: true
        class: Packagist\WebBundle\Service\GitHubUserMigrationWorker
        arguments: ["@logger", "@doctrine", "@guzzle_client", "%github.webhook_secret%"]

    security_advisory_worker:
        public: true
        class: Packagist\WebBundle\Service\SecurityAdvisoryWorker
        arguments:
            - "@locker"
            - "@logger"
            - "@doctrine"
            - 'FriendsOfPHP/security-advisories': "@Packagist\\WebBundle\\SecurityAdvisory\\FriendsOfPhpSecurityAdvisoriesSource"

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