Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created November 17, 2012 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/4098721 to your computer and use it in GitHub Desktop.
Save Ocramius/4098721 to your computer and use it in GitHub Desktop.
ZF2 Lazy Service Proxy and original class
<?php
namespace Zend\ServiceManager\Proxy\__CG__\ZendTest\ServiceManager\TestAsset;
/**
* DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
*/
class LazyService extends \ZendTest\ServiceManager\TestAsset\LazyService 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();
/**
* @var object wrapped object to which method calls will be forwarded
*/
public $__wrappedObject__;
/**
* @param \Closure $initializer
* @param \Closure $cloner
*/
public function __construct($initializer = null, $cloner = null)
{
$this->__initializer__ = $initializer;
$this->__cloner__ = $cloner;
}
/**
* @param string $name
*/
public function __get($name)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', array($name));
return $this->__wrappedObject__->$name;
}
/**
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', array($name, $value));
$this->__wrappedObject__->$name = $value;
}
/**
* @param string $name
*/
public function __isset($name)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', array($name));
return isset($this->__wrappedObject__->$name);
}
/**
*
*/
public function __sleep()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__sleep', array());
return array('__isInitialized__', '__wrappedObject__');
}
/**
*
*/
public function __wakeup()
{
unset($this->counter);
}
/**
*
*/
public function __clone()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, '__clone', array());
$this->__wrappedObject__ = clone $this->__wrappedObject__;
}
/**
* 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 increment()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'increment', array());
return $this->__wrappedObject__->increment();
}
/**
* {@inheritDoc}
*/
public function count()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'count', array());
return $this->__wrappedObject__->count();
}
}
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/
namespace ZendTest\ServiceManager\TestAsset;
class LazyService
{
/**
* @var int
*/
protected $counter = 0;
/**
* Increments internal counter by 1
*/
public function increment()
{
$this->counter += 1;
}
/**
* Retrieves current internal counter
*
* @return int
*/
public function count()
{
return $this->counter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment