Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee4adaa

Browse files
leofeyerfabpot
authored andcommitted
Use a dedicated exception in the file locator
1 parent e408b50 commit ee4adaa

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Config\Exception;
13+
14+
/**
15+
* File locator exception if a file does not exist.
16+
*
17+
* @author Leo Feyer <https://github.com/leofeyer>
18+
*/
19+
class FileLocatorFileNotFoundException extends \InvalidArgumentException
20+
{
21+
}

src/Symfony/Component/Config/FileLocator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Config;
1313

14+
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
15+
1416
/**
1517
* FileLocator uses an array of pre-defined paths to find files.
1618
*
@@ -41,7 +43,7 @@ public function locate($name, $currentPath = null, $first = true)
4143

4244
if ($this->isAbsolutePath($name)) {
4345
if (!file_exists($name)) {
44-
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
46+
throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist.', $name));
4547
}
4648

4749
return $name;
@@ -66,7 +68,7 @@ public function locate($name, $currentPath = null, $first = true)
6668
}
6769

6870
if (!$filepaths) {
69-
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
71+
throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
7072
}
7173

7274
return $filepaths;

src/Symfony/Component/Config/FileLocatorInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Config;
1313

14+
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
15+
1416
/**
1517
* @author Fabien Potencier <[email protected]>
1618
*/
@@ -25,7 +27,8 @@ interface FileLocatorInterface
2527
*
2628
* @return string|array The full path to the file or an array of file paths
2729
*
28-
* @throws \InvalidArgumentException When file is not found
30+
* @throws \InvalidArgumentException If $name is empty
31+
* @throws FileLocatorFileNotFoundException If a file is not found
2932
*/
3033
public function locate($name, $currentPath = null, $first = true);
3134
}

src/Symfony/Component/Config/Tests/FileLocatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testLocate()
8686
}
8787

8888
/**
89-
* @expectedException \InvalidArgumentException
89+
* @expectedException \Symfony\Component\Config\Exception\FileLocatorFileNotFoundException
9090
* @expectedExceptionMessage The file "foobar.xml" does not exist
9191
*/
9292
public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
@@ -97,7 +97,7 @@ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
9797
}
9898

9999
/**
100-
* @expectedException \InvalidArgumentException
100+
* @expectedException \Symfony\Component\Config\Exception\FileLocatorFileNotFoundException
101101
*/
102102
public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath()
103103
{

0 commit comments

Comments
 (0)