|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelDoctrine\Fluent\Extensions\Gedmo; |
|
4
|
|
|
|
|
5
|
|
|
use Gedmo\Loggable\Mapping\Driver\Fluent; |
|
6
|
|
|
use LaravelDoctrine\Fluent\Buildable; |
|
7
|
|
|
use LaravelDoctrine\Fluent\Builders\Entity; |
|
8
|
|
|
use LaravelDoctrine\Fluent\Builders\Field; |
|
9
|
|
|
use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata; |
|
10
|
|
|
use LaravelDoctrine\Fluent\Relations\ManyToOne; |
|
11
|
|
|
use LaravelDoctrine\Fluent\Relations\OneToOne; |
|
12
|
|
|
|
|
13
|
|
|
class Loggable implements Buildable |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ExtensibleClassMetadata |
|
17
|
|
|
*/ |
|
18
|
|
|
private $classMetadata; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string|null |
|
22
|
|
|
*/ |
|
23
|
|
|
private $logEntry; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param ExtensibleClassMetadata $classMetadata |
|
27
|
|
|
* @param string|null $logEntry |
|
28
|
|
|
*/ |
|
29
|
7 |
|
public function __construct(ExtensibleClassMetadata $classMetadata, $logEntry = null) |
|
30
|
|
|
{ |
|
31
|
7 |
|
$this->classMetadata = $classMetadata; |
|
32
|
7 |
|
$this->logEntry = $logEntry; |
|
33
|
7 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
4 |
|
public static function enable() |
|
39
|
|
|
{ |
|
40
|
|
|
Entity::macro('loggable', function (Entity $builder, $logEntry = null) { |
|
41
|
1 |
|
$loggable = new static($builder->getClassMetadata(), $logEntry); |
|
|
|
|
|
|
42
|
1 |
|
$loggable->build(); |
|
43
|
4 |
|
}); |
|
44
|
|
|
|
|
45
|
|
|
Field::macro('versioned', function (Field $builder) { |
|
46
|
1 |
|
return new Versioned($builder->getClassMetadata(), $builder->getName()); |
|
47
|
4 |
|
}); |
|
48
|
|
|
|
|
49
|
|
|
ManyToOne::macro('versioned', function (ManyToOne $builder) { |
|
50
|
1 |
|
return new Versioned($builder->getClassMetadata(), $builder->getRelation()); |
|
|
|
|
|
|
51
|
4 |
|
}); |
|
52
|
|
|
|
|
53
|
4 |
|
OneToOne::macro('versioned', function (OneToOne $builder) { |
|
54
|
1 |
|
return new Versioned($builder->getClassMetadata(), $builder->getRelation()); |
|
|
|
|
|
|
55
|
4 |
|
}); |
|
56
|
4 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Execute the build process |
|
60
|
|
|
*/ |
|
61
|
4 |
|
public function build() |
|
62
|
|
|
{ |
|
63
|
|
|
$config = [ |
|
64
|
4 |
|
'loggable' => true, |
|
65
|
4 |
|
]; |
|
66
|
|
|
|
|
67
|
4 |
|
if ($this->logEntry !== null) { |
|
68
|
1 |
|
$config['logEntryClass'] = $this->logEntry; |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
4 |
|
$this->classMetadata->addExtension(Fluent::EXTENSION_NAME, array_merge( |
|
72
|
4 |
|
$this->classMetadata->getExtension(Fluent::EXTENSION_NAME), |
|
73
|
|
|
$config |
|
74
|
4 |
|
)); |
|
75
|
4 |
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.