@@ -27,14 +27,19 @@ trait FileManagerTrait
27
27
*/
28
28
protected $ webPath ;
29
29
30
+ /**
31
+ * @var bool
32
+ */
33
+ private $ booted = false ;
34
+
30
35
31
36
/**
32
37
* Initialize trait properties
33
38
*
34
39
* @param array $arrayFilepath Associative array containing the file path for each property of the managed entity.
35
40
* This array must also contain a 'root' and a 'web' path.
36
41
*/
37
- protected function initialize ($ arrayFilepath )
42
+ protected function initialize (array $ arrayFilepath )
38
43
{
39
44
if (!isset ($ arrayFilepath ['bundle.web ' ])) {
40
45
throw new \InvalidArgumentException ('$arrayFilepath must have a bundle.web key (even empty). ' );
@@ -52,6 +57,8 @@ protected function initialize($arrayFilepath)
52
57
$ this ->rootPath = $ classDir .'/../../../../../../../web ' .$ this ->webPath ;
53
58
}
54
59
$ this ->arrayFilepath = $ arrayFilepath ;
60
+
61
+ $ this ->booted = true ;
55
62
}
56
63
57
64
/**
@@ -65,6 +72,10 @@ protected function initialize($arrayFilepath)
65
72
*/
66
73
public function saveWithFiles (BaseEntityWithFile $ entity , $ callback = null )
67
74
{
75
+ if (!$ this ->booted ) {
76
+ throw new \Exception ('Manager has not been initialized ' );
77
+ }
78
+
68
79
$ managedProperties = $ this ->arrayFilepath ;
69
80
$ managedProperties = array_keys ($ managedProperties );
70
81
@@ -104,6 +115,10 @@ public function saveWithFiles(BaseEntityWithFile $entity, $callback = null)
104
115
*/
105
116
public function deleteWithFiles (BaseEntityWithFile $ entity )
106
117
{
118
+ if (!$ this ->booted ) {
119
+ throw new \Exception ('Manager has not been initialized ' );
120
+ }
121
+
107
122
$ managedProperties = $ this ->arrayFilepath ;
108
123
$ managedProperties = array_keys ($ managedProperties );
109
124
0 commit comments