@@ -60,7 +60,10 @@ public function buildPreloadFile(): array
60
60
61
61
$ compiledPreloadFile = $ compiler ->compile ($ this ->compilerConfig , $ classes );
62
62
63
- file_put_contents ($ this ->preloadFilePath , $ compiledPreloadFile );
63
+ $ result = file_put_contents ($ this ->preloadFilePath , $ compiledPreloadFile );
64
+ if ($ result === false ) {
65
+ throw new ContainerException ("File ' $ this ->preloadFilePath ' cannot be written " );
66
+ }
64
67
65
68
return $ classes ;
66
69
}
@@ -81,11 +84,18 @@ public function buildContainer(array $preloadedClasses): void
81
84
$ this ->createDirectory ($ definitionDirectory );
82
85
83
86
foreach ($ compiledContainerFiles ["definitions " ] as $ filename => $ content ) {
84
- file_put_contents ($ definitionDirectory . DIRECTORY_SEPARATOR . $ filename , $ content );
87
+ $ file = $ definitionDirectory . DIRECTORY_SEPARATOR . $ filename ;
88
+ $ result = file_put_contents ($ file , $ content );
89
+ if ($ result === false ) {
90
+ throw new ContainerException ("File '$ $ file' cannot be written " );
91
+ }
85
92
}
86
93
}
87
94
88
- file_put_contents ($ this ->containerPath , $ compiledContainerFiles ["container " ]);
95
+ $ result = file_put_contents ($ this ->containerPath , $ compiledContainerFiles ["container " ]);
96
+ if ($ result === false ) {
97
+ throw new ContainerException ("File ' $ this ->containerPath ' cannot be written " );
98
+ }
89
99
}
90
100
91
101
private function deleteDirectory (string $ directory ): void
@@ -100,9 +110,15 @@ private function deleteDirectory(string $directory): void
100
110
foreach ($ files as $ file ) {
101
111
assert ($ file instanceof SplFileInfo);
102
112
if ($ file ->isDir ()) {
103
- rmdir ($ file ->getRealPath ());
113
+ $ result = rmdir ($ file ->getRealPath ());
114
+ if ($ result === false ) {
115
+ throw new ContainerException ("Directory ' " . $ file ->getRealPath () . "' cannot be deleted " );
116
+ }
104
117
} else {
105
- unlink ($ file ->getRealPath ());
118
+ $ result = unlink ($ file ->getRealPath ());
119
+ if ($ result === false ) {
120
+ throw new ContainerException ("File ' " . $ file ->getRealPath () . "' cannot be deleted " );
121
+ }
106
122
}
107
123
}
108
124
@@ -120,7 +136,7 @@ private function createDirectory(string $directory): void
120
136
121
137
$ result = mkdir ($ directory );
122
138
if ($ result === false ) {
123
- throw new ContainerException ("Directory ' $ directory' can not be created! " );
139
+ throw new ContainerException ("Directory ' $ directory' cannot be created " );
124
140
}
125
141
}
126
142
@@ -130,7 +146,7 @@ private function getDefinitionDirectory(): string
130
146
$ relativeDirectory = $ this ->compilerConfig ->getFileBasedDefinitionConfig ()->getRelativeDefinitionDirectory ();
131
147
132
148
if ($ relativeDirectory === "" ) {
133
- throw new ContainerException ("Relative directory of file-based definitions can not be empty! " );
149
+ throw new ContainerException ("Relative directory of file-based definitions cannot be empty " );
134
150
}
135
151
136
152
return $ basePath . DIRECTORY_SEPARATOR . $ relativeDirectory ;
0 commit comments