Closed nbish11 closed 1 year ago
Hi! You just need to open app.php
file and use something like below
$app = App::create(
directories: [
'root' => __DIR__,
'app' => __DIR__ . '/',
]
)->run();
But I don't recommend to use root directory for Application, it's not secure.
You need also change autoloader namespaces in composer.json
"autoload": {
"psr-4": {
"App\\": "app/src" <============
}
},
I re-installed Spiral from scratch, made only the changes you gave, and ran composer dump-autoload
. I have also tried to run php app.php configure -vvv
, which just hangs, and I have to force quit. Unfortunately, is still does not work.
May I ask why it is insecure to run from root directory?
Oh, I missed that you have src
folder for all your source code.
I'll try to check it by myself
Thanks
@nbish11 I investigated the problem and found the solution.
The reason of the problem is tokenizer
component. By default, when you start an application it starts to iterate classes in application directory. But if you set as application directory root
- Tokenizer start to scan vendor
directory also, but there are some classes can not be parsed by tokenizer and it throws an exception.
There are two ways to solve the problem:
mapDirectories
method. Somethig like code belowprotected function mapDirectories(array $directories): array
{
$directories['app'] = $directories['root'] . '/src/';
$directories['config'] = $directories['root'] . '/config/';
$directories['resources'] = $directories['root'] . '/resources/';
return parent::mapDirectories($directories);
}
tokenizer.php
config file on your config directory and fix application path<?php
declare(strict_types=1);
return [
'debug' => false,
'directories' => [
directory('app') . '/src', <---------- Scan only inside src directory
],
'exclude' => [
directory('resources'),
directory('config'),
'tests',
'migrations',
],
];
P.S. Don't forget fix paths in composer.json
"autoload": {
"psr-4": {
"App\\": "src" <=========
},
"files": [
"src/Application/helpers.php" <=========
]
},
I hope it will help you!
I went with the second option, everything works perfectly now! Thank you for your help.
I would like to use this package and when I follow the documentation and install it, everything works in its default state. However, I need to change the directory structure of the app, instead of having everything under the
app
folder, I would like everything under theroot
folder instead. No matter how I try to configure the application, it doesn't work. The documentation states I can change directories in the mapDirectories method, and after a dump, everything points to the right place.This is the error I keep getting:
This is my
mapDirectories()
method:My folder structure:
If I reset everything back to defaults, there are no problems. I have change no other files other than directory paths in.