Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy interface tweaks #82

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/Doctrine/Common/Persistence/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,19 @@ interface Proxy
*
* @return void
*/
public function __load();
function __load();

/**
* Check if the proxy is initialized.
*
* @return bool
*/
function __isInitialized();

/**
* Get the list of internal properties
*
* @return array
*/
function __getInternalProperties();
}
31 changes: 29 additions & 2 deletions lib/Doctrine/Common/Util/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

namespace Doctrine\Common\Util;

use Doctrine\ORM\Proxy\Proxy as ORMProxy;
use Doctrine\Common\Persistence\Proxy;

/**
* Static class containing most used debug methods.
*
Expand All @@ -41,6 +44,28 @@ final class Debug
*/
private function __construct() {}

/**
* Determine if a given variable contains a Proxy
* It has BC handling for Doctrine ORM 2.0/2.1
*
* @static
* @param $var
* @param null $initializationState if set, it is compared to the initialization state of the variable
* @return bool
*/
public static function isProxy($var, $initializationState = null)
{
if ($var instanceof Proxy) {
return null === $initializationState ? true : $var->__isInitialized() === $initializationState;
}

if ($var instanceof ORMProxy) {
return null === $initializationState ? true : $var->__isInitialized__ === $initializationState;
}

return false;
}

/**
* Prints a dump of the public, protected and private properties of $var.
*
Expand Down Expand Up @@ -94,7 +119,7 @@ public static function export($var, $maxDepth)
$return = new \stdclass();
$return->{'__CLASS__'} = get_class($var);

if ($var instanceof \Doctrine\ORM\Proxy\Proxy && ! $var->__isInitialized__) {
if (static::isProxy($var, false)) {
$reflProperty = $reflClass->getProperty('_identifier');
$reflProperty->setAccessible(true);

Expand All @@ -104,7 +129,9 @@ public static function export($var, $maxDepth)
} else {
$excludeProperties = array();

if ($var instanceof \Doctrine\ORM\Proxy\Proxy) {
if ($var instanceof Proxy) {
$excludeProperties = $var->__getInternalProperties();
} elseif ($var instanceof ORMProxy) {
$excludeProperties = array('_entityPersister', '__isInitialized__', '_identifier');
}

Expand Down