Reputation: 3226
After upgrading my Homestead and installing my packages I came across a strange bug. On calling php artisan
the following was given as output:
In LoadConfiguration.php line 68:
Unable to load the "app" configuration file.
A few people suggest that this is the cause of Windows (10) capitalising the filenames. However this can't be seen in my folders and also does not apply in my Ubuntu (18.04) environment.
Looking in the source code of LoadConfiguration.php
we can see that it is using the Finder
class from the symfony/finder
component.
foreach (Finder::create()->files()->name('*.php')->in($configPath) as $file) {
$directory = $this->getNestedDirectory($file, $configPath);
$files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath();
}
The problem is that the finder does return an iterator that somehow cannot find my config files. A simple scandir($configPath)
returns all files:
.
..
app.php
and all other files
Wrapping the call in iterator_to_array()
returns an empty array []
.
The following object is returned by adding ..->in($configPath)->getIterator()
:
Symfony\Component\Finder\Iterator\PathFilterIterator {#47
#matchRegexps: []
#noMatchRegexps: array:2 [
0 => "#(^|/)\..+(/|$)#"
1 => "#(^|/)\..+(/|$)#"
]
innerIterator: Symfony\Component\Finder\Iterator\FilenameFilterIterator {#43
#matchRegexps: array:1 [
0 => "#^(?=[^\.])[^/]*\.php$#"
]
#noMatchRegexps: []
innerIterator: Symfony\Component\Finder\Iterator\FileTypeFilterIterator {#39
-mode: 1
innerIterator: RecursiveIteratorIterator {#42
innerIterator: Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator {#46
-iterator: Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator {#48
-ignoreUnreadableDirs: false
-rewindable: null
-rootPath: "/home/vagrant/somepath/api/config"
-subPath: null
-directorySeparator: "/"
path: "/home/vagrant/somepath/api/config"
filename: "app.php"
basename: "app.php"
pathname: "/home/vagrant/somepath/api/config/app.php"
extension: "php"
realPath: "./config/app.php"
aTime: 2019-07-02 09:28:30
mTime: 2019-01-31 17:43:49
cTime: 2019-07-02 16:32:52
inode: 429
size: 9727
perms: 0100777
owner: 1000
group: 1000
type: "file"
writable: true
readable: true
executable: true
file: true
dir: false
link: false
}
-isRecursive: true
-excludedDirs: array:9 [
".svn" => true
"_svn" => true
"CVS" => true
"_darcs" => true
".arch-params" => true
".monotone" => true
".bzr" => true
".git" => true
".hg" => true
]
-excludedPattern: null
innerIterator: Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator {#48}
}
}
}
}
}
Assume I do not know anything about these type of iterators. Two things stand out to me:
innerIterator
's are present.#48
, we can see our config/app.php
, but is inside a ExcludeDirectoryFilterIterator
.Has anybody had this problem before or know how to lead me in the right direction?
The following versions were used:
OS: Windows 10/Ubuntu 18.04 LTS
Homestead: 9.0.1
laravel/framework: 5.8.*/5.7.*
\ symfony/finder: ^4.2/^4.1,
EDIT
Downgraded my Homestead to v8.0.1
and everything works. However still no explanation about why this happened on v9.0.1
.
Upvotes: 9
Views: 3353
Reputation: 2336
I don't have an answer for why this happened, but I did code up an alternative to using Finder
in the LoadConfiguration::getConfigurationFiles
function (within \vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\LoadConfiguration.php) which allows me to run php artisan
commands without any issues...
protected function getConfigurationFiles(Application $app)
{
$files = [];
$configPath = realpath($app->configPath());
$file = new \DirectoryIterator($configPath);
while($file->valid()) {
if(!$file->isDot() && ($file->getExtension() == 'php')) {
$directory = $this->getNestedDirectory($file, $configPath);
$files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath();
}
$file->next();
}
ksort($files, SORT_NATURAL);
return $files;
}
Hope that helps someone.
Upvotes: 0