Skip to content

Commit 97bb22c

Browse files
committed
minor symfony#12206 [Config] fix filelocator with empty name (Tobion)
This PR was merged into the 2.3 branch. Discussion ---------- [Config] fix filelocator with empty name | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - fix filelocator with empty name + phpdoc in config component Commits ------- 63b8c07 [DependencyInjection] use inheritdoc for loaders ddd2fe2 [Config] fix filelocator with empty name
2 parents 9a8ac52 + 63b8c07 commit 97bb22c

19 files changed

+110
-150
lines changed

src/Symfony/Component/Config/FileLocator.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,14 @@ public function __construct($paths = array())
3131
}
3232

3333
/**
34-
* Returns a full path for a given file name.
35-
*
36-
* @param mixed $name The file name to locate
37-
* @param string $currentPath The current path
38-
* @param bool $first Whether to return the first occurrence or an array of filenames
39-
*
40-
* @return string|array The full path to the file|An array of file paths
41-
*
42-
* @throws \InvalidArgumentException When file is not found
34+
* {@inheritdoc}
4335
*/
4436
public function locate($name, $currentPath = null, $first = true)
4537
{
38+
if ('' == $name) {
39+
throw new \InvalidArgumentException('An empty file name is not valid to be located.');
40+
}
41+
4642
if ($this->isAbsolutePath($name)) {
4743
if (!file_exists($name)) {
4844
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
@@ -84,10 +80,10 @@ public function locate($name, $currentPath = null, $first = true)
8480
*/
8581
private function isAbsolutePath($file)
8682
{
87-
if ($file[0] == '/' || $file[0] == '\\'
83+
if ($file[0] === '/' || $file[0] === '\\'
8884
|| (strlen($file) > 3 && ctype_alpha($file[0])
89-
&& $file[1] == ':'
90-
&& ($file[2] == '\\' || $file[2] == '/')
85+
&& $file[1] === ':'
86+
&& ($file[2] === '\\' || $file[2] === '/')
9187
)
9288
|| null !== parse_url($file, PHP_URL_SCHEME)
9389
) {

src/Symfony/Component/Config/FileLocatorInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ interface FileLocatorInterface
1919
/**
2020
* Returns a full path for a given file name.
2121
*
22-
* @param mixed $name The file name to locate
23-
* @param string $currentPath The current path
24-
* @param bool $first Whether to return the first occurrence or an array of filenames
22+
* @param string $name The file name to locate
23+
* @param string|null $currentPath The current path
24+
* @param bool $first Whether to return the first occurrence or an array of filenames
2525
*
26-
* @return string|array The full path to the file|An array of file paths
26+
* @return string|array The full path to the file or an array of file paths
2727
*
2828
* @throws \InvalidArgumentException When file is not found
2929
*/

src/Symfony/Component/Config/Loader/DelegatingLoader.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@ public function __construct(LoaderResolverInterface $resolver)
3434
}
3535

3636
/**
37-
* Loads a resource.
38-
*
39-
* @param mixed $resource A resource
40-
* @param string $type The resource type
41-
*
42-
* @return mixed
43-
*
44-
* @throws FileLoaderLoadException if no loader is found.
37+
* {@inheritdoc}
4538
*/
4639
public function load($resource, $type = null)
4740
{

src/Symfony/Component/Config/Loader/FileLoader.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
*/
2323
abstract class FileLoader extends Loader
2424
{
25+
/**
26+
* @var array
27+
*/
2528
protected static $loading = array();
2629

30+
/**
31+
* @var FileLocatorInterface
32+
*/
2733
protected $locator;
2834

2935
private $currentDir;
@@ -38,11 +44,21 @@ public function __construct(FileLocatorInterface $locator)
3844
$this->locator = $locator;
3945
}
4046

47+
/**
48+
* Sets the current directory.
49+
*
50+
* @param string $dir
51+
*/
4152
public function setCurrentDir($dir)
4253
{
4354
$this->currentDir = $dir;
4455
}
4556

57+
/**
58+
* Returns the file locator used by this loader.
59+
*
60+
* @return FileLocatorInterface
61+
*/
4662
public function getLocator()
4763
{
4864
return $this->locator;
@@ -51,10 +67,10 @@ public function getLocator()
5167
/**
5268
* Imports a resource.
5369
*
54-
* @param mixed $resource A Resource
55-
* @param string $type The resource type
56-
* @param bool $ignoreErrors Whether to ignore import errors or not
57-
* @param string $sourceResource The original resource importing the new resource
70+
* @param mixed $resource A Resource
71+
* @param string|null $type The resource type or null if unknown
72+
* @param bool $ignoreErrors Whether to ignore import errors or not
73+
* @param string|null $sourceResource The original resource importing the new resource
5874
*
5975
* @return mixed
6076
*

src/Symfony/Component/Config/Loader/Loader.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,15 @@ abstract class Loader implements LoaderInterface
2323
protected $resolver;
2424

2525
/**
26-
* Gets the loader resolver.
27-
*
28-
* @return LoaderResolverInterface A LoaderResolverInterface instance
26+
* {@inheritdoc}
2927
*/
3028
public function getResolver()
3129
{
3230
return $this->resolver;
3331
}
3432

3533
/**
36-
* Sets the loader resolver.
37-
*
38-
* @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
34+
* {@inheritdoc}
3935
*/
4036
public function setResolver(LoaderResolverInterface $resolver)
4137
{
@@ -45,8 +41,8 @@ public function setResolver(LoaderResolverInterface $resolver)
4541
/**
4642
* Imports a resource.
4743
*
48-
* @param mixed $resource A Resource
49-
* @param string $type The resource type
44+
* @param mixed $resource A resource
45+
* @param string|null $type The resource type or null if unknown
5046
*
5147
* @return mixed
5248
*/
@@ -58,12 +54,12 @@ public function import($resource, $type = null)
5854
/**
5955
* Finds a loader able to load an imported resource.
6056
*
61-
* @param mixed $resource A Resource
62-
* @param string $type The resource type
57+
* @param mixed $resource A resource
58+
* @param string|null $type The resource type or null if unknown
6359
*
6460
* @return LoaderInterface A LoaderInterface instance
6561
*
66-
* @throws FileLoaderLoadException if no loader is found
62+
* @throws FileLoaderLoadException If no loader is found
6763
*/
6864
public function resolve($resource, $type = null)
6965
{

src/Symfony/Component/Config/Loader/LoaderInterface.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ interface LoaderInterface
2121
/**
2222
* Loads a resource.
2323
*
24-
* @param mixed $resource The resource
25-
* @param string $type The resource type
24+
* @param mixed $resource The resource
25+
* @param string|null $type The resource type or null if unknown
26+
*
27+
* @throws \Exception If something went wrong
2628
*/
2729
public function load($resource, $type = null);
2830

2931
/**
30-
* Returns true if this class supports the given resource.
32+
* Returns whether this class supports the given resource.
3133
*
32-
* @param mixed $resource A resource
33-
* @param string $type The resource type
34+
* @param mixed $resource A resource
35+
* @param string|null $type The resource type or null if unknown
3436
*
35-
* @return bool true if this class supports the given resource, false otherwise
37+
* @return bool True if this class supports the given resource, false otherwise
3638
*/
3739
public function supports($resource, $type = null);
3840

src/Symfony/Component/Config/Loader/LoaderResolver.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ public function __construct(array $loaders = array())
4040
}
4141

4242
/**
43-
* Returns a loader able to load the resource.
44-
*
45-
* @param mixed $resource A resource
46-
* @param string $type The resource type
47-
*
48-
* @return LoaderInterface|false A LoaderInterface instance
43+
* {@inheritdoc}
4944
*/
5045
public function resolve($resource, $type = null)
5146
{

src/Symfony/Component/Config/Loader/LoaderResolverInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ interface LoaderResolverInterface
2121
/**
2222
* Returns a loader able to load the resource.
2323
*
24-
* @param mixed $resource A resource
25-
* @param string $type The resource type
24+
* @param mixed $resource A resource
25+
* @param string|null $type The resource type or null if unknown
2626
*
27-
* @return LoaderInterface A LoaderInterface instance
27+
* @return LoaderInterface|false The loader or false if none is able to load the resource
2828
*/
2929
public function resolve($resource, $type = null);
3030
}

src/Symfony/Component/Config/Resource/DirectoryResource.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class DirectoryResource implements ResourceInterface, \Serializable
2424
/**
2525
* Constructor.
2626
*
27-
* @param string $resource The file path to the resource
28-
* @param string $pattern A pattern to restrict monitored files
27+
* @param string $resource The file path to the resource
28+
* @param string|null $pattern A pattern to restrict monitored files
2929
*/
3030
public function __construct($resource, $pattern = null)
3131
{
@@ -34,36 +34,33 @@ public function __construct($resource, $pattern = null)
3434
}
3535

3636
/**
37-
* Returns a string representation of the Resource.
38-
*
39-
* @return string A string representation of the Resource
37+
* {@inheritdoc}
4038
*/
4139
public function __toString()
4240
{
4341
return (string) $this->resource;
4442
}
4543

4644
/**
47-
* Returns the resource tied to this Resource.
48-
*
49-
* @return mixed The resource
45+
* {@inheritdoc}
5046
*/
5147
public function getResource()
5248
{
5349
return $this->resource;
5450
}
5551

52+
/**
53+
* Returns the pattern to restrict monitored files
54+
*
55+
* @return string|null
56+
*/
5657
public function getPattern()
5758
{
5859
return $this->pattern;
5960
}
6061

6162
/**
62-
* Returns true if the resource has not been updated since the given timestamp.
63-
*
64-
* @param int $timestamp The last time the resource was loaded
65-
*
66-
* @return bool true if the resource has not been updated, false otherwise
63+
* {@inheritdoc}
6764
*/
6865
public function isFresh($timestamp)
6966
{

src/Symfony/Component/Config/Resource/FileResource.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
class FileResource implements ResourceInterface, \Serializable
2222
{
23+
/**
24+
* @var string|false
25+
*/
2326
private $resource;
2427

2528
/**
@@ -33,35 +36,27 @@ public function __construct($resource)
3336
}
3437

3538
/**
36-
* Returns a string representation of the Resource.
37-
*
38-
* @return string A string representation of the Resource
39+
* {@inheritdoc}
3940
*/
4041
public function __toString()
4142
{
4243
return (string) $this->resource;
4344
}
4445

4546
/**
46-
* Returns the resource tied to this Resource.
47-
*
48-
* @return mixed The resource
47+
* {@inheritdoc}
4948
*/
5049
public function getResource()
5150
{
5251
return $this->resource;
5352
}
5453

5554
/**
56-
* Returns true if the resource has not been updated since the given timestamp.
57-
*
58-
* @param int $timestamp The last time the resource was loaded
59-
*
60-
* @return bool true if the resource has not been updated, false otherwise
55+
* {@inheritdoc}
6156
*/
6257
public function isFresh($timestamp)
6358
{
64-
if (!file_exists($this->resource)) {
59+
if (false === $this->resource || !file_exists($this->resource)) {
6560
return false;
6661
}
6762

0 commit comments

Comments
 (0)