Change usage of "base_path" and "public_path" #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request does three things:
Since most PHP functions (and
__DIR__
) and many third-party librairies return and expect paths without a trailing slash, it makes sense to expect Charcoal to follow that same behavior.Many paths in Charcoal are defined as relative but to what is not well documented (the "public_path") and does not always work as expected (such as from the Charcoal CLI or a custom PHP script).
When using the Charcoal CLI from the project's base path, we end up with secondary cache and logs directories in the directory above the base path. If that path is not accessible from the current user, Charcoal will throw an error from being unable to create the aforementioned directories/files.
Ideally, for security reasons, relative paths should always be from the "base_path", instead of the "public_path".
One solution, I propose, to assist with configuring relative paths is with "template tags":
Examples
This is accomplished with a new method
AppConfig::resolveValue()
that replaces any supported%app.*%
tokens:As for the new configurable paths, "cache_path" and "logs_path", I propose we follow Symfony's default location:
$this->basePath().'/var/cache'
$this->basePath().'/var/log'
Both the removal of the trailing slash and recommendations for relative paths requires changes to be made in many Charcoal packages such as:
ElfinderConnectorAction
andUploadImageAction
.StaticWebsite
actions.MetadataLoader
.FileProperty
andImageProperty
.TranslatorConfig
.TranslatorServiceProvider
.ViewServiceProvider
andAbstractLoader
.