Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created November 8, 2012 10:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/4038004 to your computer and use it in GitHub Desktop.
Save Ocramius/4038004 to your computer and use it in GitHub Desktop.
DCOM-96 generated proxy example
<?php
namespace Doctrine\Tests\Common\ProxyProxy\__CG__\Doctrine\Tests\Common\Proxy;
/**
* DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
*/
class LazyLoadableObject extends \Doctrine\Tests\Common\Proxy\LazyLoadableObject implements \Doctrine\Common\Proxy\Proxy
{
/**
* @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with
* three parameters, being respectively the proxy object to be initialized, the method that triggered the
* initialization process and an array of ordered parameters that were passed to that method.
* @see \Doctrine\Common\Persistence\Proxy::__setInitializer
*/
public $__initializer__;
/**
* @var \Closure the callback responsible of loading properties that need to be copied in the cloned object
* @see \Doctrine\Common\Persistence\Proxy::__setCloner
*/
public $__cloner__;
/**
* @var bool flag indicating if this object was already initialized
* @see \Doctrine\Common\Persistence\Proxy::__isInitialized
*/
public $__isInitialized__ = false;
/**
* @var array public properties to be lazy loaded (with their default values)
* @see \Doctrine\Common\Persistence\Proxy::__getLazyLoadedPublicProperties
*/
public static $lazyPublicPropertiesDefaultValues = array('publicPersistentField' => 'publicPersistentFieldValue', 'publicAssociation' => 'publicAssociationValue');
/**
* @param \Closure $initializer
* @param \Closure $cloner
*/
public function __construct($initializer = null, $cloner = null)
{
unset($this->publicPersistentField, $this->publicAssociation);
$this->__initializer__ = $initializer;
$this->__cloner__ = $cloner;
}
/**
* @param string $name
*/
public function __get($name)
{
if (array_key_exists($name, $this->__getLazyLoadedPublicProperties())) {
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', array($name));
return $this->$name;
}
trigger_error('Undefined property: ' . __CLASS__ . '::$' . $name, E_USER_NOTICE);
}
/**
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
{
if (array_key_exists($name, $this->__getLazyLoadedPublicProperties())) {
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', array($name, $value));
$this->$name = $value;
return;
}
$this->$name = $value;
}
/**
* @param string $name
* @return boolean
*/
public function __isset($name)
{
if (array_key_exists($name, $this->__getLazyLoadedPublicProperties())) {
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', array($name));
return isset($this->$name);
}
return false;
}
/**
*
*/
public function __sleep()
{
if ($this->__isInitialized__) {
return array('__isInitialized__', 'publicIdentifierField', 'protectedIdentifierField', 'publicTransientField', 'protectedTransientField', 'publicPersistentField', 'protectedPersistentField', 'publicAssociation', 'protectedAssociation');
}
return array('__isInitialized__', 'publicIdentifierField', 'protectedIdentifierField', 'publicTransientField', 'protectedTransientField', 'protectedPersistentField', 'protectedAssociation');
}
/**
*
*/
public function __wakeup()
{
if ( ! $this->__isInitialized__) {
$this->__initializer__ = function(LazyLoadableObject $proxy){
$proxy->__setInitializer(null);
$proxy->__setCloner(null);
$existingProperties = get_object_vars($proxy);
foreach ($proxy->__getLazyLoadedPublicProperties() as $property => $defaultValue) {
if ( ! array_key_exists($property, $existingProperties)) {
$proxy->$property = $defaultValue;
}
}
};
unset($this->publicPersistentField, $this->publicAssociation);
}
}
/**
*
*/
public function __clone()
{
$this->__cloner__ && $this->__cloner__->__invoke($this, '__clone', array());
}
/**
* Forces initialization of the proxy
* @private
*/
public function __load()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__load', array());
}
/**
* {@inheritDoc}
* @private
*/
public function __isInitialized()
{
return $this->__isInitialized__;
}
/**
* {@inheritDoc}
* @private
*/
public function __setInitialized($initialized)
{
$this->__isInitialized__ = $initialized;
}
/**
* {@inheritDoc}
* @private
*/
public function __setInitializer(\Closure $initializer = null)
{
$this->__initializer__ = $initializer;
}
/**
* {@inheritDoc}
* @private
*/
public function __getInitializer()
{
return $this->__initializer__;
}
/**
* {@inheritDoc}
* @private
*/
public function __setCloner(\Closure $cloner = null)
{
$this->__cloner__ = $cloner;
}
/**
* {@inheritDoc}
* @private
*/
public function __getCloner()
{
return $this->__cloner__;
}
/**
* {@inheritDoc}
* @private
*/
public function __getLazyLoadedPublicProperties()
{
return self::$lazyPublicPropertiesDefaultValues;
}
/**
* {@inheritDoc}
*/
public function getProtectedIdentifierField()
{
if ($this->__isInitialized__ === false) {
return parent::getProtectedIdentifierField();
}
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getProtectedIdentifierField', array());
return parent::getProtectedIdentifierField();
}
/**
* {@inheritDoc}
*/
public function testInitializationTriggeringMethod()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'testInitializationTriggeringMethod', array());
return parent::testInitializationTriggeringMethod();
}
/**
* {@inheritDoc}
*/
public function getProtectedAssociation()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getProtectedAssociation', array());
return parent::getProtectedAssociation();
}
/**
* {@inheritDoc}
*/
public function publicTypeHintedMethod(\stdClass $param)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'publicTypeHintedMethod', array($param));
return parent::publicTypeHintedMethod($param);
}
/**
* {@inheritDoc}
*/
public function &byRefMethod()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'byRefMethod', array());
return parent::byRefMethod();
}
/**
* {@inheritDoc}
*/
public function byRefParamMethod($thisIsNotByRef, &$thisIsByRef)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'byRefParamMethod', array($thisIsNotByRef, $thisIsByRef));
return parent::byRefParamMethod($thisIsNotByRef, $thisIsByRef);
}
}
<?php
/**
* @author Marco Pivetta <ocramius@gmail.com>
*/
class LazyLoadableObject
{
public $publicIdentifierField;
protected $protectedIdentifierField;
public $publicTransientField = 'publicTransientFieldValue';
protected $protectedTransientField = 'protectedTransientFieldValue';
public $publicPersistentField = 'publicPersistentFieldValue';
protected $protectedPersistentField = 'protectedPersistentFieldValue';
public $publicAssociation = 'publicAssociationValue';
protected $protectedAssociation = 'protectedAssociationValue';
public function getProtectedIdentifierField()
{
return $this->protectedIdentifierField;
}
public function testInitializationTriggeringMethod()
{
return 'testInitializationTriggeringMethod';
}
public function getProtectedAssociation()
{
return $this->protectedAssociation;
}
public function publicTypeHintedMethod(stdClass $param)
{
}
public function &byRefMethod()
{
}
public function byRefParamMethod($thisIsNotByRef, &$thisIsByRef)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment