Completed
Push — extensions-support ( 729df1...1e50b0 )
by Guido
03:48
created

GedmoExtensions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 87
wmc 4
lcom 1
cbo 3
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerAll() 0 4 1
A registerAbstract() 0 4 1
A register() 0 11 2
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Extensions;
4
5
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
6
use LaravelDoctrine\Fluent\FluentDriver;
7
8
class GedmoExtensions
9
{
10
    /**
11
     * Abstract Gedmo classes.
12
     *
13
     * @var string[]
14
     */
15
    protected static $abstract = [
16
        Gedmo\Mappings\Loggable\AbstractLogEntryMapping::class,
17
        Gedmo\Mappings\Translatable\AbstractPersonalTranslationMapping::class,
18
        Gedmo\Mappings\Translatable\AbstractTranslationMapping::class,
19
        Gedmo\Mappings\Tree\AbstractClosureMapping::class,
20
    ];
21
22
    /**
23
     * Concrete Gedmo classes.
24
     *
25
     * @var string[]
26
     */
27
    protected static $concrete = [
28
        Gedmo\Mappings\Loggable\LogEntryMapping::class,
29
        Gedmo\Mappings\Translatable\TranslationMapping::class,
30
    ];
31
32
    /**
33
     * @var Extension[]
34
     */
35
    protected static $extensions = [
36
        Gedmo\Blameable::class,
37
        Gedmo\IpTraceable::class,
38
        Gedmo\Loggable::class,
39
        Gedmo\Sluggable::class,
40
        Gedmo\Softdeleteable::class,
41
        Gedmo\Sortable::class,
42
        Gedmo\Timestampable::class,
43
        Gedmo\Translatable::class,
44
        Gedmo\Tree::class,
45
        Gedmo\Uploadable::class,
46
    ];
47
48
    /**
49
     * Register all Gedmo classes on Fluent.
50
     *
51
     * @param MappingDriverChain $driverChain
52
     *
53
     * @return void
54
     * @see \Gedmo\DoctrineExtensions::registerMappingIntoDriverChainORM
55
     */
56 41
    public static function registerAll(MappingDriverChain $driverChain)
57
    {
58 41
        self::register($driverChain, array_merge(self::$abstract, self::$concrete));
59 41
    }
60
61
    /**
62
     * Register only abstract Gedmo classes on Fluent.
63
     *
64
     * @param MappingDriverChain $driverChain
65
     *
66
     * @return void
67
     * @see \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM
68
     */
69 39
    public static function registerAbstract(MappingDriverChain $driverChain)
70
    {
71 39
        self::register($driverChain, self::$abstract);
72 39
    }
73
74
    /**
75
     * Register a new FluentDriver for the Gedmo namespace on the given chain.
76
     * Adds all extensions as macros.
77
     *
78
     * @param MappingDriverChain $driverChain
79
     * @param string[]           $mappings
80
     *
81
     * @return void
82
     */
83 80
    protected static function register(MappingDriverChain $driverChain, array $mappings)
84
    {
85 80
        $driverChain->addDriver(
86 80
            new FluentDriver($mappings),
87
            'Gedmo'
88 80
        );
89
90 80
        foreach (self::$extensions as $extension) {
91 80
            $extension::enable();
92 80
        }
93 80
    }
94
}
95