[BUGFIX] Fix broken link to anchor
[Packages/TYPO3.CMS.git] / typo3 / contrib / vendor / doctrine / instantiator / src / Doctrine / Instantiator / Exception / InvalidArgumentException.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 InvalidArgumentException as BaseInvalidArgumentException;
23 use ReflectionClass;
24
25 /**
26 * Exception for invalid arguments provided to the instantiator
27 *
28 * @author Marco Pivetta <ocramius@gmail.com>
29 */
30 class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface
31 {
32 /**
33 * @param string $className
34 *
35 * @return self
36 */
37 public static function fromNonExistingClass($className)
38 {
39 if (interface_exists($className)) {
40 return new self(sprintf('The provided type "%s" is an interface, and can not be instantiated', $className));
41 }
42
43 if (PHP_VERSION_ID >= 50400 && trait_exists($className)) {
44 return new self(sprintf('The provided type "%s" is a trait, and can not be instantiated', $className));
45 }
46
47 return new self(sprintf('The provided class "%s" does not exist', $className));
48 }
49
50 /**
51 * @param ReflectionClass $reflectionClass
52 *
53 * @return self
54 */
55 public static function fromAbstractClass(ReflectionClass $reflectionClass)
56 {
57 return new self(sprintf(
58 'The provided class "%s" is abstract, and can not be instantiated',
59 $reflectionClass->getName()
60 ));
61 }
62 }