Completed
Push — master ( 675c4a...6ab08a )
by Stefan
12s
created

ServiceContainer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 4
dl 0
loc 12
rs 9.4285
1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace ShopwarePlugins\Connect\Subscribers;
9
10
use Shopware\Components\Model\ModelManager;
11
use Shopware\Connect\Gateway\PDO;
12
use Shopware\CustomModels\Connect\PaymentRepository;
13
use Shopware\CustomModels\Connect\ProductToRemoteCategory;
14
use Shopware\CustomModels\Connect\RemoteCategory;
15
use ShopwarePlugins\Connect\Components\Api\Request\RestApiRequest;
16
use ShopwarePlugins\Connect\Components\CategoryExtractor;
17
use ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver;
18
use ShopwarePlugins\Connect\Components\Config;
19
use ShopwarePlugins\Connect\Components\CategoryResolver\DefaultCategoryResolver;
20
use ShopwarePlugins\Connect\Components\FrontendQuery\FrontendQuery;
21
use ShopwarePlugins\Connect\Components\ImportService;
22
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamRepository;
23
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamService;
24
use Shopware\CustomModels\Connect\ProductStreamAttributeRepository;
25
use ShopwarePlugins\Connect\Components\RandomStringGenerator;
26
use ShopwarePlugins\Connect\Services\MenuService;
27
use ShopwarePlugins\Connect\Services\PaymentService;
28
use Shopware\Components\DependencyInjection\Container;
29
use Shopware\Models\Category\Category as CategoryModel;
30
use Shopware\Models\Article\Article as ArticleModel;
31
use Shopware\CustomModels\Connect\Attribute as ConnectAttribute;
32
use Enlight_Components_Db_Adapter_Pdo_Mysql;
33
34
class ServiceContainer extends BaseSubscriber
35
{
36
    /** @var ModelManager */
37
    private $manager;
38
39
    /** @var Enlight_Components_Db_Adapter_Pdo_Mysql */
40
    private $db;
41
42
    /** @var Container */
43
    private $container;
44
45
    /** @var Config */
46
    private $config;
47
48
    /**
49
     * ServiceContainer constructor.
50
     * @param ModelManager $manager
51
     * @param Enlight_Components_Db_Adapter_Pdo_Mysql $db
52
     * @param Container $container
53
     * @param Config $config
54
     */
55
    public function __construct(
56
        ModelManager $manager,
57
        Enlight_Components_Db_Adapter_Pdo_Mysql $db,
58
        Container $container,
59
        Config $config
60
    ) {
61
        parent::__construct();
62
        $this->manager = $manager;
63
        $this->db = $db;
64
        $this->container = $container;
65
        $this->config = $config;
66
    }
67
68
    public function getSubscribedEvents()
69
    {
70
        return [
71
            'Enlight_Bootstrap_InitResource_swagconnect.product_stream_service' => 'onProductStreamService',
72
            'Enlight_Bootstrap_InitResource_swagconnect.payment_service' => 'onPaymentService',
73
            'Enlight_Bootstrap_InitResource_swagconnect.menu_service' => 'onMenuService',
74
            'Enlight_Bootstrap_InitResource_swagconnect.frontend_query' => 'onCreateFrontendQuery',
75
            'Enlight_Bootstrap_InitResource_swagconnect.rest_api_request' => 'onRestApiRequest',
76
            'Enlight_Bootstrap_InitResource_swagconnect.import_service' => 'onImportService',
77
            'Enlight_Bootstrap_InitResource_swagconnect.auto_category_reverter' => 'onAutoCategoryReverter',
78
            'Enlight_Bootstrap_InitResource_swagconnect.auto_category_resolver' => 'onAutoCategoryResolver',
79
            'Enlight_Bootstrap_InitResource_swagconnect.default_category_resolver' => 'onDefaultCategoryResolver',
80
        ];
81
    }
82
83
    /**
84
     * @return ProductStreamService
85
     */
86
    public function onProductStreamService()
87
    {
88
        /** @var ProductStreamAttributeRepository $streamAttrRepository */
89
        $streamAttrRepository = $this->manager->getRepository('Shopware\CustomModels\Connect\ProductStreamAttribute');
90
91
        return new ProductStreamService(
92
            new ProductStreamRepository($this->manager, $this->container->get('shopware_product_stream.repository')),
93
            $streamAttrRepository,
94
            $this->config,
95
            $this->container->get('shopware_search.product_search'),
96
            $this->container->get('shopware_storefront.context_service')
97
        );
98
    }
99
100
    /**
101
     * @return MenuService
102
     */
103
    public function onMenuService()
104
    {
105
        return new MenuService(
106
            $this->container->get('shopware_plugininstaller.plugin_manager'),
107
            $this->manager
108
        );
109
    }
110
111
    /**
112
     * @return PaymentService
113
     */
114
    public function onPaymentService()
115
    {
116
        return new PaymentService(
117
            $this->manager->getRepository('Shopware\Models\Payment\Payment'),
118
            new PaymentRepository($this->manager)
119
        );
120
    }
121
122
    public function onCreateFrontendQuery()
123
    {
124
        return new FrontendQuery($this->manager);
125
    }
126
127
    public function onRestApiRequest()
128
    {
129
        return new RestApiRequest($this->config);
130
    }
131
132
    /**
133
     * @return \ShopwarePlugins\Connect\Components\ImportService
134
     */
135
    public function onImportService()
136
    {
137
        return new ImportService(
138
            $this->manager,
139
            $this->container->get('multi_edit.product'),
140
            $this->manager->getRepository(CategoryModel::class),
141
            $this->manager->getRepository(ArticleModel::class),
142
            $this->manager->getRepository(RemoteCategory::class),
143
            $this->manager->getRepository(ProductToRemoteCategory::class),
144
            $this->container->get('swagconnect.auto_category_resolver'),
145
            new CategoryExtractor(
146
                $this->manager->getRepository(ConnectAttribute::class),
147
                $this->container->get('swagconnect.auto_category_resolver'),
148
                new PDO($this->db->getConnection()),
149
                new RandomStringGenerator(),
150
                $this->db
151
            )
152
        );
153
    }
154
155
    /**
156
     * @return \ShopwarePlugins\Connect\Components\AutoCategoryReverter
157
     */
158
    public function onAutoCategoryReverter()
159
    {
160
        return new \ShopwarePlugins\Connect\Components\AutoCategoryReverter(
161
            $this->container->get('swagconnect.import_service')
162
        );
163
    }
164
165
    /**
166
     * @return \ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver
167
     */
168
    public function onAutoCategoryResolver()
169
    {
170
        return new AutoCategoryResolver(
171
            $this->manager,
172
            $this->manager->getRepository(CategoryModel::class),
173
            $this->manager->getRepository(RemoteCategory::class),
174
            $this->config,
175
            $this->manager->getRepository(ProductToRemoteCategory::class)
176
        );
177
    }
178
179
    /**
180
     * @return \ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver
181
     */
182
    public function onDefaultCategoryResolver()
183
    {
184
        return new DefaultCategoryResolver(
185
            $this->manager,
186
            $this->manager->getRepository(RemoteCategory::class),
187
            $this->manager->getRepository(ProductToRemoteCategory::class)
188
        );
189
    }
190
}
191