Merge pull request #183 from asm89/ProxyIdentifier-types
Proxy identifier type casting
This commit is contained in:
commit
cce3798b4b
@ -210,8 +210,12 @@ class ProxyFactory
|
|||||||
$methods .= $parameterString . ')';
|
$methods .= $parameterString . ')';
|
||||||
$methods .= "\n" . ' {' . "\n";
|
$methods .= "\n" . ' {' . "\n";
|
||||||
if ($this->isShortIdentifierGetter($method, $class)) {
|
if ($this->isShortIdentifierGetter($method, $class)) {
|
||||||
|
$identifier = lcfirst(substr($method->getName(), 3));
|
||||||
|
|
||||||
|
$cast = in_array($class->fieldMappings[$identifier]['type'], array('integer', 'smallint')) ? '(int) ' : '';
|
||||||
|
|
||||||
$methods .= ' if ($this->__isInitialized__ === false) {' . "\n";
|
$methods .= ' if ($this->__isInitialized__ === false) {' . "\n";
|
||||||
$methods .= ' return $this->_identifier["' . lcfirst(substr($method->getName(), 3)) . '"];' . "\n";
|
$methods .= ' return ' . $cast . '$this->_identifier["' . $identifier . '"];' . "\n";
|
||||||
$methods .= ' }' . "\n";
|
$methods .= ' }' . "\n";
|
||||||
}
|
}
|
||||||
$methods .= ' $this->__load();' . "\n";
|
$methods .= ' $this->__load();' . "\n";
|
||||||
@ -237,6 +241,7 @@ class ProxyFactory
|
|||||||
in_array($identifier, $class->identifier, true) &&
|
in_array($identifier, $class->identifier, true) &&
|
||||||
$class->hasField($identifier) &&
|
$class->hasField($identifier) &&
|
||||||
(($method->getEndLine() - $method->getStartLine()) <= 4)
|
(($method->getEndLine() - $method->getStartLine()) <= 4)
|
||||||
|
&& in_array($class->fieldMappings[$identifier]['type'], array('integer', 'bigint', 'smallint', 'string'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional;
|
|||||||
use Doctrine\ORM\Proxy\ProxyFactory;
|
use Doctrine\ORM\Proxy\ProxyFactory;
|
||||||
use Doctrine\ORM\Proxy\ProxyClassGenerator;
|
use Doctrine\ORM\Proxy\ProxyClassGenerator;
|
||||||
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
|
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
|
||||||
|
use Doctrine\Tests\Models\ECommerce\ECommerceShipping;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../TestInit.php';
|
require_once __DIR__ . '/../../TestInit.php';
|
||||||
|
|
||||||
@ -160,6 +161,29 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertFalse($entity->__isInitialized__, "Getting the identifier doesn't initialize the proxy.");
|
$this->assertFalse($entity->__isInitialized__, "Getting the identifier doesn't initialize the proxy.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDoNotInitializeProxyOnGettingTheIdentifierAndReturnTheRightType()
|
||||||
|
{
|
||||||
|
$product = new ECommerceProduct();
|
||||||
|
$product->setName('Doctrine Cookbook');
|
||||||
|
|
||||||
|
$shipping = new ECommerceShipping();
|
||||||
|
$shipping->setDays(1);
|
||||||
|
$product->setShipping($shipping);
|
||||||
|
$this->_em->persist($product);
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$id = $shipping->getId();
|
||||||
|
|
||||||
|
$product = $this->_em->getRepository('Doctrine\Tests\Models\ECommerce\ECommerceProduct')->find($product->getId());
|
||||||
|
|
||||||
|
$entity = $product->getShipping();
|
||||||
|
$this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy.");
|
||||||
|
$this->assertEquals($id, $entity->getId());
|
||||||
|
$this->assertTrue($id === $entity->getId(), "Check that the id's are the same value, and type.");
|
||||||
|
$this->assertFalse($entity->__isInitialized__, "Getting the identifier doesn't initialize the proxy.");
|
||||||
|
}
|
||||||
|
|
||||||
public function testInitializeProxyOnGettingSomethingOtherThanTheIdentifier()
|
public function testInitializeProxyOnGettingSomethingOtherThanTheIdentifier()
|
||||||
{
|
{
|
||||||
$id = $this->createProduct();
|
$id = $this->createProduct();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user