Skip to content

Commit c334155

Browse files
committed
#147. Fix Routes/web.php with backslashes for Laravel >= 5.7
1 parent 5263e7d commit c334155

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

src/Blocks/ContentManager.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ protected function setComment(string $comment, int $tabs = 1): void
213213
}
214214

215215
/**
216+
* Sets an amount of tabs to source code
216217
* @param int $amount
217218
*/
218219
protected function setTabs(int $amount = 1): void
@@ -222,6 +223,17 @@ protected function setTabs(int $amount = 1): void
222223
}
223224
}
224225

226+
/**
227+
* Sets an amount of backslashes to source code
228+
* @param int $amount
229+
*/
230+
protected function setBackslashes(int $amount = 1): void
231+
{
232+
for ($i = $amount; $i > 0; --$i) {
233+
$this->sourceCode .= PhpInterface::BACKSLASH;
234+
}
235+
}
236+
225237
/**
226238
* @param array $attrVal
227239
*/

src/Blocks/FileManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use SoliDry\Exceptions\DirectoryException;
77
use SoliDry\Helpers\ConfigHelper;
88
use SoliDry\ApiGenerator;
9-
use SoliDry\Types\ApiInterface;
109
use SoliDry\Types\ConsoleInterface;
1110
use SoliDry\Types\DirsInterface;
1211
use SoliDry\Types\ModulesInterface;

src/Blocks/Routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function create(): void
3838
$this->setRoutes();
3939
$isCreated = false;
4040

41-
$file = FileManager::getModulePath($this->generator, true) .
42-
RoutesInterface::ROUTES_FILE_NAME . PhpInterface::PHP_EXT;
41+
$file = FileManager::getModulePath($this->generator) .
42+
RoutesInterface::ROUTES_DIR . DIRECTORY_SEPARATOR . RoutesInterface::ROUTES_FILE_NAME . PhpInterface::PHP_EXT;
4343

4444
// TODO: fix this behaviour - collect data 1-st for ex.
4545
if ($this->generator->routesCreated === 0 || file_exists($file) === false) {

src/Blocks/RoutesTrait.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait RoutesTrait
2525
*/
2626
public function openGroup() : void
2727
{
28-
$versionNamespace = DirsInterface::MODULES_DIR .
28+
$versionNamespace = DirsInterface::MODULES_DIR .
2929
PhpInterface::BACKSLASH . PhpInterface::BACKSLASH
3030
. strtoupper($this->generator->version);
3131

@@ -41,12 +41,16 @@ public function openGroup() : void
4141
PhpInterface::QUOTES
4242
. PhpInterface::PHP_NAMESPACE . PhpInterface::QUOTES
4343
. PhpInterface::SPACE . PhpInterface::DOUBLE_ARROW
44-
. PhpInterface::SPACE . PhpInterface::QUOTES .
45-
$versionNamespace
46-
. PhpInterface::BACKSLASH . PhpInterface::BACKSLASH .
47-
DirsInterface::HTTP_DIR
48-
. PhpInterface::BACKSLASH . PhpInterface::BACKSLASH .
49-
DirsInterface::CONTROLLERS_DIR . PhpInterface::QUOTES
44+
. PhpInterface::SPACE . PhpInterface::QUOTES;
45+
46+
$this->setBackslashes(2);
47+
$this->sourceCode .= $versionNamespace;
48+
49+
$this->setBackslashes(2);
50+
$this->sourceCode .= DirsInterface::HTTP_DIR;
51+
52+
$this->setBackslashes(2);
53+
$this->sourceCode .= DirsInterface::CONTROLLERS_DIR . PhpInterface::QUOTES
5054
. PhpInterface::CLOSE_BRACKET . PhpInterface::COMMA
5155
. PhpInterface::SPACE . PhpInterface::PHP_FUNCTION .
5256
PhpInterface::OPEN_PARENTHESES

src/Types/RoutesInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ interface RoutesInterface
1313
public const METHOD_DELETE = 'delete';
1414
public const METHOD_OPTIONS = 'options';
1515

16-
public const ROUTES_FILE_NAME = 'routes';
17-
18-
// std routes path for laravel/lumen
19-
public const ROUTES_APP_PATH = 'routes/web.php';
16+
public const ROUTES_DIR = 'Routes';
17+
public const ROUTES_FILE_NAME = 'web';
2018
}

0 commit comments

Comments
 (0)