Completed
Push — master ( c85fb7...4b358a )
by Adam
12:10
created

ProductMappingEnhancer::getExtraTraitClass()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <adam@wellcommerce.org>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\FeatureBundle\Enhancer;
14
15
use WellCommerce\Bundle\CatalogBundle\Entity\Extra\ProductExtraTrait;
16
use WellCommerce\Bundle\CatalogBundle\Entity\Product;
17
use WellCommerce\Bundle\FeatureBundle\Entity\FeatureSet;
18
use WellCommerce\Bundle\FeatureBundle\Entity\ProductFeature;
19
use WellCommerce\Component\DoctrineEnhancer\AbstractMappingEnhancer;
20
use WellCommerce\Component\DoctrineEnhancer\Definition\ManyToOneDefinition;
21
use WellCommerce\Component\DoctrineEnhancer\Definition\MappingDefinitionCollection;
22
use WellCommerce\Component\DoctrineEnhancer\Definition\OneToManyDefinition;
23
24
/**
25
 * Class ProductMappingEnhancer
26
 *
27
 * @author  Adam Piotrowski <adam@wellcommerce.org>
28
 */
29
final class ProductMappingEnhancer extends AbstractMappingEnhancer
30
{
31
    protected function configureMappingDefinition(MappingDefinitionCollection $collection)
32
    {
33
        $collection->add(new ManyToOneDefinition([
34
            'fieldName'    => 'featureSet',
35
            'joinColumns'  => [
36
                [
37
                    'name'                 => 'feature_set_id',
38
                    'referencedColumnName' => 'id',
39
                    'onDelete'             => 'SET NULL',
40
                ],
41
            ],
42
            'targetEntity' => FeatureSet::class,
43
        ]));
44
        
45
        $collection->add(new OneToManyDefinition([
46
            'fieldName'     => 'features',
47
            'targetEntity'  => ProductFeature::class,
48
            'mappedBy'      => 'product',
49
            'orphanRemoval' => true,
50
        ]));
51
    }
52
    
53
    public function getSupportedEntityClass(): string
54
    {
55
        return Product::class;
56
    }
57
    
58
    public function getExtraTraitClass(): string
59
    {
60
        return ProductExtraTrait::class;
61
    }
62
}
63