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

Skip to content

Commit 0175962

Browse files
ProgMinernicolas-grekas
authored andcommitted
[Config] Rename FileLoaderLoadException to LoaderLoadException
1 parent b6f17f4 commit 0175962

14 files changed

+149
-122
lines changed

UPGRADE-4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Config
1010
------
1111

1212
* Deprecated constructing a `TreeBuilder` without passing root node information.
13+
* Deprecated `FileLoaderLoadException`. Renamed to `LoaderLoadException`.
1314

1415
Console
1516
-------

src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Routing;
1313

1414
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
15-
use Symfony\Component\Config\Exception\FileLoaderLoadException;
15+
use Symfony\Component\Config\Exception\LoaderLoadException;
1616
use Symfony\Component\Config\Loader\DelegatingLoader as BaseDelegatingLoader;
1717
use Symfony\Component\Config\Loader\LoaderResolverInterface;
1818

@@ -64,7 +64,7 @@ public function load($resource, $type = null)
6464
// - this handles the case and prevents the second fatal error
6565
// by triggering an exception beforehand.
6666

67-
throw new FileLoaderLoadException($resource, null, null, null, $type);
67+
throw new LoaderLoadException($resource, null, null, null, $type);
6868
}
6969
$this->loading = true;
7070

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated constructing a `TreeBuilder` without passing root node information
8+
* renamed `FileLoaderLoadException` to `LoaderLoadException`
89

910
4.1.0
1011
-----

