Completed
Pull Request — master (#369)
by Stefan
02:34
created

ServiceContainer::onPaymentService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 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 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\CategoryResolver\DefaultCategoryResolver;
19
use ShopwarePlugins\Connect\Components\FrontendQuery\FrontendQuery;
20
use ShopwarePlugins\Connect\Components\ImportService;
21
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamRepository;
22
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamService;
23
use Shopware\CustomModels\Connect\ProductStreamAttributeRepository;
24
use ShopwarePlugins\Connect\Components\RandomStringGenerator;
25
use ShopwarePlugins\Connect\Services\MenuService;
26
use ShopwarePlugins\Connect\Services\PaymentService;
27
use Shopware\Components\DependencyInjection\Container;
28
use ShopwarePlugins\Connect\Components\Config;
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
    /**
46
     * ServiceContainer constructor.
47
     * @param ModelManager $manager
48
     * @param Enlight_Components_Db_Adapter_Pdo_Mysql $db
49
     * @param Container $container
50
     */
51
    public function __construct(
52
        ModelManager $manager,
53
        Enlight_Components_Db_Adapter_Pdo_Mysql $db,
54
        Container $container
55
    ) {
56
        parent::__construct();
57
        $this->manager = $manager;
58
        $this->db = $db;
59
        $this->container = $container;
60
    }
61
62
    public function getSubscribedEvents()
63
    {
64
        return [
65
            'Enlight_Bootstrap_InitResource_swagconnect.product_stream_service' => 'onProductStreamService',
66
            'Enlight_Bootstrap_InitResource_swagconnect.payment_service' => 'onPaymentService',
67
            'Enlight_Bootstrap_InitResource_swagconnect.menu_service' => 'onMenuService',
68
            'Enlight_Bootstrap_InitResource_swagconnect.frontend_query' => 'onCreateFrontendQuery',
69
            'Enlight_Bootstrap_InitResource_swagconnect.rest_api_request' => 'onRestApiRequest',
70
            'Enlight_Bootstrap_InitResource_swagconnect.import_service' => 'onImportService',
71
            'Enlight_Bootstrap_InitResource_swagconnect.auto_category_reverter' => 'onAutoCategoryReverter',
72
            'Enlight_Bootstrap_InitResource_swagconnect.auto_category_resolver' => 'onAutoCategoryResolver',
73
            'Enlight_Bootstrap_InitResource_swagconnect.default_category_resolver' => 'onDefaultCategoryResolver',
74
        ];
75
    }
76
77
    /**
78
     * @return ProductStreamService
79
     */
80
    public function onProductStreamService()
81
    {
82
        /** @var ProductStreamAttributeRepository $streamAttrRepository */
83
        $streamAttrRepository = $this->manager->getRepository('Shopware\CustomModels\Connect\ProductStreamAttribute');
84
85
        return new ProductStreamService(
86
            new ProductStreamRepository($this->manager, $this->container->get('shopware_product_stream.repository')),
87
            $streamAttrRepository,
88
            new Config($this->manager),
89
            $this->container->get('shopware_search.product_search'),
90
            $this->container->get('shopware_storefront.context_service')
91
        );
92
    }
93
94
    /**
95
     * @return MenuService
96
     */
97
    public function onMenuService()
98
    {
99
        return new MenuService(
100
            $this->container->get('shopware_plugininstaller.plugin_manager'),
101
            $this->manager
102
        );
103
    }
104
105
    /**
106
     * @return PaymentService
107
     */
108
    public function onPaymentService()
109
    {
110
        return new PaymentService(
111
            $this->manager->getRepository('Shopware\Models\Payment\Payment'),
112
            new PaymentRepository($this->manager)
113
        );
114
    }
115
116
    public function onCreateFrontendQuery()
117
    {
118
        return new FrontendQuery($this->manager);
119
    }
120
121
    public function onRestApiRequest()
122
    {
123
        return new RestApiRequest(
124
            new Config($this->manager)
125
        );
126
    }
127
128
    /**
129
     * @return \ShopwarePlugins\Connect\Components\ImportService
130
     */
131
    public function onImportService()
132
    {
133
        return new ImportService(
134
            $this->manager,
135
            $this->container->get('multi_edit.product'),
136
            $this->manager->getRepository(CategoryModel::class),
137
            $this->manager->getRepository(ArticleModel::class),
138
            $this->manager->getRepository(RemoteCategory::class),
139
            $this->manager->getRepository(ProductToRemoteCategory::class),
140
            $this->container->get('swagconnect.auto_category_resolver'),
141
            new CategoryExtractor(
142
                $this->manager->getRepository(ConnectAttribute::class),
143
                $this->container->get('swagconnect.auto_category_resolver'),
144
                new PDO($this->db->getConnection()),
145
                new RandomStringGenerator(),
146
                $this->db
147
            )
148
        );
149
    }
150
151
    /**
152
     * @return \ShopwarePlugins\Connect\Components\AutoCategoryReverter
153
     */
154
    public function onAutoCategoryReverter()
155
    {
156
        return new \ShopwarePlugins\Connect\Components\AutoCategoryReverter(
157
            $this->container->get('swagconnect.import_service')
158
        );
159
    }
160
161
    /**
162
     * @return \ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver
163
     */
164
    public function onAutoCategoryResolver()
165
    {
166
        return new AutoCategoryResolver(
167
            $this->manager,
168
            $this->manager->getRepository(CategoryModel::class),
169
            $this->manager->getRepository(RemoteCategory::class),
170
            new Config($this->manager),
171
            $this->manager->getRepository(ProductToRemoteCategory::class)
172
        );
173
    }
174
175
    /**
176
     * @return \ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver
177
     */
178
    public function onDefaultCategoryResolver()
179
    {
180
        return new DefaultCategoryResolver(
181
            $this->manager,
182
            $this->manager->getRepository(RemoteCategory::class),
183
            $this->manager->getRepository(ProductToRemoteCategory::class)
184
        );
185
    }
186
}
187