Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

DCOM-194 #281

Merged
merged 2 commits into from

3 participants

@Ocramius
Owner

Cleaned up version of #278 - fixes DCOM-194

@Ocramius Ocramius was assigned
@jmikola jmikola commented on the diff
lib/Doctrine/Common/Proxy/ProxyGenerator.php
((18 lines not shown))
if (empty($lazyPublicProperties) && ! $hasParentGet) {
return '';
}
- $inheritDoc = $hasParentGet ? '{@inheritDoc}' : '';
$magicGet = <<<EOT
/**
* $inheritDoc
@jmikola Owner
jmikola added a note

Should this be {$inheritDoc}?

@Ocramius Owner

@jmikola no need. I used the {$var} notation below because there's no space between {$returnReference} and __get

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

@guilhermeblanco you weren't on IRC anymore, but FYI, there's already a test to verify the parent setter existence ;)

This is only for the ByRef problem: merging.

@Ocramius Ocramius merged commit d658ec7 into master
@Ocramius Ocramius deleted the hotfix/DCOM-194 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
17 lib/Doctrine/Common/Proxy/ProxyGenerator.php
@@ -393,19 +393,30 @@ public function __construct($initializer = null, $cloner = null)
private function generateMagicGet(ClassMetadata $class)
{
$lazyPublicProperties = array_keys($this->getLazyLoadedPublicProperties($class));
- $hasParentGet = $class->getReflectionClass()->hasMethod('__get');
+ $reflectionClass = $class->getReflectionClass();
+ $hasParentGet = false;
+ $returnReference = '';
+ $inheritDoc = '';
+
+ if ($reflectionClass->hasMethod('__get')) {
+ $hasParentGet = true;
+ $inheritDoc = '{@inheritDoc}';
+
+ if ($reflectionClass->getMethod('__get')->returnsReference()) {
+ $returnReference = '& ';
+ }
+ }
if (empty($lazyPublicProperties) && ! $hasParentGet) {
return '';
}
- $inheritDoc = $hasParentGet ? '{@inheritDoc}' : '';
$magicGet = <<<EOT
/**
* $inheritDoc
@jmikola Owner
jmikola added a note

Should this be {$inheritDoc}?

@Ocramius Owner

@jmikola no need. I used the {$var} notation below because there's no space between {$returnReference} and __get

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
* @param string \$name
*/
- public function __get(\$name)
+ public function {$returnReference}__get(\$name)
{
EOT;
View
51 tests/Doctrine/Tests/Common/Proxy/MagicGetByRefClass.php
@@ -0,0 +1,51 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\Tests\Common\Proxy;
+
+use InvalidArgumentException;
+
+/**
+ * Test asset class
+ *
+ * @since 2.4
+ */
+class MagicGetByRefClass
+{
+ /**
+ * @var mixed
+ */
+ public $valueField;
+
+ /**
+ * @param string $name
+ *
+ * @return mixed
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function & __get($name)
+ {
+ if ($name === 'value') {
+ return $this->valueField;
+ }
+
+ throw new InvalidArgumentException();
+ }
+}
View
24 tests/Doctrine/Tests/Common/Proxy/ProxyMagicMethodsTest.php
@@ -94,6 +94,28 @@ function (Proxy $proxy, $method, $params) use (&$counter) {
$this->assertSame(3, $counter);
}
+ /**
+ * @group DCOM-194
+ */
+ public function testInheritedMagicGetByRef()
+ {
+ $proxyClassName = $this->generateProxyClass(__NAMESPACE__ . '\\MagicGetByRefClass');
+ /* @var $proxy \Doctrine\Tests\Common\Proxy\MagicGetByRefClass */
+ $proxy = new $proxyClassName();
+ $proxy->valueField = 123;
+ $value = & $proxy->__get('value');
+
+ $this->assertSame(123, $value);
+
+ $value = 456;
+
+ $this->assertSame(456, $proxy->__get('value'), 'Value was fetched by reference');
+
+ $this->setExpectedException('InvalidArgumentException');
+
+ $undefined = $proxy->nonExisting;
+ }
+
public function testInheritedMagicSet()
{
$proxyClassName = $this->generateProxyClass(__NAMESPACE__ . '\\MagicSetClass');
@@ -282,4 +304,4 @@ private function generateProxyClass($className)
return $proxyClassName;
}
-}
+}
Something went wrong with that request. Please try again.