Completed
Push — master ( 159a25...a86692 )
by Stefan
03:09
created

ServiceContainer::onAutoCategoryResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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 Enlight\Event\SubscriberInterface;
11
use Shopware\Components\Model\ModelManager;
12
use Shopware\Connect\Gateway\PDO;
13
use Shopware\CustomModels\Connect\PaymentRepository;
14
use Shopware\CustomModels\Connect\ProductToRemoteCategory;
15
use Shopware\CustomModels\Connect\RemoteCategory;
16
use ShopwarePlugins\Connect\Components\Api\Request\RestApiRequest;
17
use ShopwarePlugins\Connect\Components\CategoryExtractor;
18
use ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver;
19
use ShopwarePlugins\Connect\Components\Config;
20
use ShopwarePlugins\Connect\Components\CategoryResolver\DefaultCategoryResolver;
21
use ShopwarePlugins\Connect\Components\FrontendQuery\FrontendQuery;
22
use ShopwarePlugins\Connect\Components\ImportService;
23
use ShopwarePlugins\Connect\Components\ProductStream\ProductSearch;
24
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamRepository;
25
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamService;
26
use Shopware\CustomModels\Connect\ProductStreamAttributeRepository;
27
use ShopwarePlugins\Connect\Components\RandomStringGenerator;
28
use ShopwarePlugins\Connect\Services\MenuService;
29
use ShopwarePlugins\Connect\Services\PaymentService;
30
use Shopware\Components\DependencyInjection\Container;
31
use Shopware\Models\Category\Category as CategoryModel;
32
use Shopware\Models\Article\Article as ArticleModel;
33
use Shopware\CustomModels\Connect\Attribute as ConnectAttribute;
34
use Enlight_Components_Db_Adapter_Pdo_Mysql;
35
use Shopware\CustomModels\Connect\ProductStreamAttribute;
36
37
class ServiceContainer implements SubscriberInterface
38
{
39
    /**
40
     * @var ModelManager
41
     */
42
    private $manager;
43
44
    /**
45
     * @var Enlight_Components_Db_Adapter_Pdo_Mysql
46
     */
47
    private $db;
48
49
    /**
50
     * @var Container
51
     */
52
    private $container;
53
54
    /** @var Config */
55
    private $config;
56
57
    /**
58
     * ServiceContainer constructor.
59
     * @param ModelManager $manager
60
     * @param Enlight_Components_Db_Adapter_Pdo_Mysql $db
61
     * @param Container $container
62
     * @param Config $config
63
     */
64
    public function __construct(
65
        ModelManager $manager,
66
        Enlight_Components_Db_Adapter_Pdo_Mysql $db,
67
        Container $container,
68
        Config $config
69
    ) {
70
        $this->manager = $manager;
71
        $this->db = $db;
72
        $this->container = $container;
73
        $this->config = $config;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public static function getSubscribedEvents()
80
    {
81
        return [
82
            'Enlight_Bootstrap_InitResource_swagconnect.product_stream_service' => 'onProductStreamService',
83
            'Enlight_Bootstrap_InitResource_swagconnect.product_search' => 'onProductSearch',
84
            'Enlight_Bootstrap_InitResource_swagconnect.payment_service' => 'onPaymentService',
85
            'Enlight_Bootstrap_InitResource_swagconnect.menu_service' => 'onMenuService',
86
            'Enlight_Bootstrap_InitResource_swagconnect.frontend_query' => 'onCreateFrontendQuery',
87
            'Enlight_Bootstrap_InitResource_swagconnect.rest_api_request' => 'onRestApiRequest',
88
            'Enlight_Bootstrap_InitResource_swagconnect.import_service' => 'onImportService',
89
            'Enlight_Bootstrap_InitResource_swagconnect.auto_category_reverter' => 'onAutoCategoryReverter',
90
            'Enlight_Bootstrap_InitResource_swagconnect.auto_category_resolver' => 'onAutoCategoryResolver',
91
            'Enlight_Bootstrap_InitResource_swagconnect.default_category_resolver' => 'onDefaultCategoryResolver',
92
        ];
93
    }
94
95
    /**
96
     * @return ProductStreamService
97
     */
98
    public function onProductStreamService()
99
    {
100
        /** @var ProductStreamAttributeRepository $streamAttrRepository */
101
        $streamAttrRepository = $this->manager->getRepository(ProductStreamAttribute::class);
102
103
        return new ProductStreamService(
104
            new ProductStreamRepository($this->manager, $this->container->get('shopware_product_stream.repository')),
105
            $streamAttrRepository,
106
            $this->config
107
        );
108
    }
109
110
    /**
111
     * @return ProductSearch
112
     */
113
    public function onProductSearch()
114
    {
115
        return new ProductSearch(
116
            $this->container->get('shopware_product_stream.repository'),
117
            $this->config,
118
            $this->container->get('shopware_search.product_search'),
119
            $this->container->get('shopware_storefront.context_service')
120
        );
121
    }
122
123
    /**
124
     * @return MenuService
125
     */
126
    public function onMenuService()
127
    {
128
        return new MenuService(
129
            $this->container->get('shopware_plugininstaller.plugin_manager'),
130
            $this->manager
131
        );
132
    }
133
134
    /**
135
     * @return PaymentService
136
     */
137
    public function onPaymentService()
138
    {
139
        return new PaymentService(
140
            $this->manager->getRepository('Shopware\Models\Payment\Payment'),
141
            new PaymentRepository($this->manager)
142
        );
143
    }
144
145
    /**
146
     * @return FrontendQuery
147
     */
148
    public function onCreateFrontendQuery()
149
    {
150
        return new FrontendQuery($this->manager);
151
    }
152
153
    /**
154
     * @return RestApiRequest
155
     */
156
    public function onRestApiRequest()
157
    {
158
        return new RestApiRequest($this->config);
159
    }
160
161
    /**
162
     * @return \ShopwarePlugins\Connect\Components\ImportService
163
     */
164
    public function onImportService()
165
    {
166
        return new ImportService(
167
            $this->manager,
168
            $this->container->get('multi_edit.product'),
169
            $this->manager->getRepository(CategoryModel::class),
170
            $this->manager->getRepository(ArticleModel::class),
171
            $this->manager->getRepository(RemoteCategory::class),
172
            $this->manager->getRepository(ProductToRemoteCategory::class),
173
            $this->container->get('swagconnect.auto_category_resolver'),
174
            new CategoryExtractor(
175
                $this->manager->getRepository(ConnectAttribute::class),
176
                $this->container->get('swagconnect.auto_category_resolver'),
177
                new PDO($this->db->getConnection()),
178
                new RandomStringGenerator(),
179
                $this->db
180
            ),
181
            $this->container->get('CategoryDenormalization'),
182
            $this->container->get('shopware_attribute.data_persister')
183
        );
184
    }
185
186
    /**
187
     * @return \ShopwarePlugins\Connect\Components\AutoCategoryReverter
188
     */
189
    public function onAutoCategoryReverter()
190
    {
191
        return new \ShopwarePlugins\Connect\Components\AutoCategoryReverter(
192
            $this->container->get('swagconnect.import_service')
193
        );
194
    }
195
196
    /**
197
     * @return \ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver
198
     */
199
    public function onAutoCategoryResolver()
200
    {
201
        return new AutoCategoryResolver(
202
            $this->manager,
203
            $this->manager->getRepository(CategoryModel::class),
204
            $this->manager->getRepository(RemoteCategory::class),
205
            $this->config,
206
            $this->manager->getRepository(ProductToRemoteCategory::class)
207
        );
208
    }
209
210
    /**
211
     * @return \ShopwarePlugins\Connect\Components\CategoryResolver\DefaultCategoryResolver
212
     */
213
    public function onDefaultCategoryResolver()
214
    {
215
        return new DefaultCategoryResolver(
216
            $this->manager,
217
            $this->manager->getRepository(RemoteCategory::class),
218
            $this->manager->getRepository(ProductToRemoteCategory::class),
219
            $this->manager->getRepository(CategoryModel::class)
220
        );
221
    }
222
}
223