Skip to content

Commit bcd6ad3

Browse files
committed
Merge pull request #56 from jdecool/manager-initialization-detect
Manager initialization detection
2 parents 4c444ec + 67c6da8 commit bcd6ad3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Manager/Traits/FileManagerTrait.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ trait FileManagerTrait
2727
*/
2828
protected $webPath;
2929

30+
/**
31+
* @var bool
32+
*/
33+
private $booted = false;
34+
3035

3136
/**
3237
* Initialize trait properties
3338
*
3439
* @param array $arrayFilepath Associative array containing the file path for each property of the managed entity.
3540
* This array must also contain a 'root' and a 'web' path.
3641
*/
37-
protected function initialize($arrayFilepath)
42+
protected function initialize(array $arrayFilepath)
3843
{
3944
if (!isset($arrayFilepath['bundle.web'])) {
4045
throw new \InvalidArgumentException('$arrayFilepath must have a bundle.web key (even empty).');
@@ -52,6 +57,8 @@ protected function initialize($arrayFilepath)
5257
$this->rootPath = $classDir.'/../../../../../../../web'.$this->webPath;
5358
}
5459
$this->arrayFilepath = $arrayFilepath;
60+
61+
$this->booted = true;
5562
}
5663

5764
/**
@@ -65,6 +72,10 @@ protected function initialize($arrayFilepath)
6572
*/
6673
public function saveWithFiles(BaseEntityWithFile $entity, $callback = null)
6774
{
75+
if (!$this->booted) {
76+
throw new \Exception('Manager has not been initialized');
77+
}
78+
6879
$managedProperties = $this->arrayFilepath;
6980
$managedProperties = array_keys($managedProperties);
7081

@@ -104,6 +115,10 @@ public function saveWithFiles(BaseEntityWithFile $entity, $callback = null)
104115
*/
105116
public function deleteWithFiles(BaseEntityWithFile $entity)
106117
{
118+
if (!$this->booted) {
119+
throw new \Exception('Manager has not been initialized');
120+
}
121+
107122
$managedProperties = $this->arrayFilepath;
108123
$managedProperties = array_keys($managedProperties);
109124

Manager/Traits/ImageManagerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait ImageManagerTrait
3737
* @param array $imageFormatDefinition Associative array to define image properties which be stored on filesystem
3838
* @param array $imageFormatChoices Associative array to apply some format definitions to an entity property
3939
*/
40-
protected function initialize($arrayFilepath, $imageFormatDefinition, $imageFormatChoices)
40+
protected function initialize(array $arrayFilepath, $imageFormatDefinition, $imageFormatChoices)
4141
{
4242
$this->parentInitialize($arrayFilepath);
4343

0 commit comments

Comments
 (0)