Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Improved exception when a type hint class can not be found #514

Closed
wants to merge 1 commit into from

2 participants

Arnaud Le Blanc doctrinebot
Arnaud Le Blanc

This improves the exception message when a type hint class was not found during the generation of a proxy.

Example:

<?php
class Foo
{
    function test(\InvalidClass $param) 
    {
    }
}

When generating a proxy for this class Foo, if the type hint class InvalidClass cannot be found, a ReflectionException exception is thrown with the following message: Class InvalidClass does not exist. There is no hint on the real cause of the error (which class, method, ...).

This PR wraps this exception with a message making the cause of the exception more obvious.

doctrinebot
Collaborator

Oh btw, I just (automatically) realized that you are not creating this pull request against the master branch.

Unless there are good reasons for this, i would suggest to close and rebase the Pull Request against master and then create it again. Sorry!

doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2145

Arnaud Le Blanc

closing because duplicate of PR 469

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 14, 2012
Arnaud Le Blanc arnaud-lb Improved exception when a type hint class can not be found
when generating a proxy
d0e15b1
This page is out of date. Refresh to see the latest.
9 lib/Doctrine/ORM/Proxy/ProxyException.php
@@ -49,4 +49,13 @@ public static function notProxyClass($className, $proxyNamespace)
49 49 ));
50 50 }
51 51
  52 + public static function typeHintClassReflectionFailure($paramName, $className, $methodName, $previousException)
  53 + {
  54 + return new self(sprintf(
  55 + "Can not get type hint class for parameter %s of %s::%s()",
  56 + $paramName,
  57 + $className,
  58 + $methodName
  59 + ), 0, $previousException);
  60 + }
52 61 }
14 lib/Doctrine/ORM/Proxy/ProxyFactory.php
@@ -230,7 +230,19 @@ private function _generateMethods(ClassMetadata $class)
230 230 }
231 231
232 232 // We need to pick the type hint class too
233   - if (($paramClass = $param->getClass()) !== null) {
  233 +
  234 + try {
  235 + $paramClass = $param->getClass();
  236 + } catch (\ReflectionException $e) {
  237 + throw ProxyException::typeHintClassReflectionFailure(
  238 + $param->getName(),
  239 + $param->getDeclaringClass()->getName(),
  240 + $param->getDeclaringFunction()->getName(),
  241 + $e
  242 + );
  243 + }
  244 +
  245 + if ($paramClass !== null) {
234 246 $parameterString .= '\\' . $paramClass->getName() . ' ';
235 247 } else if ($param->isArray()) {
236 248 $parameterString .= 'array ';
22 tests/Doctrine/Tests/ORM/Proxy/ProxyClassGeneratorTest.php
@@ -181,6 +181,20 @@ public function testNoNamespace_ThrowsException()
181 181 new ProxyFactory($this->_getTestEntityManager(), __DIR__ . '/generated', null);
182 182 }
183 183
  184 + public function testWrongTypeHintClass_ThrowsException()
  185 + {
  186 + $this->setExpectedException(
  187 + 'Doctrine\ORM\Proxy\ProxyException',
  188 + "Can not get type hint class for parameter param of Doctrine\Tests\ORM\Proxy\WrontTypeHintClass::test()"
  189 + );
  190 +
  191 + $cm = new \Doctrine\ORM\Mapping\ClassMetadata(__NAMESPACE__ . '\\WrontTypeHintClass');
  192 + $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
  193 + $this->assertNotNull($cm->reflClass);
  194 +
  195 + $this->_proxyFactory->generateProxyClasses(array($cm));
  196 + }
  197 +
184 198 protected function _getMockPersister()
185 199 {
186 200 $persister = $this->getMock('Doctrine\ORM\Persisters\BasicEntityPersister', array('load'), array(), '', false);
@@ -202,3 +216,11 @@ public function __sleep()
202 216 {
203 217
204 218 }
  219 +
  220 +class WrontTypeHintClass
  221 +{
  222 + public function test(\WrontTypeHint $param)
  223 + {
  224 + }
  225 +}
  226 +

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.