1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Configuration.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license https://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
8
|
|
|
* @package iPublikuj:DoctrineBlameable! |
9
|
|
|
* @subpackage common |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 02.01.16 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\DoctrineBlameable; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Doctrine blameable extension configuration storage |
23
|
|
|
* Store basic extension settings |
24
|
|
|
* |
25
|
|
|
* @package iPublikuj:DoctrineBlameable! |
26
|
|
|
* @subpackage common |
27
|
|
|
* |
28
|
|
|
* @author Adam Kadlec <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
final class Configuration |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Implement nette smart magic |
34
|
|
|
*/ |
35
|
|
|
use Nette\SmartObject; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Flag if use lazy association or not |
39
|
|
|
* |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
public $lazyAssociation = FALSE; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* User entity name |
46
|
|
|
* |
47
|
|
|
* @var string|NULL |
48
|
|
|
*/ |
49
|
|
|
public $userEntity; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Automatically map filed if not set |
53
|
|
|
* |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
public $autoMapField = TRUE; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string|NULL $userEntity |
60
|
|
|
* @param bool $lazyAssociation |
61
|
|
|
* @param bool $autoMapField |
62
|
|
|
*/ |
63
|
|
|
public function __construct(string $userEntity = NULL, bool $lazyAssociation = FALSE, bool $autoMapField = FALSE) |
64
|
|
|
{ |
65
|
|
|
$this->userEntity = $userEntity; |
66
|
|
|
$this->lazyAssociation = $lazyAssociation; |
67
|
|
|
$this->autoMapField = $autoMapField; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function automapWithAssociation() : bool |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
if ($this->userEntity !== NULL && class_exists($this->userEntity) && $this->autoMapField === TRUE) { |
76
|
|
|
return TRUE; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return FALSE; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function automapWithField() : bool |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
if ($this->userEntity === NULL && $this->autoMapField === TRUE) { |
88
|
|
|
return TRUE; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return FALSE; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
|
|
public function useLazyAssociation() : bool |
98
|
|
|
{ |
99
|
|
|
return $this->lazyAssociation === TRUE; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.