/usr/share/php/ProxyManager/ProxyGenerator/HydratorGenerator.php is in php-proxy-manager 0.3.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | <?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\MethodGenerator;
use ProxyManager\ProxyGenerator\Hydrator\MethodGenerator\GetAccessorProperties;
use ProxyManager\ProxyGenerator\Hydrator\MethodGenerator\SetAccessorProperties;
use ProxyManager\ProxyGenerator\Hydrator\PropertyGenerator\PropertyAccessor;
use ProxyManager\ProxyGenerator\Hydrator\MethodGenerator\Constructor;
use ProxyManager\ProxyGenerator\Hydrator\MethodGenerator\DisabledMethod;
use ProxyManager\ProxyGenerator\Hydrator\MethodGenerator\Extract;
use ProxyManager\ProxyGenerator\Hydrator\MethodGenerator\Hydrate;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
use Zend\Code\Generator\ClassGenerator;
use Zend\Code\Reflection\MethodReflection;
/**
* Generator for proxies being a hydrator - {@see \Zend\Stdlib\Hydrator\HydratorInterface}
* for objects
*
* {@inheritDoc}
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class HydratorGenerator implements ProxyGeneratorInterface
{
/**
* {@inheritDoc}
*/
public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
{
$interfaces = array('ProxyManager\\Proxy\\HydratorInterface',);
if ($originalClass->isInterface()) {
$interfaces[] = $originalClass->getName();
} else {
$classGenerator->setExtendedClass($originalClass->getName());
}
$classGenerator->setImplementedInterfaces($interfaces);
$excluded = array(
'__get' => true,
'__set' => true,
'__isset' => true,
'__unset' => true,
'__clone' => true,
'__sleep' => true,
'__wakeup' => true,
);
/* @var $methods ReflectionMethod[] */
$methods = array_filter(
$originalClass->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED),
function (ReflectionMethod $method) use ($excluded) {
return ! (
$method->isConstructor()
|| isset($excluded[strtolower($method->getName())])
|| $method->isFinal()
|| $method->isStatic()
);
}
);
foreach ($methods as $method) {
$classGenerator->addMethodFromGenerator(
DisabledMethod::fromReflection(
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())
)
);
}
foreach (array('__clone', '__sleep', '__wakeup') as $magicMethod) {
$classGenerator->addMethodFromGenerator(new DisabledMethod($magicMethod));
}
$classGenerator->addMethodFromGenerator(new DisabledMethod('__get', array('name')));
$classGenerator->addMethodFromGenerator(new DisabledMethod('__set', array('name', 'value')));
$classGenerator->addMethodFromGenerator(new DisabledMethod('__isset', array('name')));
$classGenerator->addMethodFromGenerator(new DisabledMethod('__unset', array('name')));
$accessibleFlag = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED;
$accessibleProperties = $originalClass->getProperties($accessibleFlag);
$inaccessibleProps = $originalClass->getProperties(ReflectionProperty::IS_PRIVATE);
$propertyAccessors = array();
foreach ($inaccessibleProps as $inaccessibleProp) {
$propertyAccessors[] = new PropertyAccessor($inaccessibleProp);
}
$classGenerator->addProperties($propertyAccessors);
$classGenerator->addMethodFromGenerator(new Constructor($propertyAccessors));
$classGenerator->addMethodFromGenerator(new Hydrate($accessibleProperties, $propertyAccessors));
$classGenerator->addMethodFromGenerator(new Extract($accessibleProperties, $propertyAccessors));
$classGenerator->addMethodFromGenerator(new GetAccessorProperties($propertyAccessors));
$classGenerator->addMethodFromGenerator(new SetAccessorProperties($propertyAccessors));
}
}
|