src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Fabien Potencier <[email protected]>
1818
*/
19-
class FileLoaderImportCircularReferenceException extends FileLoaderLoadException
19+
class FileLoaderImportCircularReferenceException extends LoaderLoadException
2020
{
2121
public function __construct(array $resources, int $code = null, \Exception $previous = null)
2222
{

src/Symfony/Component/Config/Exception/FileLoaderLoadException.php

Lines changed: 7 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,99 +11,15 @@
1111

1212
namespace Symfony\Component\Config\Exception;
1313

14-
/**
15-
* Exception class for when a resource cannot be loaded or imported.
16-
*
17-
* @author Ryan Weaver <[email protected]>
18-
*/
19-
class FileLoaderLoadException extends \Exception
20-
{
21-
/**
22-
* @param string $resource The resource that could not be imported
23-
* @param string $sourceResource The original resource importing the new resource
24-
* @param int $code The error code
25-
* @param \Exception $previous A previous exception
26-
* @param string $type The type of resource
27-
*/
28-
public function __construct(string $resource, string $sourceResource = null, int $code = null, \Exception $previous = null, string $type = null)
29-
{
30-
$message = '';
31-
if ($previous) {
32-
// Include the previous exception, to help the user see what might be the underlying cause
14+
class_alias(LoaderLoadException::class, FileLoaderLoadException::class);
3315

34-
// Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
35-
if ('.' === substr($previous->getMessage(), -1)) {
36-
$trimmedMessage = substr($previous->getMessage(), 0, -1);
37-
$message .= sprintf('%s', $trimmedMessage).' in ';
38-
} else {
39-
$message .= sprintf('%s', $previous->getMessage()).' in ';
40-
}
41-
$message .= $resource.' ';
42-
43-
// show tweaked trace to complete the human readable sentence
44-
if (null === $sourceResource) {
45-
$message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
46-
} else {
47-
$message .= sprintf('(which is being imported from "%s")', $this->varToString($sourceResource));
48-
}
49-
$message .= '.';
50-
51-
// if there's no previous message, present it the default way
52-
} elseif (null === $sourceResource) {
53-
$message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
54-
} else {
55-
$message .= sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
56-
}
57-
58-
// Is the resource located inside a bundle?
59-
if ('@' === $resource[0]) {
60-
$parts = explode(\DIRECTORY_SEPARATOR, $resource);
61-
$bundle = substr($parts[0], 1);
62-
$message .= sprintf(' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
63-
$message .= sprintf(' If the bundle is registered, make sure the bundle path "%s" is not empty.', $resource);
64-
} elseif (null !== $type) {
65-
// maybe there is no loader for this specific type
66-
if ('annotation' === $type) {
67-
$message .= ' Make sure annotations are installed and enabled.';
68-
} else {
69-
$message .= sprintf(' Make sure there is a loader supporting the "%s" type.', $type);
70-
}
71-
}
72-
73-
parent::__construct($message, $code, $previous);
74-
}
16+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.2, use "%s" instead.', FileLoaderLoadException::class, LoaderLoadException::class), E_USER_DEPRECATED);
7517

76-
protected function varToString($var)
18+
if (false) {
19+
/**
20+
* @deprecated since Symfony 4.2, use LoaderLoadException instead.
21+
*/
22+
class FileLoaderLoadException extends LoaderLoadException
7723
{
78-
if (\is_object($var)) {
79-
return sprintf('Object(%s)', \get_class($var));
80-
}
81-
82-
if (\is_array($var)) {
83-
$a = array();
84-
foreach ($var as $k => $v) {
85-
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
86-
}
87-
88-
return sprintf('Array(%s)', implode(', ', $a));
89-
}
90-
91-
if (\is_resource($var)) {
92-
return sprintf('Resource(%s)', get_resource_type($var));
93-
}
94-
95-
if (null === $var) {
96-
return 'null';
97-
}
98-
99-
if (false === $var) {
100-
return 'false';
101-
}
102-
103-
if (true === $var) {
104-
return 'true';
105-
}
106-
107-
return (string) $var;
10824
}
10925
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
* Exception class for when a resource cannot be loaded or imported.
16+
*
17+
* @author Ryan Weaver <[email protected]>
18+
*/
19+
class LoaderLoadException extends \Exception
20+
{
21+
/**
22+
* @param string $resource The resource that could not be imported
23+
* @param string $sourceResource The original resource importing the new resource
24+
* @param int $code The error code
25+
* @param \Exception $previous A previous exception
26+
* @param string $type The type of resource
27+
*/
28+
public function __construct(string $resource, string $sourceResource = null, int $code = null, \Exception $previous = null, string $type = null)
29+
{
30+
$message = '';
31+
if ($previous) {
32+
// Include the previous exception, to help the user see what might be the underlying cause
33+
34+
// Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
35+
if ('.' === substr($previous->getMessage(), -1)) {
36+
$trimmedMessage = substr($previous->getMessage(), 0, -1);
37+
$message .= sprintf('%s', $trimmedMessage).' in ';
38+
} else {
39+
$message .= sprintf('%s', $previous->getMessage()).' in ';
40+
}
41+
$message .= $resource.' ';
42+
43+
// show tweaked trace to complete the human readable sentence
44+
if (null === $sourceResource) {
45+
$message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
46+
} else {
47+
$message .= sprintf('(which is being imported from "%s")', $this->varToString($sourceResource));
48+
}
49+
$message .= '.';
50+
51+
// if there's no previous message, present it the default way
52+
} elseif (null === $sourceResource) {
53+
$message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
54+
} else {
55+
$message .= sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
56+
}
57+
58+
// Is the resource located inside a bundle?
59+
if ('@' === $resource[0]) {
60+
$parts = explode(\DIRECTORY_SEPARATOR, $resource);
61+
$bundle = substr($parts[0], 1);
62+
$message .= sprintf(' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
63+
$message .= sprintf(' If the bundle is registered, make sure the bundle path "%s" is not empty.', $resource);
64+
} elseif (null !== $type) {
65+
// maybe there is no loader for this specific type
66+
if ('annotation' === $type) {
67+
$message .= ' Make sure annotations are installed and enabled.';
68+
} else {
69+
$message .= sprintf(' Make sure there is a loader supporting the "%s" type.', $type);
70+
}
71+
}
72+
73+
parent::__construct($message, $code, $previous);
74+
}
75+
76+
protected function varToString($var)
77+
{
78+
if (\is_object($var)) {
79+
return sprintf('Object(%s)', \get_class($var));
80+
}
81+
82+
if (\is_array($var)) {
83+
$a = array();
84+
foreach ($var as $k => $v) {
85+
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
86+
}
87+
88+
return sprintf('Array(%s)', implode(', ', $a));
89+
}
90+
91+
if (\is_resource($var)) {
92+
return sprintf('Resource(%s)', get_resource_type($var));
93+
}
94+
95+
if (null === $var) {
96+
return 'null';
97+
}
98+
99+
if (false === $var) {
100+
return 'false';
101+
}
102+
103+
if (true === $var) {
104+
return 'true';
105+
}
106+
107+
return (string) $var;
108+
}
109+
}

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

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

1212
namespace Symfony\Component\Config\Loader;
1313

14-
use Symfony\Component\Config\Exception\FileLoaderLoadException;
14+
use Symfony\Component\Config\Exception\LoaderLoadException;
1515

1616
/**
1717
* DelegatingLoader delegates loading to other loaders using a loader resolver.
@@ -34,7 +34,7 @@ public function __construct(LoaderResolverInterface $resolver)
3434
public function load($resource, $type = null)
3535
{
3636
if (false === $loader = $this->resolver->resolve($resource, $type)) {
37-
throw new FileLoaderLoadException($resource, null, null, null, $type);
37+
throw new LoaderLoadException($resource, null, null, null, $type);
3838
}
3939

4040
return $loader->load($resource, $type);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\Config\Loader;
1313

1414
use Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException;
15-
use Symfony\Component\Config\Exception\FileLoaderLoadException;
1615
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
16+
use Symfony\Component\Config\Exception\LoaderLoadException;
1717
use Symfony\Component\Config\FileLocatorInterface;
1818
use Symfony\Component\Config\Resource\FileExistenceResource;
1919
use Symfony\Component\Config\Resource\GlobResource;
@@ -66,7 +66,7 @@ public function getLocator()
6666
*
6767
* @return mixed
6868
*
69-
* @throws FileLoaderLoadException
69+
* @throws LoaderLoadException
7070
* @throws FileLoaderImportCircularReferenceException
7171
* @throws FileLocatorFileNotFoundException
7272
*/
@@ -161,11 +161,11 @@ private function doImport($resource, $type = null, bool $ignoreErrors = false, $
161161
} catch (\Exception $e) {
162162
if (!$ignoreErrors) {
163163
// prevent embedded imports from nesting multiple exceptions
164-
if ($e instanceof FileLoaderLoadException) {
164+
if ($e instanceof LoaderLoadException) {
165165
throw $e;
166166
}
167167

168-
throw new FileLoaderLoadException($resource, $sourceResource, null, $e, $type);
168+
throw new LoaderLoadException($resource, $sourceResource, null, $e, $type);
169169
}
170170
}
171171
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Config\Loader;
1313

14-
use Symfony\Component\Config\Exception\FileLoaderLoadException;
14+
use Symfony\Component\Config\Exception\LoaderLoadException;
1515

1616
/**
1717
* Loader is the abstract class used by all built-in loaders.
@@ -59,7 +59,7 @@ public function import($resource, $type = null)
5959
*
6060
* @return $this|LoaderInterface
6161
*
62-
* @throws FileLoaderLoadException If no loader is found
62+
* @throws LoaderLoadException If no loader is found
6363
*/
6464
public function resolve($resource, $type = null)
6565
{
@@ -70,7 +70,7 @@ public function resolve($resource, $type = null)
7070
$loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
7171

7272
if (false === $loader) {
73-
throw new FileLoaderLoadException($resource, null, null, null, $type);
73+
throw new LoaderLoadException($resource, null, null, null, $type);
7474
}
7575

7676
return $loader;

0 commit comments

Comments
 (0)