Open hdodov opened 5 years ago
We already have a static $root
property, but it's protected. We could add a method to return that.
Yeah, but that property is set in the constructor of the class. So if you want to get the root, there must be an instance first, which can't be guaranteed. If you create a new Kirby instance, you might overwrite a previous one.
Also, the $root
points to the kirby directory, not the installation directory. I'm thinking something like the following pseudo code might be alright:
public static function webRoot () {
if (hasInstance) {
return instance->roots->index;
} else {
return dirname(__DIR__, 3);
}
}
Since all roots can be changed, it should use the index root of an already existing instance, when there is one.
Also, why is this static::$root = dirname(__DIR__, 2);
set in the class constructor when its constant? Couldn't it be set right after the class declaration just once? It might be against the PSR gospel, but it makes sense.
It would be very useful to be able to get the Kirby installation directory when developing Kirby utilities. I want to further advance my kirby-tester and to get the installation directory, I need to do something like:
To help with that, the Kirby class (
src/cms/App.php
) could have this static method:Then, I'd be able to use
Kirby::dir()
to get the directory, which will be much more reliable.