Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple "baseDir" (array) to search for templates. #306

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mducharme
Copy link

This change allows FileSystemLoader to use an array as “baseDir”. When
loading a template, all directories will be searched into, the first one
matching the given file will be returned.

It is backward-compatible; passing a string as baseDir still works as intended.

Also included: Unit tests.

This change allows FileSystemLoader to use an array as “baseDir”. When
loading a template, all baseDir will be searched into, the first one
matching the given file will be returned.

Also included: Unit tests.
@bobthecow
Copy link
Owner

Hi. Sorry for the delay!

The protected methods on FilesystemLoader are part of the public API of this library. Developers extend that loader and expect those method signatures to keep working when upgrading. So we have two options: either ensure that all the private methods have backwards compatible signatures, or this change waits until the next major release (v3.0.0) which, to be honest, doesn't even have a roadmap yet :)

To make 'em backwards compatible, you could do something like…

protected function shouldCheckPath($dir = null)
{
    if ($dir === null) {
        $dir = $this->baseDir[0];
    }

    return strpos($dir, '://') === false || strpos($dir, 'file://') === 0;
}

if ($this->shouldCheckPath() && !file_exists($fileName)) {
throw new Mustache_Exception_UnknownTemplateException($name);
if (!$this->shouldCheckPath($dir) || file_exists($fileName)) {
return file_get_contents($fileName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a little bit weird, because if any "directory" in $this->baseDir uses a stream loader, it will never even check any directory after it in the list.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there's a good way to fix that, it's just an observation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants