Skip to content

Commit 7c4f5fa

Browse files
committed
feat: automatic path in config
1 parent dc562bc commit 7c4f5fa

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

config/config.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
declare(strict_types=1);
1111

12+
$subFolder = \str_replace($_SERVER['DOCUMENT_ROOT'], "", APP_DIR);
13+
$subFolder = $subFolder == "" ? "/" : $subFolder;
14+
1215
return [
1316

1417
'app' => [
@@ -18,10 +21,11 @@
1821
//folder of the app, if app isn't in the web server root add a
1922
//directory (/app, /other/app) else insert a / (slash) as value
2023
//default value [/app]
21-
'subFolder' => '/',
24+
//automatically determinated
25+
'subFolder' => $subFolder,
2226
//public folder of the app, starting from web server root
2327
//default value [/app/public]
24-
'publicFolder' => '/public',
28+
'publicFolder' => $subFolder.'/public',
2529
//.env file position, remember to add ../ if don't use an absolute path
2630
'envFile' => '../.env',
2731
//name of the fallback route, indicate the path when router return a NullRoute
@@ -64,7 +68,7 @@
6468
//that the router ignore when check a route. Example '/app/user/delete/5'
6569
//become '/user/delete/5' where the router subtract the basePath
6670
//default [/app]
67-
'basePath' => '/',
71+
'basePath' => $subFolder,
6872
//url rewriting
6973
//default [true]
7074
'rewriteMode' => true,

public/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
declare(strict_types=1);
1111

1212
use Linna\App\Helper\AppDotEnv;
13-
1413
use Linna\Authentication\Exception\AuthenticationException;
1514
use Linna\Authorization\Exception\AuthorizationException;
1615
use Linna\Container\Container;

src/Linna/App/Helper/RouteHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function generate(): RouteCollection
5858
// create reflection class and get attributes if attribute is istance of Route
5959
foreach ($reflectorClass->getAttributes(Route::class, ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
6060
// create new route instance using as arguments the attribute arguments plus the controller class
61-
$routes[] =(new ReflectionClass(Route::class)
61+
$routes[] = (new ReflectionClass(Route::class)
6262
)->newInstanceArgs($attribute->getArguments() +
6363
['controller' => $class]);
6464
}
@@ -77,7 +77,7 @@ public function generate(): RouteCollection
7777
foreach ($method->getAttributes(Route::class, ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
7878
// create new route instance using as arguments the attribute arguments plus the controller class
7979
// and the action
80-
$routes[] =(new ReflectionClass(Route::class))
80+
$routes[] = (new ReflectionClass(Route::class))
8181
->newInstanceArgs($attribute->getArguments() +
8282
['action' => $method->getName(), 'controller' => $class]);
8383
}

tests/Linna/App/Helper/RouteHelperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Linna\Mvc\ModelViewController;
1919
use Linna\Mvc\Model;
2020
use PHPUnit\Framework\TestCase;
21+
use PHPUnit\Framework\Attributes\DataProvider;
2122

2223
/**
2324
* Route Helper Test
@@ -62,7 +63,7 @@ public function testGenerateRoutes(): void
6263
*
6364
* @return array
6465
*/
65-
public function routesProvider(): array
66+
public static function routesProvider(): array
6667
{
6768
return [
6869
['/rest', 'GET', 'View getActionAll(): getActionAll()'],
@@ -78,14 +79,13 @@ public function routesProvider(): array
7879
/**
7980
* Test generated routes.
8081
*
81-
* @dataProvider routesProvider
82-
*
8382
* @param string $route
8483
* @param string $method
8584
* @param string $result
8685
*
8786
* @return void
8887
*/
88+
#[DataProvider('routesProvider')]
8989
public function testGeneratedRoutes(string $route, string $method, string $result): void
9090
{
9191
$router = new Router(

tests/Linna/App/Templates/HtmlTemplateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testNewInstance(): void
5656
public function testOutput(): void
5757
{
5858
self::$template->loadHtml('testPage');
59-
self::$template->setData(['test'=>'value']);
59+
self::$template->setData(['test' => 'value']);
6060

6161
$this->assertEquals('<b>value</b>', self::$template->getOutput());
6262
}

tests/Linna/App/Templates/JsonTemplateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testNewInstance(): void
5050
*/
5151
public function testOutput(): void
5252
{
53-
self::$template->setData(['test'=>'value']);
53+
self::$template->setData(['test' => 'value']);
5454

5555
$this->assertEquals('{"test":"value"}', self::$template->getOutput());
5656
}

tests/Linna/App/Templates/NullTemplateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testNewInstance(): void
5050
*/
5151
public function testOutput(): void
5252
{
53-
self::$template->setData(['test'=>'value']);
53+
self::$template->setData(['test' => 'value']);
5454

5555
$this->assertEquals('', self::$template->getOutput());
5656
}

0 commit comments

Comments
 (0)