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

fixed the filesystem loader with relative paths #2195

Merged
merged 1 commit into from
Oct 21, 2016

Conversation

fabpot
Copy link
Contributor

@fabpot fabpot commented Oct 20, 2016

closes #2145

TODO

  • document the new $rootPath option
  • add test with a $rootPath different from getcwd()
  • test the cache key does not vary when $rootPath changes

{
$this->rootPath = realpath(null !== $rootPath ? $rootPath : getcwd()).DIRECTORY_SEPARATOR;
Copy link
Member

Choose a reason for hiding this comment

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

this is the place being broken if $rootPath is inside a phar, as $this->rootPath will be false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say that we don't want to support this use case (if everything is in a phar, then using an absolute path is not really an issue anymore). So, if realpath returns false here, I would prefer to throw an exception.

Copy link
Member

Choose a reason for hiding this comment

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

well, if someone uses relative path for the loader paths and passes __DIR__ as root path (instead of making all paths absolute in the loader paths), your suggestion would break the project once it gets bundled as phar.
This seems worse than forbidding passing relative paths to the loader altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@fabpot fabpot force-pushed the loader-relative-paths branch 6 times, most recently from e5041b6 to 2fd5b0f Compare October 20, 2016 15:48
@fabpot
Copy link
Contributor Author

fabpot commented Oct 20, 2016

Ready.

@fabpot fabpot force-pushed the loader-relative-paths branch from 2fd5b0f to 5f25a11 Compare October 20, 2016 19:56
/**
* Constructor.
*
* @param string|array $paths A path or an array of paths where to look for templates
* @param string|array $paths A path or an array of paths where to look for templates
* @param string $rootPath The root path common to all relative paths
Copy link
Contributor

Choose a reason for hiding this comment

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

string|null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@fabpot fabpot force-pushed the loader-relative-paths branch from 5f25a11 to a343c92 Compare October 21, 2016 13:52
@fabpot fabpot merged commit a343c92 into twigphp:1.x Oct 21, 2016
fabpot added a commit that referenced this pull request Oct 21, 2016
This PR was merged into the 1.x branch.

Discussion
----------

fixed the filesystem loader with relative paths

closes #2145

TODO

 - [x] document the new `$rootPath` option
 - [x] add test with a `$rootPath` different from `getcwd()`
 - [x] test the cache key does not vary when `$rootPath` changes

Commits
-------

a343c92 fixed the filesystem loader with relative paths
@fabpot fabpot deleted the loader-relative-paths branch October 22, 2016 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants