Skip to content

Commit

Permalink
bug #18820 [Config] Allow schemed paths in FileResource (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.1 branch.

Discussion
----------

[Config] Allow schemed paths in FileResource

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17598
| License       | MIT
| Doc PR        | -

This is a small new feature fixing a BC break that has been introduced in #17598 on 3.1.
It happens that 3.1 is breaking a `phar` app on our side where we end up doing something like `new FileResource('phar://...')`.

Ping @xabbuh and @javiereguiluz esp.

Commits
-------

c73f34d [Config] Allow schemed path in FileResource
  • Loading branch information
fabpot committed May 23, 2016
2 parents d794f2f + c73f34d commit f467859
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Config/Resource/FileResource.php
Expand Up @@ -36,6 +36,10 @@ public function __construct($resource)
{
$this->resource = realpath($resource);

if (false === $this->resource && file_exists($resource)) {
$this->resource = $resource;
}

if (false === $this->resource) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $resource));
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
$this->file = sys_get_temp_dir().'/tmp.xml';
$this->time = time();
touch($this->file, $this->time);
$this->resource = new FileResource($this->file);
Expand All @@ -41,6 +41,12 @@ public function testGetResource()
$this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
}

public function testGetResourceWithScheme()
{
$resource = new FileResource('file://'.$this->file);
$this->assertSame('file://'.$this->file, $resource->getResource(), '->getResource() returns the path to the schemed resource');
}

public function testToString()
{
$this->assertSame(realpath($this->file), (string) $this->resource);
Expand Down

0 comments on commit f467859

Please sign in to comment.