Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #19511 Use a dedicated exception in the file locator (leofeyer)
This PR was squashed before being merged into the 3.2-dev branch (closes #19511). Discussion ---------- Use a dedicated exception in the file locator | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR adds a dedicated `FileLocatorFileNotFoundException` class to the file locator, so it is possible to catch file locator exceptions separately from invalid argument exceptions. ```php try { foreach ($container->get('file_locator')->locate('file.php', null, false) as $file) { include $file; } } catch (\InvalidArgumentException $e) { // this will catch both file locator exceptions as well as // any invalid argument exception thrown in an included file } ``` With the dedicated exceptions, we could do this: ```php try { foreach ($container->get('file_locator')->locate('file.php', null, false) as $file) { include $file; } } catch (FileLocatorFileNotFoundException $e) { // this will only ignore file locator exceptions } ``` Commits ------- ee4adaa Use a dedicated exception in the file locator
- Loading branch information
Showing
4 changed files
with
31 additions
and
5 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Symfony/Component/Config/Exception/FileLocatorFileNotFoundException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Config\Exception; | ||
|
||
/** | ||
* File locator exception if a file does not exist. | ||
* | ||
* @author Leo Feyer <https://github.com/leofeyer> | ||
*/ | ||
class FileLocatorFileNotFoundException extends \InvalidArgumentException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters