Ajout du FR
Ajout du FR + correction du "functions.php"
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Magic `__wakeup` for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicWakeup extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass)
|
||||
{
|
||||
parent::__construct($originalClass, '__wakeup');
|
||||
|
||||
/* @var $publicProperties \ReflectionProperty[] */
|
||||
$publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
$unsetProperties = array();
|
||||
|
||||
foreach ($publicProperties as $publicProperty) {
|
||||
$unsetProperties[] = '$this->' . $publicProperty->getName();
|
||||
}
|
||||
|
||||
$this->setBody($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");" : '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\AccessInterceptorInterface::setMethodPrefixInterceptor}
|
||||
* for access interceptor objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class SetMethodPrefixInterceptor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $prefixInterceptor)
|
||||
{
|
||||
parent::__construct('setMethodPrefixInterceptor');
|
||||
|
||||
$interceptor = new ParameterGenerator('prefixInterceptor');
|
||||
|
||||
$interceptor->setType('Closure');
|
||||
$interceptor->setDefaultValue(null);
|
||||
$this->setParameter(new ParameterGenerator('methodName'));
|
||||
$this->setParameter($interceptor);
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('$this->' . $prefixInterceptor->getName() . '[$methodName] = $prefixInterceptor;');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\AccessInterceptorInterface::setMethodSuffixInterceptor}
|
||||
* for access interceptor objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class SetMethodSuffixInterceptor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $suffixInterceptor)
|
||||
{
|
||||
parent::__construct('setMethodSuffixInterceptor');
|
||||
|
||||
$interceptor = new ParameterGenerator('suffixInterceptor');
|
||||
|
||||
$interceptor->setType('Closure');
|
||||
$interceptor->setDefaultValue(null);
|
||||
$this->setParameter(new ParameterGenerator('methodName'));
|
||||
$this->setParameter($interceptor);
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('$this->' . $suffixInterceptor->getName() . '[$methodName] = $suffixInterceptor;');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Property that contains the interceptor for operations to be executed before method execution
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MethodPrefixInterceptors extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('methodPrefixInterceptors'));
|
||||
|
||||
$this->setDefaultValue(array());
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setDocblock('@var \\Closure[] map of interceptors to be called per-method before execution');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Property that contains the interceptor for operations to be executed after method execution
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MethodSuffixInterceptors extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('methodSuffixInterceptors'));
|
||||
|
||||
$this->setDefaultValue(array());
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setDocblock('@var \\Closure[] map of interceptors to be called per-method after execution');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Exception\UnsupportedProxiedClassException;
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* The `__construct` implementation for lazy loading proxies
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Constructor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct('__construct');
|
||||
|
||||
$localizedObject = new ParameterGenerator('localizedObject');
|
||||
$prefix = new ParameterGenerator('prefixInterceptors');
|
||||
$suffix = new ParameterGenerator('suffixInterceptors');
|
||||
|
||||
$localizedObject->setType($originalClass->getName());
|
||||
$prefix->setDefaultValue(array());
|
||||
$suffix->setDefaultValue(array());
|
||||
$prefix->setType('array');
|
||||
$suffix->setType('array');
|
||||
|
||||
$this->setParameter($localizedObject);
|
||||
$this->setParameter($prefix);
|
||||
$this->setParameter($suffix);
|
||||
|
||||
$localizedProperties = array();
|
||||
|
||||
foreach ($originalClass->getProperties() as $originalProperty) {
|
||||
if ((! method_exists('Closure', 'bind')) && $originalProperty->isPrivate()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw UnsupportedProxiedClassException::unsupportedLocalizedReflectionProperty($originalProperty);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$propertyName = $originalProperty->getName();
|
||||
|
||||
if ($originalProperty->isPrivate()) {
|
||||
$localizedProperties[] = "\\Closure::bind(function () use (\$localizedObject) {\n "
|
||||
. '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";\n"
|
||||
. '}, $this, ' . var_export($originalProperty->getDeclaringClass()->getName(), true)
|
||||
. ')->__invoke();';
|
||||
} else {
|
||||
$localizedProperties[] = '$this->' . $propertyName . ' = & $localizedObject->' . $propertyName . ";";
|
||||
}
|
||||
}
|
||||
|
||||
$this->setDocblock(
|
||||
"@override constructor to setup interceptors\n\n"
|
||||
. "@param \\" . $originalClass->getName() . " \$localizedObject\n"
|
||||
. "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n"
|
||||
. "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic"
|
||||
);
|
||||
$this->setBody(
|
||||
(empty($localizedProperties) ? '' : implode("\n\n", $localizedProperties) . "\n\n")
|
||||
. '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n"
|
||||
. '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Method with additional pre- and post- interceptor logic in the body
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InterceptedMethod extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \Zend\Code\Reflection\MethodReflection $originalMethod
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function generateMethod(
|
||||
MethodReflection $originalMethod,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
/* @var $method self */
|
||||
$method = static::fromReflection($originalMethod);
|
||||
$forwardedParams = array();
|
||||
|
||||
foreach ($originalMethod->getParameters() as $parameter) {
|
||||
$forwardedParams[] = '$' . $parameter->getName();
|
||||
}
|
||||
|
||||
$method->setDocblock('{@inheritDoc}');
|
||||
$method->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
'$returnValue = parent::'
|
||||
. $originalMethod->getName() . '(' . implode(', ', $forwardedParams) . ');',
|
||||
$method,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__clone` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicClone extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct($originalClass, '__clone');
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$originalClass->hasMethod('__clone') ? '$returnValue = parent::__clone();' : '$returnValue = null;',
|
||||
$this,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__get` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicGet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param PropertyGenerator $prefixInterceptors
|
||||
* @param PropertyGenerator $suffixInterceptors
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct($originalClass, '__get', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__get');
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if ($override) {
|
||||
$callParent = '$returnValue = & parent::__get($name);';
|
||||
} else {
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_GET,
|
||||
'name',
|
||||
null,
|
||||
null,
|
||||
'returnValue'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__isset` method for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicIsset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param PropertyGenerator $prefixInterceptors
|
||||
* @param PropertyGenerator $suffixInterceptors
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__isset');
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if ($override) {
|
||||
$callParent = '$returnValue = & parent::__isset($name);';
|
||||
} else {
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_ISSET,
|
||||
'name',
|
||||
null,
|
||||
null,
|
||||
'returnValue'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__set` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct(
|
||||
$originalClass,
|
||||
'__set',
|
||||
array(new ParameterGenerator('name'), new ParameterGenerator('value'))
|
||||
);
|
||||
|
||||
$override = $originalClass->hasMethod('__set');
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if ($override) {
|
||||
$callParent = '$returnValue = & parent::__set($name, $value);';
|
||||
} else {
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_SET,
|
||||
'name',
|
||||
'value',
|
||||
null,
|
||||
'returnValue'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__sleep` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSleep extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct($originalClass, '__sleep');
|
||||
|
||||
$callParent = $originalClass->hasMethod('__sleep')
|
||||
? '$returnValue = & parent::__sleep();'
|
||||
: '$returnValue = array_keys((array) $this);';
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__unset` method for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicUnset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param PropertyGenerator $prefixInterceptors
|
||||
* @param PropertyGenerator $suffixInterceptors
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__unset');
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if ($override) {
|
||||
$callParent = '$returnValue = & parent::__unset($name);';
|
||||
} else {
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_UNSET,
|
||||
'name',
|
||||
null,
|
||||
null,
|
||||
'returnValue'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Utility to create pre- and post- method interceptors around a given method body
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @internal - this class is just here as a small utility for this component,
|
||||
* don't use it in your own code
|
||||
*/
|
||||
class InterceptorGenerator
|
||||
{
|
||||
/**
|
||||
* @param string $methodBody the body of the previously generated code.
|
||||
* It MUST assign the return value to a variable
|
||||
* `$returnValue` instead of directly returning
|
||||
* @param \ProxyManager\Generator\MethodGenerator $method
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function createInterceptedMethodBody(
|
||||
$methodBody,
|
||||
MethodGenerator $method,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
$name = var_export($method->getName(), true);
|
||||
$prefixInterceptors = $prefixInterceptors->getName();
|
||||
$suffixInterceptors = $suffixInterceptors->getName();
|
||||
$params = array();
|
||||
|
||||
foreach ($method->getParameters() as $parameter) {
|
||||
$parameterName = $parameter->getName();
|
||||
$params[] = var_export($parameterName, true) . ' => $' . $parameter->getName();
|
||||
}
|
||||
|
||||
$paramsString = 'array(' . implode(', ', $params) . ')';
|
||||
|
||||
return "if (isset(\$this->$prefixInterceptors" . "[$name])) {\n"
|
||||
. " \$returnEarly = false;\n"
|
||||
. " \$prefixReturnValue = \$this->$prefixInterceptors" . "[$name]->__invoke("
|
||||
. "\$this, \$this, $name, $paramsString, \$returnEarly);\n\n"
|
||||
. " if (\$returnEarly) {\n"
|
||||
. " return \$prefixReturnValue;\n"
|
||||
. " }\n"
|
||||
. "}\n\n"
|
||||
. $methodBody . "\n\n"
|
||||
. "if (isset(\$this->$suffixInterceptors" . "[$name])) {\n"
|
||||
. " \$returnEarly = false;\n"
|
||||
. " \$suffixReturnValue = \$this->$suffixInterceptors" . "[$name]->__invoke("
|
||||
. "\$this, \$this, $name, $paramsString, \$returnValue, \$returnEarly);\n\n"
|
||||
. " if (\$returnEarly) {\n"
|
||||
. " return \$suffixReturnValue;\n"
|
||||
. " }\n"
|
||||
. "}\n\n"
|
||||
. "return \$returnValue;";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\ClassGeneratorUtils;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodPrefixInterceptor;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Constructor;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\InterceptedMethod;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicClone;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicGet;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSet;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicSleep;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicUnset;
|
||||
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
|
||||
use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Generator for proxies implementing {@see \ProxyManager\Proxy\ValueHolderInterface}
|
||||
* and localizing scope of the proxied object at instantiation
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class AccessInterceptorScopeLocalizerGenerator implements ProxyGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
|
||||
{
|
||||
CanProxyAssertion::assertClassCanBeProxied($originalClass, false);
|
||||
|
||||
$classGenerator->setExtendedClass($originalClass->getName());
|
||||
$classGenerator->setImplementedInterfaces(array('ProxyManager\\Proxy\\AccessInterceptorInterface'));
|
||||
$classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
|
||||
$classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodPrefixInterceptors());
|
||||
|
||||
array_map(
|
||||
function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
|
||||
},
|
||||
array_merge(
|
||||
array_map(
|
||||
function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptors) {
|
||||
return InterceptedMethod::generateMethod(
|
||||
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
},
|
||||
ProxiedMethodsFilter::getProxiedMethods(
|
||||
$originalClass,
|
||||
array('__get', '__set', '__isset', '__unset', '__clone', '__sleep')
|
||||
)
|
||||
),
|
||||
array(
|
||||
new Constructor($originalClass, $prefixInterceptors, $suffixInterceptors),
|
||||
new SetMethodPrefixInterceptor($prefixInterceptors),
|
||||
new SetMethodSuffixInterceptor($suffixInterceptors),
|
||||
new MagicGet($originalClass, $prefixInterceptors, $suffixInterceptors),
|
||||
new MagicSet($originalClass, $prefixInterceptors, $suffixInterceptors),
|
||||
new MagicIsset($originalClass, $prefixInterceptors, $suffixInterceptors),
|
||||
new MagicUnset($originalClass, $prefixInterceptors, $suffixInterceptors),
|
||||
new MagicSleep($originalClass, $prefixInterceptors, $suffixInterceptors),
|
||||
new MagicClone($originalClass, $prefixInterceptors, $suffixInterceptors),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* The `__construct` implementation for lazy loading proxies
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Constructor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $valueHolder,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct('__construct');
|
||||
|
||||
$prefix = new ParameterGenerator('prefixInterceptors');
|
||||
$suffix = new ParameterGenerator('suffixInterceptors');
|
||||
|
||||
$prefix->setDefaultValue(array());
|
||||
$suffix->setDefaultValue(array());
|
||||
$prefix->setType('array');
|
||||
$suffix->setType('array');
|
||||
|
||||
$this->setParameter(new ParameterGenerator('wrappedObject'));
|
||||
$this->setParameter($prefix);
|
||||
$this->setParameter($suffix);
|
||||
|
||||
/* @var $publicProperties \ReflectionProperty[] */
|
||||
$publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
$unsetProperties = array();
|
||||
|
||||
foreach ($publicProperties as $publicProperty) {
|
||||
$unsetProperties[] = '$this->' . $publicProperty->getName();
|
||||
}
|
||||
|
||||
$this->setDocblock(
|
||||
"@override constructor to setup interceptors\n\n"
|
||||
. "@param \\" . $originalClass->getName() . " \$wrappedObject\n"
|
||||
. "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n"
|
||||
. "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic"
|
||||
);
|
||||
$this->setBody(
|
||||
($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '')
|
||||
. '$this->' . $valueHolder->getName() . " = \$wrappedObject;\n"
|
||||
. '$this->' . $prefixInterceptors->getName() . " = \$prefixInterceptors;\n"
|
||||
. '$this->' . $suffixInterceptors->getName() . " = \$suffixInterceptors;"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Method with additional pre- and post- interceptor logic in the body
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InterceptedMethod extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \Zend\Code\Reflection\MethodReflection $originalMethod
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $valueHolderProperty
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function generateMethod(
|
||||
MethodReflection $originalMethod,
|
||||
PropertyGenerator $valueHolderProperty,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
/* @var $method self */
|
||||
$method = static::fromReflection($originalMethod);
|
||||
$forwardedParams = array();
|
||||
|
||||
foreach ($originalMethod->getParameters() as $parameter) {
|
||||
$forwardedParams[] = '$' . $parameter->getName();
|
||||
}
|
||||
|
||||
$method->setDocblock('{@inheritDoc}');
|
||||
$method->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
'$returnValue = $this->' . $valueHolderProperty->getName() . '->'
|
||||
. $originalMethod->getName() . '(' . implode(', ', $forwardedParams) . ');',
|
||||
$method,
|
||||
$valueHolderProperty,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__clone` for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicClone extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $valueHolderProperty,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
parent::__construct($originalClass, '__clone');
|
||||
|
||||
$valueHolder = $valueHolderProperty->getName();
|
||||
$prefix = $prefixInterceptors->getName();
|
||||
$suffix = $suffixInterceptors->getName();
|
||||
|
||||
$this->setBody(
|
||||
"\$this->$valueHolder = clone \$this->$valueHolder;\n\n"
|
||||
. "foreach (\$this->$prefix as \$key => \$value) {\n"
|
||||
. " \$this->$prefix" . "[\$key] = clone \$value;\n"
|
||||
. "}\n\n"
|
||||
. "foreach (\$this->$suffix as \$key => \$value) {\n"
|
||||
. " \$this->$suffix" . "[\$key] = clone \$value;\n"
|
||||
. "}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__get` for method interceptor value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicGet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $valueHolder,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__get', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__get');
|
||||
$valueHolderName = $valueHolder->getName();
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_GET,
|
||||
'name',
|
||||
'value',
|
||||
$valueHolder,
|
||||
'returnValue'
|
||||
);
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' $returnValue = & $this->' . $valueHolderName . '->$name;'
|
||||
. "\n} else {\n $callParent\n}\n\n";
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__isset` for method interceptor value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicIsset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $valueHolder,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__isset');
|
||||
$valueHolderName = $valueHolder->getName();
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_ISSET,
|
||||
'name',
|
||||
'value',
|
||||
$valueHolder,
|
||||
'returnValue'
|
||||
);
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' $returnValue = isset($this->' . $valueHolderName . '->$name);'
|
||||
. "\n} else {\n $callParent\n}\n\n";
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__set` for method interceptor value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $valueHolder,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct(
|
||||
$originalClass,
|
||||
'__set',
|
||||
array(new ParameterGenerator('name'), new ParameterGenerator('value'))
|
||||
);
|
||||
|
||||
$override = $originalClass->hasMethod('__set');
|
||||
$valueHolderName = $valueHolder->getName();
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_SET,
|
||||
'name',
|
||||
'value',
|
||||
$valueHolder,
|
||||
'returnValue'
|
||||
);
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' $returnValue = ($this->' . $valueHolderName . '->$name = $value);'
|
||||
. "\n} else {\n $callParent\n}\n\n";
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__unset` for method interceptor value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicUnset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $valueHolder,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__unset');
|
||||
$valueHolderName = $valueHolder->getName();
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
$callParent = PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_UNSET,
|
||||
'name',
|
||||
'value',
|
||||
$valueHolder,
|
||||
'returnValue'
|
||||
);
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' unset($this->' . $valueHolderName . '->$name);'
|
||||
. "\n} else {\n $callParent\n}\n\n";
|
||||
}
|
||||
|
||||
$callParent .= '$returnValue = false;';
|
||||
|
||||
$this->setBody(
|
||||
InterceptorGenerator::createInterceptedMethodBody(
|
||||
$callParent,
|
||||
$this,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Utility to create pre- and post- method interceptors around a given method body
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @internal - this class is just here as a small utility for this component,
|
||||
* don't use it in your own code
|
||||
*/
|
||||
class InterceptorGenerator
|
||||
{
|
||||
/**
|
||||
* @param string $methodBody the body of the previously generated code.
|
||||
* It MUST assign the return value to a variable
|
||||
* `$returnValue` instead of directly returning
|
||||
* @param \ProxyManager\Generator\MethodGenerator $method
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $valueHolder
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $prefixInterceptors
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $suffixInterceptors
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function createInterceptedMethodBody(
|
||||
$methodBody,
|
||||
MethodGenerator $method,
|
||||
PropertyGenerator $valueHolder,
|
||||
PropertyGenerator $prefixInterceptors,
|
||||
PropertyGenerator $suffixInterceptors
|
||||
) {
|
||||
$name = var_export($method->getName(), true);
|
||||
$valueHolder = $valueHolder->getName();
|
||||
$prefixInterceptors = $prefixInterceptors->getName();
|
||||
$suffixInterceptors = $suffixInterceptors->getName();
|
||||
$params = array();
|
||||
|
||||
foreach ($method->getParameters() as $parameter) {
|
||||
$parameterName = $parameter->getName();
|
||||
$params[] = var_export($parameterName, true) . ' => $' . $parameter->getName();
|
||||
}
|
||||
|
||||
$paramsString = 'array(' . implode(', ', $params) . ')';
|
||||
|
||||
return "if (isset(\$this->$prefixInterceptors" . "[$name])) {\n"
|
||||
. " \$returnEarly = false;\n"
|
||||
. " \$prefixReturnValue = \$this->$prefixInterceptors" . "[$name]->__invoke("
|
||||
. "\$this, \$this->$valueHolder, $name, $paramsString, \$returnEarly);\n\n"
|
||||
. " if (\$returnEarly) {\n"
|
||||
. " return \$prefixReturnValue;\n"
|
||||
. " }\n"
|
||||
. "}\n\n"
|
||||
. $methodBody . "\n\n"
|
||||
. "if (isset(\$this->$suffixInterceptors" . "[$name])) {\n"
|
||||
. " \$returnEarly = false;\n"
|
||||
. " \$suffixReturnValue = \$this->$suffixInterceptors" . "[$name]->__invoke("
|
||||
. "\$this, \$this->$valueHolder, $name, $paramsString, \$returnValue, \$returnEarly);\n\n"
|
||||
. " if (\$returnEarly) {\n"
|
||||
. " return \$suffixReturnValue;\n"
|
||||
. " }\n"
|
||||
. "}\n\n"
|
||||
. "return \$returnValue;";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\ClassGeneratorUtils;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodPrefixInterceptor;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\SetMethodSuffixInterceptor;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodPrefixInterceptors;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\PropertyGenerator\MethodSuffixInterceptors;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Constructor;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\InterceptedMethod;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicClone;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicGet;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicIsset;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicSet;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\MagicUnset;
|
||||
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
|
||||
use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue;
|
||||
use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\MagicSleep;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Generator for proxies implementing {@see \ProxyManager\Proxy\ValueHolderInterface}
|
||||
* and {@see \ProxyManager\Proxy\AccessInterceptorInterface}
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class AccessInterceptorValueHolderGenerator implements ProxyGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
|
||||
{
|
||||
CanProxyAssertion::assertClassCanBeProxied($originalClass);
|
||||
|
||||
$publicProperties = new PublicPropertiesMap($originalClass);
|
||||
$interfaces = array(
|
||||
'ProxyManager\\Proxy\\AccessInterceptorInterface',
|
||||
'ProxyManager\\Proxy\\ValueHolderInterface',
|
||||
);
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$interfaces[] = $originalClass->getName();
|
||||
} else {
|
||||
$classGenerator->setExtendedClass($originalClass->getName());
|
||||
}
|
||||
|
||||
$classGenerator->setImplementedInterfaces($interfaces);
|
||||
$classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty());
|
||||
$classGenerator->addPropertyFromGenerator($prefixInterceptors = new MethodPrefixInterceptors());
|
||||
$classGenerator->addPropertyFromGenerator($suffixInterceptors = new MethodSuffixInterceptors());
|
||||
$classGenerator->addPropertyFromGenerator($publicProperties);
|
||||
|
||||
array_map(
|
||||
function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
|
||||
},
|
||||
array_merge(
|
||||
array_map(
|
||||
function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptors, $valueHolder) {
|
||||
return InterceptedMethod::generateMethod(
|
||||
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors
|
||||
);
|
||||
},
|
||||
ProxiedMethodsFilter::getProxiedMethods($originalClass)
|
||||
),
|
||||
array(
|
||||
new Constructor($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors),
|
||||
new GetWrappedValueHolderValue($valueHolder),
|
||||
new SetMethodPrefixInterceptor($prefixInterceptors),
|
||||
new SetMethodSuffixInterceptor($suffixInterceptors),
|
||||
new MagicGet(
|
||||
$originalClass,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
),
|
||||
new MagicSet(
|
||||
$originalClass,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
),
|
||||
new MagicIsset(
|
||||
$originalClass,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
),
|
||||
new MagicUnset(
|
||||
$originalClass,
|
||||
$valueHolder,
|
||||
$prefixInterceptors,
|
||||
$suffixInterceptors,
|
||||
$publicProperties
|
||||
),
|
||||
new MagicClone($originalClass, $valueHolder, $prefixInterceptors, $suffixInterceptors),
|
||||
new MagicSleep($originalClass, $valueHolder),
|
||||
new MagicWakeup($originalClass, $valueHolder),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
102
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Assertion/CanProxyAssertion.php
vendored
Normal file
102
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Assertion/CanProxyAssertion.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\Assertion;
|
||||
|
||||
use BadMethodCallException;
|
||||
use ProxyManager\Exception\InvalidProxiedClassException;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Assertion that verifies that a class can be proxied
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
final class CanProxyAssertion
|
||||
{
|
||||
/**
|
||||
* Disabled constructor: not meant to be instantiated
|
||||
*
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
throw new BadMethodCallException('Unsupported constructor.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param bool $allowInterfaces
|
||||
*
|
||||
* @throws InvalidProxiedClassException
|
||||
*/
|
||||
public static function assertClassCanBeProxied(ReflectionClass $originalClass, $allowInterfaces = true)
|
||||
{
|
||||
self::isNotFinal($originalClass);
|
||||
self::hasNoAbstractProtectedMethods($originalClass);
|
||||
|
||||
if (! $allowInterfaces) {
|
||||
self::isNotInterface($originalClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
*
|
||||
* @throws InvalidProxiedClassException
|
||||
*/
|
||||
private static function isNotFinal(ReflectionClass $originalClass)
|
||||
{
|
||||
if ($originalClass->isFinal()) {
|
||||
throw InvalidProxiedClassException::finalClassNotSupported($originalClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
*
|
||||
* @throws InvalidProxiedClassException
|
||||
*/
|
||||
private static function hasNoAbstractProtectedMethods(ReflectionClass $originalClass)
|
||||
{
|
||||
$protectedAbstract = array_filter(
|
||||
$originalClass->getMethods(),
|
||||
function (ReflectionMethod $method) {
|
||||
return $method->isAbstract() && $method->isProtected();
|
||||
}
|
||||
);
|
||||
|
||||
if ($protectedAbstract) {
|
||||
throw InvalidProxiedClassException::abstractProtectedMethodsNotSupported($originalClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
*
|
||||
* @throws InvalidProxiedClassException
|
||||
*/
|
||||
private static function isNotInterface(ReflectionClass $originalClass)
|
||||
{
|
||||
if ($originalClass->isInterface()) {
|
||||
throw InvalidProxiedClassException::interfaceNotSupported($originalClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* The `__construct` implementation for lazy loading proxies
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Constructor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, PropertyGenerator $initializerProperty)
|
||||
{
|
||||
parent::__construct('__construct');
|
||||
|
||||
$this->setParameter(new ParameterGenerator('initializer'));
|
||||
|
||||
/* @var $publicProperties \ReflectionProperty[] */
|
||||
$publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
$unsetProperties = array();
|
||||
|
||||
foreach ($publicProperties as $publicProperty) {
|
||||
$unsetProperties[] = '$this->' . $publicProperty->getName();
|
||||
}
|
||||
|
||||
$this->setDocblock("@override constructor for lazy initialization\n\n@param \\Closure|null \$initializer");
|
||||
$this->setBody(
|
||||
($unsetProperties ? 'unset(' . implode(', ', $unsetProperties) . ");\n\n" : '')
|
||||
. '$this->' . $initializerProperty->getName() . ' = $initializer;'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::isProxyInitialized}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class CallInitializer extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $publicPropsDefaults,
|
||||
PropertyGenerator $initTracker
|
||||
) {
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('callInitializer'));
|
||||
$this->setDocblock("Triggers initialization logic for this ghost object");
|
||||
|
||||
$this->setParameters(array(
|
||||
new ParameterGenerator('methodName'),
|
||||
new ParameterGenerator('parameters', 'array'),
|
||||
));
|
||||
|
||||
$this->setVisibility(static::VISIBILITY_PRIVATE);
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
$initialization = $initTracker->getName();
|
||||
|
||||
$this->setBody(
|
||||
'if ($this->' . $initialization . ' || ! $this->' . $initializer . ') {' . "\n return;\n}\n\n"
|
||||
. "\$this->" . $initialization . " = true;\n\n"
|
||||
. "foreach (self::\$" . $publicPropsDefaults->getName() . " as \$key => \$default) {\n"
|
||||
. " \$this->\$key = \$default;\n"
|
||||
. "}\n\n"
|
||||
. '$this->' . $initializer . '->__invoke'
|
||||
. '($this, $methodName, $parameters, $this->' . $initializer . ');' . "\n\n"
|
||||
. "\$this->" . $initialization . " = false;"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::getProxyInitializer}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class GetProxyInitializer extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $initializerProperty)
|
||||
{
|
||||
parent::__construct('getProxyInitializer');
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('return $this->' . $initializerProperty->getName() . ';');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator as ZendMethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::initializeProxy}
|
||||
* for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InitializeProxy extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $initializerProperty, ZendMethodGenerator $callInitializer)
|
||||
{
|
||||
parent::__construct('initializeProxy');
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
|
||||
$this->setBody(
|
||||
'return $this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
|
||||
. '(\'initializeProxy\', array());'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::isProxyInitialized}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class IsProxyInitialized extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $initializerProperty)
|
||||
{
|
||||
parent::__construct('isProxyInitialized');
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('return ! $this->' . $initializerProperty->getName() . ';');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator as ZendMethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Method decorator for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class LazyLoadingMethodInterceptor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \Zend\Code\Reflection\MethodReflection $originalMethod
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $initializerProperty
|
||||
* @param \Zend\Code\Generator\MethodGenerator $callInitializer
|
||||
*
|
||||
* @return LazyLoadingMethodInterceptor|static
|
||||
*/
|
||||
public static function generateMethod(
|
||||
MethodReflection $originalMethod,
|
||||
PropertyGenerator $initializerProperty,
|
||||
ZendMethodGenerator $callInitializer
|
||||
) {
|
||||
/* @var $method self */
|
||||
$method = static::fromReflection($originalMethod);
|
||||
$parameters = $originalMethod->getParameters();
|
||||
$methodName = $originalMethod->getName();
|
||||
$initializerParams = array();
|
||||
$forwardedParams = array();
|
||||
|
||||
foreach ($parameters as $parameter) {
|
||||
$parameterName = $parameter->getName();
|
||||
$initializerParams[] = var_export($parameterName, true) . ' => $' . $parameterName;
|
||||
$forwardedParams[] = '$' . $parameterName;
|
||||
}
|
||||
|
||||
$method->setBody(
|
||||
'$this->' . $initializerProperty->getName()
|
||||
. ' && $this->' . $callInitializer->getName()
|
||||
. '(' . var_export($methodName, true)
|
||||
. ', array(' . implode(', ', $initializerParams) . "));\n\n"
|
||||
. 'return parent::'
|
||||
. $methodName . '(' . implode(', ', $forwardedParams) . ');'
|
||||
);
|
||||
$method->setDocblock('{@inheritDoc}');
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__clone` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicClone extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
MethodGenerator $callInitializer
|
||||
) {
|
||||
parent::__construct($originalClass, '__clone');
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
|
||||
. '(\'__clone\', array());'
|
||||
. ($originalClass->hasMethod('__clone') ? "\n\nparent::__clone();" : '')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__get` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicGet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $initializerProperty
|
||||
* @param \Zend\Code\Generator\MethodGenerator $callInitializer
|
||||
* @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
MethodGenerator $callInitializer,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__get', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__get');
|
||||
$callParent = '';
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' return $this->$name;'
|
||||
. "\n}\n\n";
|
||||
}
|
||||
|
||||
if ($override) {
|
||||
$callParent .= 'return parent::__get($name);';
|
||||
} else {
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_GET,
|
||||
'name'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
|
||||
. '(\'__get\', array(\'name\' => $name));'
|
||||
. "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__isset` method for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicIsset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $initializerProperty
|
||||
* @param \Zend\Code\Generator\MethodGenerator $callInitializer
|
||||
* @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
MethodGenerator $callInitializer,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__isset');
|
||||
$callParent = '';
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' return isset($this->$name);'
|
||||
. "\n}\n\n";
|
||||
}
|
||||
|
||||
if ($override) {
|
||||
$callParent .= 'return parent::__isset($name);';
|
||||
} else {
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_ISSET,
|
||||
'name'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
|
||||
. '(\'__isset\', array(\'name\' => $name));'
|
||||
. "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__set` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $initializerProperty
|
||||
* @param \Zend\Code\Generator\MethodGenerator $callInitializer
|
||||
* @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
MethodGenerator $callInitializer,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct(
|
||||
$originalClass,
|
||||
'__set',
|
||||
array(new ParameterGenerator('name'), new ParameterGenerator('value'))
|
||||
);
|
||||
|
||||
$override = $originalClass->hasMethod('__set');
|
||||
$callParent = '';
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' return ($this->$name = $value);'
|
||||
. "\n}\n\n";
|
||||
}
|
||||
|
||||
if ($override) {
|
||||
$callParent .= 'return parent::__set($name, $value);';
|
||||
} else {
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_SET,
|
||||
'name',
|
||||
'value'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
|
||||
. '(\'__set\', array(\'name\' => $name, \'value\' => $value));' . "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__sleep` for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSleep extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
MethodGenerator $callInitializer
|
||||
) {
|
||||
parent::__construct($originalClass, '__sleep');
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
|
||||
. '(\'__sleep\', array());' . "\n\n"
|
||||
. ($originalClass->hasMethod('__sleep') ? 'return parent::__sleep();' : 'return array_keys((array) $this);')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__unset` method for lazy loading ghost objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicUnset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $initializerProperty
|
||||
* @param \Zend\Code\Generator\MethodGenerator $callInitializer
|
||||
* @param \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap $publicProperties
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
MethodGenerator $callInitializer,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name')));
|
||||
|
||||
$override = $originalClass->hasMethod('__unset');
|
||||
$callParent = '';
|
||||
|
||||
$this->setDocblock(($override ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' unset($this->$name);'
|
||||
. "\n\n return;"
|
||||
. "\n}\n\n";
|
||||
}
|
||||
|
||||
if ($override) {
|
||||
$callParent .= "return parent::__unset(\$name);";
|
||||
} else {
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_UNSET,
|
||||
'name'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
|
||||
. '(\'__unset\', array(\'name\' => $name));'
|
||||
. "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::setProxyInitializer}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class SetProxyInitializer extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $initializerProperty)
|
||||
{
|
||||
parent::__construct('setProxyInitializer');
|
||||
|
||||
$initializerParameter = new ParameterGenerator('initializer');
|
||||
|
||||
$initializerParameter->setType('Closure');
|
||||
$initializerParameter->setDefaultValue(null);
|
||||
$this->setParameter($initializerParameter);
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Property that contains the initializer for a lazy object
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InitializationTracker extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializationTracker'));
|
||||
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setDocblock('@var bool tracks initialization status - true while the object is initializing');
|
||||
$this->setDefaultValue(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Property that contains the initializer for a lazy object
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InitializerProperty extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializer'));
|
||||
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setDocblock('@var \\Closure|null initializer responsible for generating the wrapped object');
|
||||
}
|
||||
}
|
||||
114
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php
vendored
Normal file
114
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingGhostGenerator.php
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\ClassGeneratorUtils;
|
||||
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
|
||||
use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\IsProxyInitialized;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\LazyLoadingMethodInterceptor;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicClone;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSleep;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializerProperty;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesDefaults;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Generator for proxies implementing {@see \ProxyManager\Proxy\GhostObjectInterface}
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class LazyLoadingGhostGenerator implements ProxyGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
|
||||
{
|
||||
CanProxyAssertion::assertClassCanBeProxied($originalClass);
|
||||
|
||||
$interfaces = array('ProxyManager\\Proxy\\GhostObjectInterface');
|
||||
$publicProperties = new PublicPropertiesMap($originalClass);
|
||||
$publicPropsDefaults = new PublicPropertiesDefaults($originalClass);
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$interfaces[] = $originalClass->getName();
|
||||
} else {
|
||||
$classGenerator->setExtendedClass($originalClass->getName());
|
||||
}
|
||||
|
||||
$classGenerator->setImplementedInterfaces($interfaces);
|
||||
$classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
|
||||
$classGenerator->addPropertyFromGenerator($initializationTracker = new InitializationTracker());
|
||||
$classGenerator->addPropertyFromGenerator($publicProperties);
|
||||
$classGenerator->addPropertyFromGenerator($publicPropsDefaults);
|
||||
|
||||
$init = new CallInitializer($initializer, $publicPropsDefaults, $initializationTracker);
|
||||
|
||||
array_map(
|
||||
function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
|
||||
},
|
||||
array_merge(
|
||||
array_map(
|
||||
function (ReflectionMethod $method) use ($initializer, $init) {
|
||||
return LazyLoadingMethodInterceptor::generateMethod(
|
||||
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
|
||||
$initializer,
|
||||
$init
|
||||
);
|
||||
},
|
||||
ProxiedMethodsFilter::getProxiedMethods($originalClass)
|
||||
),
|
||||
array(
|
||||
$init,
|
||||
new Constructor($originalClass, $initializer),
|
||||
new MagicGet($originalClass, $initializer, $init, $publicProperties),
|
||||
new MagicSet($originalClass, $initializer, $init, $publicProperties),
|
||||
new MagicIsset($originalClass, $initializer, $init, $publicProperties),
|
||||
new MagicUnset($originalClass, $initializer, $init, $publicProperties),
|
||||
new MagicClone($originalClass, $initializer, $init, $publicProperties),
|
||||
new MagicSleep($originalClass, $initializer, $init, $publicProperties),
|
||||
new SetProxyInitializer($initializer),
|
||||
new GetProxyInitializer($initializer),
|
||||
new InitializeProxy($initializer, $init),
|
||||
new IsProxyInitialized($initializer),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::getProxyInitializer}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class GetProxyInitializer extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $initializerProperty)
|
||||
{
|
||||
parent::__construct('getProxyInitializer');
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('return $this->' . $initializerProperty->getName() . ';');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::initializeProxy}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InitializeProxy extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $valueHolderProperty)
|
||||
{
|
||||
parent::__construct('initializeProxy');
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
|
||||
$this->setBody(
|
||||
'return $this->' . $initializer . ' && $this->' . $initializer
|
||||
. '->__invoke($this->' . $valueHolderProperty->getName()
|
||||
. ', $this, \'initializeProxy\', array(), $this->' . $initializer . ');'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::isProxyInitialized}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class IsProxyInitialized extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $valueHolderProperty)
|
||||
{
|
||||
parent::__construct('isProxyInitialized');
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('return null !== $this->' . $valueHolderProperty->getName() . ';');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Method decorator for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class LazyLoadingMethodInterceptor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \Zend\Code\Reflection\MethodReflection $originalMethod
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $initializerProperty
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $valueHolderProperty
|
||||
*
|
||||
* @return LazyLoadingMethodInterceptor|static
|
||||
*/
|
||||
public static function generateMethod(
|
||||
MethodReflection $originalMethod,
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $valueHolderProperty
|
||||
) {
|
||||
/* @var $method self */
|
||||
$method = static::fromReflection($originalMethod);
|
||||
$initializerName = $initializerProperty->getName();
|
||||
$valueHolderName = $valueHolderProperty->getName();
|
||||
$parameters = $originalMethod->getParameters();
|
||||
$methodName = $originalMethod->getName();
|
||||
$initializerParams = array();
|
||||
$forwardedParams = array();
|
||||
|
||||
foreach ($parameters as $parameter) {
|
||||
$parameterName = $parameter->getName();
|
||||
$initializerParams[] = var_export($parameterName, true) . ' => $' . $parameterName;
|
||||
$forwardedParams[] = '$' . $parameterName;
|
||||
}
|
||||
|
||||
$method->setBody(
|
||||
'$this->' . $initializerName
|
||||
. ' && $this->' . $initializerName
|
||||
. '->__invoke($this->' . $valueHolderName . ', $this, ' . var_export($methodName, true)
|
||||
. ', array(' . implode(', ', $initializerParams) . '), $this->' . $initializerName . ");\n\n"
|
||||
. 'return $this->' . $valueHolderName . '->'
|
||||
. $methodName . '(' . implode(', ', $forwardedParams) . ');'
|
||||
);
|
||||
$method->setDocblock('{@inheritDoc}');
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__clone` for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicClone extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $valueHolderProperty
|
||||
) {
|
||||
parent::__construct($originalClass, '__clone');
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
$valueHolder = $valueHolderProperty->getName();
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializer . ' && $this->' . $initializer
|
||||
. '->__invoke($this->' . $valueHolder
|
||||
. ', $this, \'__clone\', array(), $this->' . $initializer . ');' . "\n\n"
|
||||
. '$this->' . $valueHolder . ' = clone $this->' . $valueHolder . ';'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__get` for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicGet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $valueHolderProperty,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__get', array(new ParameterGenerator('name')));
|
||||
|
||||
$this->setDocblock(($originalClass->hasMethod('__get') ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
$valueHolder = $valueHolderProperty->getName();
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' return $this->' . $valueHolder . '->$name;'
|
||||
. "\n}\n\n";
|
||||
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_GET,
|
||||
'name',
|
||||
null,
|
||||
$valueHolderProperty
|
||||
);
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializer . ' && $this->' . $initializer
|
||||
. '->__invoke($this->' . $valueHolder . ', $this, \'__get\', array(\'name\' => $name), $this->'
|
||||
. $initializer . ');'
|
||||
. "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__isset` method for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicIsset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $valueHolderProperty,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name')));
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
$valueHolder = $valueHolderProperty->getName();
|
||||
$callParent = '';
|
||||
|
||||
$this->setDocblock(($originalClass->hasMethod('__isset') ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' return isset($this->' . $valueHolder . '->$name);'
|
||||
. "\n}\n\n";
|
||||
}
|
||||
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_ISSET,
|
||||
'name',
|
||||
null,
|
||||
$valueHolderProperty
|
||||
);
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializer . ' && $this->' . $initializer
|
||||
. '->__invoke($this->' . $valueHolder . ', $this, \'__isset\', array(\'name\' => $name), $this->'
|
||||
. $initializer . ');' . "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__set` for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $valueHolderProperty,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct(
|
||||
$originalClass,
|
||||
'__set',
|
||||
array(new ParameterGenerator('name'), new ParameterGenerator('value'))
|
||||
);
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
$valueHolder = $valueHolderProperty->getName();
|
||||
$callParent = '';
|
||||
|
||||
$this->setDocblock(
|
||||
($originalClass->hasMethod('__set') ? "{@inheritDoc}\n" : '') . "@param string \$name\n@param mixed \$value"
|
||||
);
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' return ($this->' . $valueHolder . '->$name = $value);'
|
||||
. "\n}\n\n";
|
||||
}
|
||||
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_SET,
|
||||
'name',
|
||||
'value',
|
||||
$valueHolderProperty
|
||||
);
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializer . ' && $this->' . $initializer
|
||||
. '->__invoke($this->' . $valueHolder . ', $this, '
|
||||
. '\'__set\', array(\'name\' => $name, \'value\' => $value), $this->' . $initializer . ');'
|
||||
. "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__sleep` for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSleep extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $valueHolderProperty
|
||||
) {
|
||||
parent::__construct($originalClass, '__sleep');
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
$valueHolder = $valueHolderProperty->getName();
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializer . ' && $this->' . $initializer
|
||||
. '->__invoke($this->' . $valueHolder . ', $this, \'__sleep\', array(), $this->'
|
||||
. $initializer . ');' . "\n\n"
|
||||
. 'return array(' . var_export($valueHolder, true) . ');'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__unset` method for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicUnset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
ReflectionClass $originalClass,
|
||||
PropertyGenerator $initializerProperty,
|
||||
PropertyGenerator $valueHolderProperty,
|
||||
PublicPropertiesMap $publicProperties
|
||||
) {
|
||||
parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name')));
|
||||
|
||||
$initializer = $initializerProperty->getName();
|
||||
$valueHolder = $valueHolderProperty->getName();
|
||||
$callParent = '';
|
||||
|
||||
$this->setDocblock(($originalClass->hasMethod('__isset') ? "{@inheritDoc}\n" : '') . '@param string $name');
|
||||
|
||||
if (! $publicProperties->isEmpty()) {
|
||||
$callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n"
|
||||
. ' unset($this->' . $valueHolder . '->$name);' . "\n\n return;"
|
||||
. "\n}\n\n";
|
||||
}
|
||||
|
||||
$callParent .= PublicScopeSimulator::getPublicAccessSimulationCode(
|
||||
PublicScopeSimulator::OPERATION_UNSET,
|
||||
'name',
|
||||
null,
|
||||
$valueHolderProperty
|
||||
);
|
||||
|
||||
$this->setBody(
|
||||
'$this->' . $initializer . ' && $this->' . $initializer
|
||||
. '->__invoke($this->' . $valueHolder . ', $this, \'__unset\', array(\'name\' => $name), $this->'
|
||||
. $initializer . ');' . "\n\n" . $callParent
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\LazyLoadingInterface::setProxyInitializer}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class SetProxyInitializer extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $initializerProperty)
|
||||
{
|
||||
parent::__construct('setProxyInitializer');
|
||||
|
||||
$initializerParameter = new ParameterGenerator('initializer');
|
||||
|
||||
$initializerParameter->setType('Closure');
|
||||
$initializerParameter->setDefaultValue(null);
|
||||
$this->setParameter($initializerParameter);
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Property that contains the initializer for a lazy object
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InitializerProperty extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializer'));
|
||||
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setDocblock('@var \\Closure|null initializer responsible for generating the wrapped object');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Property that contains the wrapped value of a lazy loading proxy
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class ValueHolderProperty extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('valueHolder'));
|
||||
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setDocblock('@var \\Closure|null initializer responsible for generating the wrapped object');
|
||||
}
|
||||
}
|
||||
111
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php
vendored
Normal file
111
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\ClassGeneratorUtils;
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup;
|
||||
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
|
||||
use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicClone;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicGet;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSet;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSleep;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicUnset;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty;
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty;
|
||||
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
|
||||
use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
|
||||
use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Generator for proxies implementing {@see \ProxyManager\Proxy\VirtualProxyInterface}
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class LazyLoadingValueHolderGenerator implements ProxyGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
|
||||
{
|
||||
CanProxyAssertion::assertClassCanBeProxied($originalClass);
|
||||
|
||||
$interfaces = array('ProxyManager\\Proxy\\VirtualProxyInterface');
|
||||
$publicProperties = new PublicPropertiesMap($originalClass);
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$interfaces[] = $originalClass->getName();
|
||||
} else {
|
||||
$classGenerator->setExtendedClass($originalClass->getName());
|
||||
}
|
||||
|
||||
$classGenerator->setImplementedInterfaces($interfaces);
|
||||
$classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty());
|
||||
$classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
|
||||
$classGenerator->addPropertyFromGenerator($publicProperties);
|
||||
|
||||
array_map(
|
||||
function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
|
||||
},
|
||||
array_merge(
|
||||
array_map(
|
||||
function (ReflectionMethod $method) use ($initializer, $valueHolder) {
|
||||
return LazyLoadingMethodInterceptor::generateMethod(
|
||||
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
|
||||
$initializer,
|
||||
$valueHolder
|
||||
);
|
||||
},
|
||||
ProxiedMethodsFilter::getProxiedMethods($originalClass)
|
||||
),
|
||||
array(
|
||||
new Constructor($originalClass, $initializer),
|
||||
new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties),
|
||||
new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties),
|
||||
new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties),
|
||||
new MagicUnset($originalClass, $initializer, $valueHolder, $publicProperties),
|
||||
new MagicClone($originalClass, $initializer, $valueHolder),
|
||||
new MagicSleep($originalClass, $initializer, $valueHolder),
|
||||
new MagicWakeup($originalClass),
|
||||
new SetProxyInitializer($initializer),
|
||||
new GetProxyInitializer($initializer),
|
||||
new InitializeProxy($initializer, $valueHolder),
|
||||
new IsProxyInitialized($valueHolder),
|
||||
new GetWrappedValueHolderValue($valueHolder),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\NullObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* The `__construct` implementation for null object proxies
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Constructor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ReflectionClass $originalClass Reflection of the class to proxy
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass)
|
||||
{
|
||||
parent::__construct('__construct');
|
||||
|
||||
/* @var $publicProperties \ReflectionProperty[] */
|
||||
$publicProperties = $originalClass->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
$nullableProperties = array();
|
||||
|
||||
foreach ($publicProperties as $publicProperty) {
|
||||
$nullableProperties[] = '$this->' . $publicProperty->getName() . ' = null;';
|
||||
}
|
||||
|
||||
$this->setDocblock("@override constructor for null object initialization");
|
||||
if ($nullableProperties) {
|
||||
$this->setBody(implode("\n", $nullableProperties));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\NullObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Method decorator for null objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class NullObjectMethodInterceptor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \Zend\Code\Reflection\MethodReflection $originalMethod
|
||||
*
|
||||
* @return NullObjectMethodInterceptor|static
|
||||
*/
|
||||
public static function generateMethod(MethodReflection $originalMethod)
|
||||
{
|
||||
/* @var $method self */
|
||||
$method = static::fromReflection($originalMethod);
|
||||
|
||||
if ($originalMethod->returnsReference()) {
|
||||
$reference = UniqueIdentifierGenerator::getIdentifier('ref');
|
||||
|
||||
$method->setBody("\$$reference = null;\nreturn \$$reference;");
|
||||
} else {
|
||||
$method->setBody('');
|
||||
}
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
65
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php
vendored
Normal file
65
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/NullObjectGenerator.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\ClassGeneratorUtils;
|
||||
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
|
||||
use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\Constructor;
|
||||
use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor;
|
||||
use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Generator for proxies implementing {@see \ProxyManager\Proxy\NullObjectInterface}
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class NullObjectGenerator implements ProxyGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
|
||||
{
|
||||
CanProxyAssertion::assertClassCanBeProxied($originalClass);
|
||||
|
||||
$interfaces = array('ProxyManager\\Proxy\\NullObjectInterface');
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$interfaces[] = $originalClass->getName();
|
||||
}
|
||||
|
||||
$classGenerator->setImplementedInterfaces($interfaces);
|
||||
|
||||
foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
|
||||
$classGenerator->addMethodFromGenerator(
|
||||
NullObjectMethodInterceptor::generateMethod(
|
||||
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, new Constructor($originalClass));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Map of public properties that exist in the class being proxied
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class PublicPropertiesDefaults extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* @var bool[]
|
||||
*/
|
||||
private $publicProperties = array();
|
||||
|
||||
/**
|
||||
* @param \ReflectionClass $originalClass
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass)
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('publicPropertiesDefaults'));
|
||||
|
||||
$defaults = $originalClass->getDefaultProperties();
|
||||
|
||||
foreach ($originalClass->getProperties(ReflectionProperty::IS_PUBLIC) as $publicProperty) {
|
||||
$name = $publicProperty->getName();
|
||||
$this->publicProperties[$name] = $defaults[$name];
|
||||
}
|
||||
|
||||
$this->setDefaultValue($this->publicProperties);
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setStatic(true);
|
||||
$this->setDocblock('@var mixed[] map of default property values of the parent class');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Map of public properties that exist in the class being proxied
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class PublicPropertiesMap extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* @var bool[]
|
||||
*/
|
||||
private $publicProperties = array();
|
||||
|
||||
/**
|
||||
* @param \ReflectionClass $originalClass
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass)
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('publicProperties'));
|
||||
|
||||
foreach ($originalClass->getProperties(ReflectionProperty::IS_PUBLIC) as $publicProperty) {
|
||||
$this->publicProperties[$publicProperty->getName()] = true;
|
||||
}
|
||||
|
||||
$this->setDefaultValue($this->publicProperties);
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setStatic(true);
|
||||
$this->setDocblock('@var bool[] map of public properties of the parent class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool whether there are no public properties
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->publicProperties);
|
||||
}
|
||||
}
|
||||
42
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ProxyGeneratorInterface.php
vendored
Normal file
42
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/ProxyGeneratorInterface.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator;
|
||||
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
|
||||
/**
|
||||
* Base interface for proxy generators - describes how a proxy generator should use
|
||||
* reflection classes to modify given class generators
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface ProxyGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* Apply modifications to the provided $classGenerator to proxy logic from $originalClass
|
||||
*
|
||||
* @param \ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\ClassGenerator $classGenerator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* The `__construct` implementation for remote object proxies
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Constructor extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ReflectionClass $originalClass Reflection of the class to proxy
|
||||
* @param PropertyGenerator $adapter Adapter property
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapter)
|
||||
{
|
||||
parent::__construct('__construct');
|
||||
|
||||
$adapterName = $adapter->getName();
|
||||
|
||||
$this->setParameter(new ParameterGenerator($adapterName, 'ProxyManager\Factory\RemoteObject\AdapterInterface'));
|
||||
|
||||
$this->setDocblock(
|
||||
'@override constructor for remote object control\n\n'
|
||||
. '@param \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface \$adapter'
|
||||
);
|
||||
|
||||
$body = '$this->' . $adapterName . ' = $' . $adapterName . ';';
|
||||
|
||||
foreach ($originalClass->getProperties() as $property) {
|
||||
if ($property->isPublic() && ! $property->isStatic()) {
|
||||
$body .= "\nunset(\$this->" . $property->getName() . ');';
|
||||
}
|
||||
}
|
||||
|
||||
$this->setBody($body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__get` for remote objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicGet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $adapterProperty
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty)
|
||||
{
|
||||
parent::__construct($originalClass, '__get', array(new ParameterGenerator('name')));
|
||||
|
||||
$this->setDocblock('@param string $name');
|
||||
$this->setBody(
|
||||
'$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true)
|
||||
. ', \'__get\', array($name));' . "\n\n" . 'return $return;'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__isset` method for remote objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicIsset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $adapterProperty
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty)
|
||||
{
|
||||
parent::__construct($originalClass, '__isset', array(new ParameterGenerator('name')));
|
||||
|
||||
$this->setDocblock('@param string $name');
|
||||
$this->setBody(
|
||||
'$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true)
|
||||
. ', \'__isset\', array($name));' . "\n\n"
|
||||
. 'return $return;'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__set` for remote objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSet extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $adapterProperty
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty)
|
||||
{
|
||||
parent::__construct(
|
||||
$originalClass,
|
||||
'__set',
|
||||
array(new ParameterGenerator('name'), new ParameterGenerator('value'))
|
||||
);
|
||||
|
||||
$this->setDocblock('@param string \$name\n@param mixed \$value');
|
||||
$this->setBody(
|
||||
'$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true)
|
||||
. ', \'__set\', array($name, $value));' . "\n\n"
|
||||
. 'return $return;'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ProxyManager\Generator\ParameterGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__unset` method for remote objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicUnset extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param PropertyGenerator $adapterProperty
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, PropertyGenerator $adapterProperty)
|
||||
{
|
||||
parent::__construct($originalClass, '__unset', array(new ParameterGenerator('name')));
|
||||
|
||||
$this->setDocblock('@param string $name');
|
||||
$this->setBody(
|
||||
'$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true)
|
||||
. ', \'__unset\', array($name));' . "\n\n"
|
||||
. 'return $return;'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Method decorator for remote objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class RemoteObjectMethod extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param \Zend\Code\Reflection\MethodReflection $originalMethod
|
||||
* @param \Zend\Code\Generator\PropertyGenerator $adapterProperty
|
||||
* @param \ReflectionClass $originalClass
|
||||
*
|
||||
* @return RemoteObjectMethod|static
|
||||
*/
|
||||
public static function generateMethod(
|
||||
MethodReflection $originalMethod,
|
||||
PropertyGenerator $adapterProperty,
|
||||
ReflectionClass $originalClass
|
||||
) {
|
||||
/* @var $method self */
|
||||
$method = static::fromReflection($originalMethod);
|
||||
$parameters = $originalMethod->getParameters();
|
||||
$list = array();
|
||||
|
||||
foreach ($parameters as $parameter) {
|
||||
$list[] = '$' . $parameter->getName();
|
||||
}
|
||||
|
||||
$method->setBody(
|
||||
'$return = $this->' . $adapterProperty->getName() . '->call(' . var_export($originalClass->getName(), true)
|
||||
. ', ' . var_export($originalMethod->getName(), true) . ', array('. implode(', ', $list) .'));' . "\n\n"
|
||||
. 'return $return;'
|
||||
);
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Property that contains the remote object adapter
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class AdapterProperty extends PropertyGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(UniqueIdentifierGenerator::getIdentifier('adapter'));
|
||||
|
||||
$this->setVisibility(self::VISIBILITY_PRIVATE);
|
||||
$this->setDocblock('@var \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface Remote web service adapter');
|
||||
}
|
||||
}
|
||||
93
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php
vendored
Normal file
93
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator;
|
||||
|
||||
use ProxyManager\Generator\Util\ClassGeneratorUtils;
|
||||
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\Constructor;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod;
|
||||
use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty;
|
||||
use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Generator for proxies implementing {@see \ProxyManager\Proxy\RemoteObjectInterface}
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class RemoteObjectGenerator implements ProxyGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
|
||||
{
|
||||
CanProxyAssertion::assertClassCanBeProxied($originalClass);
|
||||
|
||||
$interfaces = array('ProxyManager\\Proxy\\RemoteObjectInterface');
|
||||
|
||||
if ($originalClass->isInterface()) {
|
||||
$interfaces[] = $originalClass->getName();
|
||||
} else {
|
||||
$classGenerator->setExtendedClass($originalClass->getName());
|
||||
}
|
||||
|
||||
$classGenerator->setImplementedInterfaces($interfaces);
|
||||
$classGenerator->addPropertyFromGenerator($adapter = new AdapterProperty());
|
||||
|
||||
array_map(
|
||||
function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
|
||||
ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
|
||||
},
|
||||
array_merge(
|
||||
array_map(
|
||||
function (ReflectionMethod $method) use ($adapter, $originalClass) {
|
||||
return RemoteObjectMethod::generateMethod(
|
||||
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
|
||||
$adapter,
|
||||
$originalClass
|
||||
);
|
||||
},
|
||||
ProxiedMethodsFilter::getProxiedMethods(
|
||||
$originalClass,
|
||||
array('__get', '__set', '__isset', '__unset')
|
||||
)
|
||||
),
|
||||
array(
|
||||
new Constructor($originalClass, $adapter),
|
||||
new MagicGet($originalClass, $adapter),
|
||||
new MagicSet($originalClass, $adapter),
|
||||
new MagicIsset($originalClass, $adapter),
|
||||
new MagicUnset($originalClass, $adapter),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
56
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/ProxiedMethodsFilter.php
vendored
Normal file
56
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/ProxiedMethodsFilter.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\Util;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Utility class used to filter methods that can be proxied
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class ProxiedMethodsFilter
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $class reflection class from which methods should be extracted
|
||||
* @param string[] $excluded methods to be ignored
|
||||
*
|
||||
* @return ReflectionMethod[]
|
||||
*/
|
||||
public static function getProxiedMethods(
|
||||
ReflectionClass $class,
|
||||
array $excluded = array('__get', '__set', '__isset', '__unset', '__clone', '__sleep', '__wakeup')
|
||||
) {
|
||||
$ignored = array_flip(array_map('strtolower', $excluded));
|
||||
|
||||
return array_filter(
|
||||
$class->getMethods(ReflectionMethod::IS_PUBLIC),
|
||||
function (ReflectionMethod $method) use ($ignored) {
|
||||
return ! (
|
||||
$method->isConstructor()
|
||||
|| isset($ignored[strtolower($method->getName())])
|
||||
|| $method->isFinal()
|
||||
|| $method->isStatic()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
190
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php
vendored
Normal file
190
vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\Util;
|
||||
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Generates code necessary to simulate a fatal error in case of unauthorized
|
||||
* access to class members in magic methods even when in child classes and dealing
|
||||
* with protected members.
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class PublicScopeSimulator
|
||||
{
|
||||
const OPERATION_SET = 'set';
|
||||
const OPERATION_GET = 'get';
|
||||
const OPERATION_ISSET = 'isset';
|
||||
const OPERATION_UNSET = 'unset';
|
||||
|
||||
/**
|
||||
* Generates code for simulating access to a property from the scope that is accessing a proxy.
|
||||
* This is done by introspecting `debug_backtrace()` and then binding a closure to the scope
|
||||
* of the parent caller.
|
||||
*
|
||||
* @param string $operationType operation to execute: one of 'get', 'set', 'isset' or 'unset'
|
||||
* @param string $nameParameter name of the `name` parameter of the magic method
|
||||
* @param string|null $valueParameter name of the `value` parameter of the magic method
|
||||
* @param PropertyGenerator $valueHolder name of the property containing the target object from which
|
||||
* to read the property. `$this` if none provided
|
||||
* @param string|null $returnPropertyName name of the property to which we want to assign the result of
|
||||
* the operation. Return directly if none provided
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function getPublicAccessSimulationCode(
|
||||
$operationType,
|
||||
$nameParameter,
|
||||
$valueParameter = null,
|
||||
PropertyGenerator $valueHolder = null,
|
||||
$returnPropertyName = null
|
||||
) {
|
||||
$byRef = self::getByRefReturnValue($operationType);
|
||||
$value = static::OPERATION_SET === $operationType ? ', $value' : '';
|
||||
$target = '$this';
|
||||
|
||||
if ($valueHolder) {
|
||||
$target = '$this->' . $valueHolder->getName();
|
||||
}
|
||||
|
||||
return '$realInstanceReflection = new \\ReflectionClass(get_parent_class($this));' . "\n\n"
|
||||
. 'if (! $realInstanceReflection->hasProperty($' . $nameParameter . ')) {' . "\n"
|
||||
. ' $targetObject = ' . $target . ';' . "\n\n"
|
||||
. self::getUndefinedPropertyNotice($operationType, $nameParameter)
|
||||
. ' ' . self::getOperation($operationType, $nameParameter, $valueParameter) . ";\n"
|
||||
. " return;\n"
|
||||
. '}' . "\n\n"
|
||||
. '$targetObject = ' . self::getTargetObject($valueHolder) . ";\n"
|
||||
. '$accessor = function ' . $byRef . '() use ($targetObject, $name' . $value . ') {' . "\n"
|
||||
. ' ' . self::getOperation($operationType, $nameParameter, $valueParameter) . "\n"
|
||||
. "};\n"
|
||||
. self::getScopeReBind()
|
||||
. (
|
||||
$returnPropertyName
|
||||
? '$' . $returnPropertyName . ' = ' . $byRef . '$accessor();'
|
||||
: '$returnValue = ' . $byRef . '$accessor();' . "\n\n" . 'return $returnValue;'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will generate code that triggers a notice if access is attempted on a non-existing property
|
||||
*
|
||||
* @param string $operationType
|
||||
* @param string $nameParameter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getUndefinedPropertyNotice($operationType, $nameParameter)
|
||||
{
|
||||
if (static::OPERATION_GET !== $operationType) {
|
||||
return '';
|
||||
}
|
||||
|
||||
//
|
||||
return ' $backtrace = debug_backtrace(false);' . "\n"
|
||||
. ' trigger_error(\'Undefined property: \' . get_parent_class($this) . \'::$\' . $'
|
||||
. $nameParameter
|
||||
. ' . \' in \' . $backtrace[0][\'file\'] . \' on line \' . $backtrace[0][\'line\'], \E_USER_NOTICE);'
|
||||
. "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines whether the given operation produces a reference.
|
||||
*
|
||||
* Note: if the object is a wrapper, the wrapped instance is accessed directly. If the object
|
||||
* is a ghost or the proxy has no wrapper, then an instance of the parent class is created via
|
||||
* on-the-fly unserialization
|
||||
*
|
||||
* @param string $operationType
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getByRefReturnValue($operationType)
|
||||
{
|
||||
return (static::OPERATION_GET === $operationType || static::OPERATION_SET === $operationType) ? '& ' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the logic to fetch the object on which access should be attempted
|
||||
*
|
||||
* @param PropertyGenerator $valueHolder
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getTargetObject(PropertyGenerator $valueHolder = null)
|
||||
{
|
||||
if ($valueHolder) {
|
||||
return '$this->' . $valueHolder->getName();
|
||||
}
|
||||
|
||||
return 'unserialize(sprintf(\'O:%d:"%s":0:{}\', strlen(get_parent_class($this)), get_parent_class($this)))';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $operationType
|
||||
* @param string $nameParameter
|
||||
* @param string|null $valueParameter
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private static function getOperation($operationType, $nameParameter, $valueParameter)
|
||||
{
|
||||
switch ($operationType) {
|
||||
case static::OPERATION_GET:
|
||||
return 'return $targetObject->$' . $nameParameter . ";";
|
||||
case static::OPERATION_SET:
|
||||
if (! $valueParameter) {
|
||||
throw new \InvalidArgumentException('Parameter $valueParameter not provided');
|
||||
}
|
||||
|
||||
return 'return $targetObject->$' . $nameParameter . ' = $' . $valueParameter . ';';
|
||||
case static::OPERATION_ISSET:
|
||||
return 'return isset($targetObject->$' . $nameParameter . ');';
|
||||
case static::OPERATION_UNSET:
|
||||
return 'unset($targetObject->$' . $nameParameter . ');';
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Invalid operation "%s" provided', $operationType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates code to bind operations to the parent scope if supported by the current PHP implementation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getScopeReBind()
|
||||
{
|
||||
if (! method_exists('Closure', 'bind')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return '';
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return ' $backtrace = debug_backtrace(true);' . "\n"
|
||||
. ' $scopeObject = isset($backtrace[1][\'object\'])'
|
||||
. ' ? $backtrace[1][\'object\'] : new \stdClass();' . "\n"
|
||||
. ' $accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));' . "\n";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MethodGenerator;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Implementation for {@see \ProxyManager\Proxy\ValueHolderInterface::getWrappedValueHolderValue}
|
||||
* for lazy loading value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class GetWrappedValueHolderValue extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(PropertyGenerator $valueHolderProperty)
|
||||
{
|
||||
parent::__construct('getWrappedValueHolderValue');
|
||||
$this->setDocblock('{@inheritDoc}');
|
||||
$this->setBody('return $this->' . $valueHolderProperty->getName() . ';');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator;
|
||||
|
||||
use ProxyManager\Generator\MagicMethodGenerator;
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\PropertyGenerator;
|
||||
|
||||
/**
|
||||
* Magic `__sleep` for value holder objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicSleep extends MagicMethodGenerator
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, PropertyGenerator $valueHolderProperty)
|
||||
{
|
||||
parent::__construct($originalClass, '__sleep');
|
||||
|
||||
$this->setBody('return array(' . var_export($valueHolderProperty->getName(), true) . ');');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user