services:
    wallabag_core.helper.detect_active_theme:
        class: Wallabag\CoreBundle\Helper\DetectActiveTheme
        arguments:
            - "@security.token_storage"
            - "%wallabag_core.theme%"

    # custom form type
    wallabag_core.form.type.config:
        class: Wallabag\CoreBundle\Form\Type\ConfigType
        arguments:
            - "%liip_theme.themes%"
            - "%wallabag_core.languages%"
        tags:
            - { name: form.type }

    wallabag_core.filter.type.entry:
        class: Wallabag\CoreBundle\Form\Type\EntryFilterType
        arguments:
            - "@wallabag_core.entry_repository"
            - "@security.token_storage"
        tags:
            - { name: form.type }

    wallabag_core.param_converter.username_feed_token_converter:
        class: Wallabag\CoreBundle\ParamConverter\UsernameFeedTokenConverter
        tags:
            - { name: request.param_converter, converter: username_feed_token_converter }
        arguments:
            - "@doctrine"

    wallabag_core.subscriber.table_prefix:
        class: Wallabag\CoreBundle\Event\Subscriber\TablePrefixSubscriber
        arguments:
            - "%database_table_prefix%"
        tags:
            - { name: doctrine.event_subscriber }

    wallabag_core.graby:
        class: Graby\Graby
        arguments:
            -
                error_message: '%wallabag_core.fetching_error_message%'
                error_message_title: '%wallabag_core.fetching_error_message_title%'
            - "@wallabag_core.http_client"
            - "@wallabag_core.graby.config_builder"
        calls:
            - [ setLogger, [ "@logger" ] ]
        tags:
            - { name: monolog.logger, channel: graby }

    wallabag_core.graby.config_builder:
        class: Graby\SiteConfig\ConfigBuilder
        arguments:
            - {}
            - "@logger"

    wallabag_core.http_client:
        alias: 'httplug.client.wallabag_core'

    wallabag_core.guzzle_authenticator.config_builder:
        class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder
        arguments:
            - "@wallabag_core.graby.config_builder"
            - "@security.token_storage"
            - "@wallabag_core.site_credential_repository"
            - '@logger'
        tags:
            - { name: monolog.logger, channel: graby }

    # service alias override
    bd_guzzle_site_authenticator.site_config_builder:
        alias: wallabag_core.guzzle_authenticator.config_builder

    wallabag_core.http_client_factory:
        class: Wallabag\CoreBundle\Helper\HttpClientFactory
        arguments:
            - "@wallabag_core.guzzle.cookie_jar"
            - '@=service(''craue_config'').get(''restricted_access'')'
            - '@logger'
        calls:
            - ["addSubscriber", ["@bd_guzzle_site_authenticator.authenticator_subscriber"]]

    wallabag_core.guzzle.cookie_jar:
        class: Wallabag\CoreBundle\Helper\FileCookieJar
        arguments:
            - "@logger"
            - "%kernel.cache_dir%/cookiejar.json"

    wallabag_core.content_proxy:
        class: Wallabag\CoreBundle\Helper\ContentProxy
        arguments:
            - "@wallabag_core.graby"
            - "@wallabag_core.rule_based_tagger"
            - "@wallabag_core.rule_based_ignore_origin_processor"
            - "@validator"
            - "@logger"
            - '%wallabag_core.fetching_error_message%'
            - '@=service(''craue_config'').get(''store_article_headers'')'

    wallabag_core.tags_assigner:
        class: Wallabag\CoreBundle\Helper\TagsAssigner
        arguments:
            - "@wallabag_core.tag_repository"

    wallabag_core.rule_based_tagger:
        class: Wallabag\CoreBundle\Helper\RuleBasedTagger
        arguments:
            - "@rulerz"
            - "@wallabag_core.tag_repository"
            - "@wallabag_core.entry_repository"
            - "@logger"

    wallabag_core.rule_based_ignore_origin_processor:
        class: Wallabag\CoreBundle\Helper\RuleBasedIgnoreOriginProcessor
        arguments:
            - "@rulerz"
            - "@logger"
            - "@wallabag_core.ignore_origin_instance_rule_repository"

    # repository as a service
    wallabag_core.entry_repository:
        class: Wallabag\CoreBundle\Repository\EntryRepository
        factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
        arguments:
            - WallabagCoreBundle:Entry

    wallabag_core.tag_repository:
        class: Wallabag\CoreBundle\Repository\TagRepository
        factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
        arguments:
            - WallabagCoreBundle:Tag

    wallabag_core.site_credential_repository:
        class: Wallabag\CoreBundle\Repository\SiteCredentialRepository
        factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
        arguments:
            - WallabagCoreBundle:SiteCredential
        calls:
            - [ setCrypto, [ "@wallabag_core.helper.crypto_proxy" ] ]

    wallabag_core.ignore_origin_instance_rule_repository:
        class: Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository
        factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
        arguments:
            - WallabagCoreBundle:IgnoreOriginInstanceRule

    wallabag_core.helper.entries_export:
        class: Wallabag\CoreBundle\Helper\EntriesExport
        arguments:
            - "@translator"
            - '%domain_name%'
            - web/img/appicon/apple-touch-icon-152.png

    wallabag.operator.array.matches:
        class: Wallabag\CoreBundle\Operator\PHP\Matches
        tags:
            - { name: rulerz.operator, target: native, operator: matches }

    wallabag.operator.doctrine.matches:
        class: Wallabag\CoreBundle\Operator\Doctrine\Matches
        tags:
            - { name: rulerz.operator, target: doctrine, operator: matches, inline: true }

    wallabag.operator.array.notmatches:
        class: Wallabag\CoreBundle\Operator\PHP\NotMatches
        tags:
            - { name: rulerz.operator, target: native, operator: notmatches }

    wallabag.operator.doctrine.notmatches:
        class: Wallabag\CoreBundle\Operator\Doctrine\NotMatches
        tags:
            - { name: rulerz.operator, target: doctrine, operator: notmatches, inline: true }

    wallabag.operator.array.pattern_matches:
        class: Wallabag\CoreBundle\Operator\PHP\PatternMatches
        tags:
            - { name: rulerz.operator, target: native, operator: "~" }

    wallabag_core.helper.redirect:
        class: Wallabag\CoreBundle\Helper\Redirect
        arguments:
            - "@router"
            - "@security.token_storage"

    wallabag_core.helper.prepare_pager_for_entries:
        class: Wallabag\CoreBundle\Helper\PreparePagerForEntries
        arguments:
            - "@security.token_storage"
            - "@router"

    wallabag_core.redis.client:
        class: Predis\Client
        arguments:
            -
                scheme: '%redis_scheme%'
                host: '%redis_host%'
                port: '%redis_port%'
                path: '%redis_path%'
                password: '%redis_password%'

    wallabag_core.exception_controller:
        class: Wallabag\CoreBundle\Controller\ExceptionController
        public: true
        arguments:
            - '@twig'
            - '%kernel.debug%'

    wallabag_core.subscriber.sqlite_cascade_delete:
        class: Wallabag\CoreBundle\Event\Subscriber\SQLiteCascadeDeleteSubscriber
        arguments:
            - "@doctrine"
        tags:
            - { name: doctrine.event_subscriber }

    wallabag_core.subscriber.download_images:
        class: Wallabag\CoreBundle\Event\Subscriber\DownloadImagesSubscriber
        arguments:
            - "@doctrine.orm.default_entity_manager"
            - "@wallabag_core.entry.download_images"
            - '@=service(''craue_config'').get(''download_images_enabled'')'
            - "@logger"
        tags:
            - { name: kernel.event_subscriber }

    wallabag_core.entry.download_images:
        class: Wallabag\CoreBundle\Helper\DownloadImages
        arguments:
            - "@wallabag_core.entry.download_images.client"
            - "%kernel.project_dir%/web/assets/images"
            - '%domain_name%'
            - "@logger"

    wallabag_core.entry.download_images.client:
        alias: 'httplug.client.wallabag_core.entry.download_images'

    wallabag_core.helper.crypto_proxy:
        class: Wallabag\CoreBundle\Helper\CryptoProxy
        arguments:
            - "%wallabag_core.site_credentials.encryption_key_path%"
            - "@logger"

    wallabag_core.command.clean_duplicates:
        class: Wallabag\CoreBundle\Command\CleanDuplicatesCommand
        tags: ['console.command']

    wallabag_core.command.export:
        class: Wallabag\CoreBundle\Command\ExportCommand
        tags: ['console.command']

    wallabag_core.command.install:
        class: Wallabag\CoreBundle\Command\InstallCommand
        tags: ['console.command']

    wallabag_core.command.list_user:
        class: Wallabag\CoreBundle\Command\ListUserCommand
        tags: ['console.command']

    wallabag_core.command.reload_entry:
        class: Wallabag\CoreBundle\Command\ReloadEntryCommand
        tags: ['console.command']

    wallabag_core.command.show_user:
        class: Wallabag\CoreBundle\Command\ShowUserCommand
        tags: ['console.command']

    wallabag_core.command.tag_all:
        class: Wallabag\CoreBundle\Command\TagAllCommand
        tags: ['console.command']
