[BUGFIX] Fix broken link to anchor
[Packages/TYPO3.CMS.git] / typo3 / contrib / vendor / doctrine / instantiator / src / Doctrine / Instantiator / Exception / UnexpectedValueException.php
1 <?php
2 /*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 *
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
18 */
19
20 namespace Doctrine\Instantiator\Exception;
21
22 use Exception;
23 use ReflectionClass;
24 use UnexpectedValueException as BaseUnexpectedValueException;
25
26 /**
27 * Exception for given parameters causing invalid/unexpected state on instantiation
28 *
29 * @author Marco Pivetta <ocramius@gmail.com>
30 */
31 class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface
32 {
33 /**
34 * @param ReflectionClass $reflectionClass
35 * @param Exception $exception
36 *
37 * @return self
38 */
39 public static function fromSerializationTriggeredException(ReflectionClass $reflectionClass, Exception $exception)
40 {
41 return new self(
42 sprintf(
43 'An exception was raised while trying to instantiate an instance of "%s" via un-serialization',
44 $reflectionClass->getName()
45 ),
46 0,
47 $exception
48 );
49 }
50
51 /**
52 * @param ReflectionClass $reflectionClass
53 * @param string $errorString
54 * @param int $errorCode
55 * @param string $errorFile
56 * @param int $errorLine
57 *
58 * @return UnexpectedValueException
59 */
60 public static function fromUncleanUnSerialization(
61 ReflectionClass $reflectionClass,
62 $errorString,
63 $errorCode,
64 $errorFile,
65 $errorLine
66 ) {
67 return new self(
68 sprintf(
69 'Could not produce an instance of "%s" via un-serialization, since an error was triggered '
70 . 'in file "%s" at line "%d"',
71 $reflectionClass->getName(),
72 $errorFile,
73 $errorLine
74 ),
75 0,
76 new Exception($errorString, $errorCode)
77 );
78 }
79 }