InvalidArgumentException.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Doctrine\Common\Proxy\Exception;
  3. use Doctrine\Persistence\Proxy;
  4. use InvalidArgumentException as BaseInvalidArgumentException;
  5. use function get_class;
  6. use function gettype;
  7. use function interface_exists;
  8. use function is_object;
  9. use function sprintf;
  10. /**
  11. * Proxy Invalid Argument Exception.
  12. *
  13. * @link www.doctrine-project.org
  14. */
  15. class InvalidArgumentException extends BaseInvalidArgumentException implements ProxyException
  16. {
  17. /**
  18. * @return self
  19. */
  20. public static function proxyDirectoryRequired()
  21. {
  22. return new self('You must configure a proxy directory. See docs for details');
  23. }
  24. /**
  25. * @param string $className
  26. * @param string $proxyNamespace
  27. *
  28. * @return self
  29. *
  30. * @psalm-param class-string $className
  31. */
  32. public static function notProxyClass($className, $proxyNamespace)
  33. {
  34. return new self(sprintf('The class "%s" is not part of the proxy namespace "%s"', $className, $proxyNamespace));
  35. }
  36. /**
  37. * @param string $name
  38. *
  39. * @return self
  40. */
  41. public static function invalidPlaceholder($name)
  42. {
  43. return new self(sprintf('Provided placeholder for "%s" must be either a string or a valid callable', $name));
  44. }
  45. /**
  46. * @return self
  47. */
  48. public static function proxyNamespaceRequired()
  49. {
  50. return new self('You must configure a proxy namespace');
  51. }
  52. /**
  53. * @return self
  54. */
  55. public static function unitializedProxyExpected(Proxy $proxy)
  56. {
  57. return new self(sprintf('Provided proxy of type "%s" must not be initialized.', get_class($proxy)));
  58. }
  59. /**
  60. * @param mixed $callback
  61. *
  62. * @return self
  63. */
  64. public static function invalidClassNotFoundCallback($callback)
  65. {
  66. $type = is_object($callback) ? get_class($callback) : gettype($callback);
  67. return new self(sprintf('Invalid \$notFoundCallback given: must be a callable, "%s" given', $type));
  68. }
  69. /**
  70. * @param string $className
  71. *
  72. * @return self
  73. *
  74. * @psalm-param class-string $className
  75. */
  76. public static function classMustNotBeAbstract($className)
  77. {
  78. return new self(sprintf('Unable to create a proxy for an abstract class "%s".', $className));
  79. }
  80. /**
  81. * @param string $className
  82. *
  83. * @return self
  84. *
  85. * @psalm-param class-string $className
  86. */
  87. public static function classMustNotBeFinal($className)
  88. {
  89. return new self(sprintf('Unable to create a proxy for a final class "%s".', $className));
  90. }
  91. /**
  92. * @param mixed $value
  93. */
  94. public static function invalidAutoGenerateMode($value): self
  95. {
  96. return new self(sprintf('Invalid auto generate mode "%s" given.', $value));
  97. }
  98. }
  99. interface_exists(Proxy::class);