|
19 | 19 |
|
20 | 20 | namespace Phalcon\Builder; |
21 | 21 |
|
| 22 | +use SplFileInfo; |
| 23 | + |
22 | 24 | /** |
23 | 25 | * Module Builder |
24 | 26 | * |
@@ -88,7 +90,7 @@ public function build() |
88 | 90 | $modulesDir = $this->path->getRootPath($modulesDir); |
89 | 91 | } |
90 | 92 |
|
91 | | - $this->options->offsetSet('modulesDir', realpath($modulesDir)); |
| 93 | + $this->options->offsetSet('modulesDir', $modulesDir); |
92 | 94 | $this->options->offsetSet('templatePath', realpath($templatePath)); |
93 | 95 | $this->options->offsetSet('projectPath', $this->path->getRootPath()); |
94 | 96 |
|
@@ -122,10 +124,39 @@ public function buildDirectories() |
122 | 124 | )); |
123 | 125 | } |
124 | 126 |
|
125 | | - mkdir($modulesDir . DIRECTORY_SEPARATOR . $moduleName, 0777, true); |
| 127 | + $modulesPath = new SplFileInfo($modulesDir); |
| 128 | + $modulePath = $modulesDir. DIRECTORY_SEPARATOR . $moduleName; |
| 129 | + |
| 130 | + try { |
| 131 | + if ($modulesPath->isFile() && !$modulesPath->isDir()) { |
| 132 | + throw new BuilderException( |
| 133 | + sprintf( |
| 134 | + "Builder expects a directory for 'modulesDir'. But %s is a file.", |
| 135 | + $modulesPath->getPathname() |
| 136 | + ) |
| 137 | + ); |
| 138 | + } elseif ($modulesPath->isReadable() && !mkdir($modulePath, 0777, true)) { |
| 139 | + throw new BuilderException("Unable to create module directory. Check permissions."); |
| 140 | + } |
| 141 | + |
| 142 | + foreach ($this->moduleDirectories as $dir) { |
| 143 | + $path = $modulePath . DIRECTORY_SEPARATOR . $dir; |
| 144 | + if (!mkdir($path, 0777, true)) { |
| 145 | + throw new BuilderException( |
| 146 | + sprintf( |
| 147 | + "Unable to create %s directory. Check permissions.", |
| 148 | + $path |
| 149 | + ) |
| 150 | + ); |
| 151 | + } |
| 152 | + } |
126 | 153 |
|
127 | | - foreach ($this->moduleDirectories as $dir) { |
128 | | - mkdir($modulesDir . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . $dir, 0777, true); |
| 154 | + } catch (\Exception $e) { |
| 155 | + throw new BuilderException( |
| 156 | + $e->getMessage(), |
| 157 | + $e->getCode(), |
| 158 | + ($e instanceof BuilderException ? null : $e) |
| 159 | + ); |
129 | 160 | } |
130 | 161 |
|
131 | 162 | return $this; |
|
0 commit comments