Ajout du FR
Ajout du FR + correction du "functions.php"
This commit is contained in:
69
vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/Autoloader.php
vendored
Normal file
69
vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/Autoloader.php
vendored
Normal file
@@ -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\Autoloader;
|
||||
|
||||
use ProxyManager\FileLocator\FileLocatorInterface;
|
||||
use ProxyManager\Inflector\ClassNameInflectorInterface;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Autoloader implements AutoloaderInterface
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\FileLocator\FileLocatorInterface
|
||||
*/
|
||||
protected $fileLocator;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Inflector\ClassNameInflectorInterface
|
||||
*/
|
||||
protected $classNameInflector;
|
||||
|
||||
/**
|
||||
* @param \ProxyManager\FileLocator\FileLocatorInterface $fileLocator
|
||||
* @param \ProxyManager\Inflector\ClassNameInflectorInterface $classNameInflector
|
||||
*/
|
||||
public function __construct(FileLocatorInterface $fileLocator, ClassNameInflectorInterface $classNameInflector)
|
||||
{
|
||||
$this->fileLocator = $fileLocator;
|
||||
$this->classNameInflector = $classNameInflector;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __invoke($className)
|
||||
{
|
||||
if (class_exists($className, false) || ! $this->classNameInflector->isProxyClassName($className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = $this->fileLocator->getProxyFileName($className);
|
||||
|
||||
if (! file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) require_once $file;
|
||||
}
|
||||
}
|
||||
37
vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/AutoloaderInterface.php
vendored
Normal file
37
vendor/ocramius/proxy-manager/src/ProxyManager/Autoloader/AutoloaderInterface.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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\Autoloader;
|
||||
|
||||
/**
|
||||
* Basic autoloader utilities required to work with proxy files
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface AutoloaderInterface
|
||||
{
|
||||
/**
|
||||
* Callback to allow the object to be handled as autoloader - tries to autoload the given class name
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __invoke($className);
|
||||
}
|
||||
241
vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php
vendored
Normal file
241
vendor/ocramius/proxy-manager/src/ProxyManager/Configuration.php
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
<?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;
|
||||
|
||||
use ProxyManager\Autoloader\Autoloader;
|
||||
use ProxyManager\Autoloader\AutoloaderInterface;
|
||||
use ProxyManager\FileLocator\FileLocator;
|
||||
use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy;
|
||||
use ProxyManager\GeneratorStrategy\GeneratorStrategyInterface;
|
||||
use ProxyManager\Inflector\ClassNameInflector;
|
||||
use ProxyManager\Inflector\ClassNameInflectorInterface;
|
||||
use ProxyManager\Signature\ClassSignatureGenerator;
|
||||
use ProxyManager\Signature\ClassSignatureGeneratorInterface;
|
||||
use ProxyManager\Signature\SignatureChecker;
|
||||
use ProxyManager\Signature\SignatureCheckerInterface;
|
||||
use ProxyManager\Signature\SignatureGenerator;
|
||||
use ProxyManager\Signature\SignatureGeneratorInterface;
|
||||
|
||||
/**
|
||||
* Base configuration class for the proxy manager - serves as micro disposable DIC/facade
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Configuration
|
||||
{
|
||||
const DEFAULT_PROXY_NAMESPACE = 'ProxyManagerGeneratedProxy';
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $proxiesTargetDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE;
|
||||
|
||||
/**
|
||||
* @var GeneratorStrategyInterface|null
|
||||
*/
|
||||
protected $generatorStrategy;
|
||||
|
||||
/**
|
||||
* @var callable|null
|
||||
*/
|
||||
protected $proxyAutoloader;
|
||||
|
||||
/**
|
||||
* @var ClassNameInflectorInterface|null
|
||||
*/
|
||||
protected $classNameInflector;
|
||||
|
||||
/**
|
||||
* @var SignatureGeneratorInterface|null
|
||||
*/
|
||||
protected $signatureGenerator;
|
||||
|
||||
/**
|
||||
* @var SignatureCheckerInterface|null
|
||||
*/
|
||||
protected $signatureChecker;
|
||||
|
||||
/**
|
||||
* @var ClassSignatureGeneratorInterface|null
|
||||
*/
|
||||
protected $classSignatureGenerator;
|
||||
|
||||
/**
|
||||
* @deprecated deprecated since version 0.5
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setAutoGenerateProxies()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated deprecated since version 0.5
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function doesAutoGenerateProxies()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AutoloaderInterface $proxyAutoloader
|
||||
*/
|
||||
public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader)
|
||||
{
|
||||
$this->proxyAutoloader = $proxyAutoloader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AutoloaderInterface
|
||||
*/
|
||||
public function getProxyAutoloader()
|
||||
{
|
||||
return $this->proxyAutoloader
|
||||
?: $this->proxyAutoloader = new Autoloader(
|
||||
new FileLocator($this->getProxiesTargetDir()),
|
||||
$this->getClassNameInflector()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $proxiesNamespace
|
||||
*/
|
||||
public function setProxiesNamespace($proxiesNamespace)
|
||||
{
|
||||
$this->proxiesNamespace = $proxiesNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProxiesNamespace()
|
||||
{
|
||||
return $this->proxiesNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $proxiesTargetDir
|
||||
*/
|
||||
public function setProxiesTargetDir($proxiesTargetDir)
|
||||
{
|
||||
$this->proxiesTargetDir = (string) $proxiesTargetDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProxiesTargetDir()
|
||||
{
|
||||
return $this->proxiesTargetDir ?: $this->proxiesTargetDir = sys_get_temp_dir();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GeneratorStrategyInterface $generatorStrategy
|
||||
*/
|
||||
public function setGeneratorStrategy(GeneratorStrategyInterface $generatorStrategy)
|
||||
{
|
||||
$this->generatorStrategy = $generatorStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GeneratorStrategyInterface
|
||||
*/
|
||||
public function getGeneratorStrategy()
|
||||
{
|
||||
return $this->generatorStrategy
|
||||
?: $this->generatorStrategy = new FileWriterGeneratorStrategy(
|
||||
new FileLocator($this->getProxiesTargetDir())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassNameInflectorInterface $classNameInflector
|
||||
*/
|
||||
public function setClassNameInflector(ClassNameInflectorInterface $classNameInflector)
|
||||
{
|
||||
$this->classNameInflector = $classNameInflector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ClassNameInflectorInterface
|
||||
*/
|
||||
public function getClassNameInflector()
|
||||
{
|
||||
return $this->classNameInflector
|
||||
?: $this->classNameInflector = new ClassNameInflector($this->getProxiesNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SignatureGeneratorInterface $signatureGenerator
|
||||
*/
|
||||
public function setSignatureGenerator(SignatureGeneratorInterface $signatureGenerator)
|
||||
{
|
||||
$this->signatureGenerator = $signatureGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SignatureGeneratorInterface
|
||||
*/
|
||||
public function getSignatureGenerator()
|
||||
{
|
||||
return $this->signatureGenerator ?: $this->signatureGenerator = new SignatureGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SignatureCheckerInterface $signatureChecker
|
||||
*/
|
||||
public function setSignatureChecker(SignatureCheckerInterface $signatureChecker)
|
||||
{
|
||||
$this->signatureChecker = $signatureChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SignatureCheckerInterface
|
||||
*/
|
||||
public function getSignatureChecker()
|
||||
{
|
||||
return $this->signatureChecker
|
||||
?: $this->signatureChecker = new SignatureChecker($this->getSignatureGenerator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassSignatureGeneratorInterface $classSignatureGenerator
|
||||
*/
|
||||
public function setClassSignatureGenerator(ClassSignatureGeneratorInterface $classSignatureGenerator)
|
||||
{
|
||||
$this->classSignatureGenerator = $classSignatureGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ClassSignatureGeneratorInterface
|
||||
*/
|
||||
public function getClassSignatureGenerator()
|
||||
{
|
||||
return $this->classSignatureGenerator
|
||||
?: new ClassSignatureGenerator($this->getSignatureGenerator());
|
||||
}
|
||||
}
|
||||
42
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/DisabledMethodException.php
vendored
Normal file
42
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/DisabledMethodException.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\Exception;
|
||||
|
||||
use BadMethodCallException;
|
||||
|
||||
/**
|
||||
* Exception for forcefully disabled methods
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class DisabledMethodException extends BadMethodCallException implements ExceptionInterface
|
||||
{
|
||||
const NAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function disabledMethod($method)
|
||||
{
|
||||
return new self(sprintf('Method "%s" is forcefully disabled', (string) $method));
|
||||
}
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/ExceptionInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/ExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Exception;
|
||||
|
||||
/**
|
||||
* Base exception class for the proxy manager
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface ExceptionInterface
|
||||
{
|
||||
}
|
||||
69
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/FileNotWritableException.php
vendored
Normal file
69
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/FileNotWritableException.php
vendored
Normal file
@@ -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\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* Exception for non writable files
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class FileNotWritableException extends UnexpectedValueException implements ExceptionInterface
|
||||
{
|
||||
/**
|
||||
* @param string $fromPath
|
||||
* @param string $toPath
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromInvalidMoveOperation($fromPath, $toPath)
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Could not move file "%s" to location "%s": '
|
||||
. 'either the source file is not readable, or the destination is not writable',
|
||||
$fromPath,
|
||||
$toPath
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function fromNonWritableLocation($path)
|
||||
{
|
||||
$messages = array();
|
||||
|
||||
if (($destination = realpath($path)) && ! is_file($destination)) {
|
||||
$messages[] = 'exists and is not a file';
|
||||
}
|
||||
|
||||
if (! is_writable($destination)) {
|
||||
$messages[] = 'is not writable';
|
||||
}
|
||||
|
||||
return new self(sprintf('Could not write to path "%s": %s', $path, implode(', ', $messages)));
|
||||
}
|
||||
}
|
||||
79
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxiedClassException.php
vendored
Normal file
79
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxiedClassException.php
vendored
Normal file
@@ -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\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Exception for invalid proxied classes
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InvalidProxiedClassException extends InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $reflection
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function interfaceNotSupported(ReflectionClass $reflection)
|
||||
{
|
||||
return new self(sprintf('Provided interface "%s" cannot be proxied', $reflection->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $reflection
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function finalClassNotSupported(ReflectionClass $reflection)
|
||||
{
|
||||
return new self(sprintf('Provided class "%s" is final and cannot be proxied', $reflection->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $reflection
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function abstractProtectedMethodsNotSupported(ReflectionClass $reflection)
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Provided class "%s" has following protected abstract methods, and therefore cannot be proxied:' . "\n%s",
|
||||
$reflection->getName(),
|
||||
implode(
|
||||
"\n",
|
||||
array_map(
|
||||
function (ReflectionMethod $reflectionMethod) {
|
||||
return $reflectionMethod->getDeclaringClass()->getName() . '::' . $reflectionMethod->getName();
|
||||
},
|
||||
array_filter(
|
||||
$reflection->getMethods(),
|
||||
function (ReflectionMethod $method) {
|
||||
return $method->isAbstract() && $method->isProtected();
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
40
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxyDirectoryException.php
vendored
Normal file
40
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/InvalidProxyDirectoryException.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Exception for invalid directories
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class InvalidProxyDirectoryException extends InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
/**
|
||||
* @param string $directory
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function proxyDirectoryNotFound($directory)
|
||||
{
|
||||
return new self(sprintf('Provided directory "%s" does not exist', (string) $directory));
|
||||
}
|
||||
}
|
||||
47
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/UnsupportedProxiedClassException.php
vendored
Normal file
47
vendor/ocramius/proxy-manager/src/ProxyManager/Exception/UnsupportedProxiedClassException.php
vendored
Normal file
@@ -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\Exception;
|
||||
|
||||
use LogicException;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Exception for invalid proxied classes
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class UnsupportedProxiedClassException extends LogicException implements ExceptionInterface
|
||||
{
|
||||
/**
|
||||
* @param ReflectionProperty $property
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function unsupportedLocalizedReflectionProperty(ReflectionProperty $property)
|
||||
{
|
||||
return new self(
|
||||
sprintf(
|
||||
'Provided reflection property "%s" of class "%s" is private and cannot be localized in PHP 5.3',
|
||||
$property->getName(),
|
||||
$property->getDeclaringClass()->getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
112
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractBaseFactory.php
vendored
Normal file
112
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractBaseFactory.php
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
<?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\Factory;
|
||||
|
||||
use ProxyManager\Configuration;
|
||||
use ProxyManager\Generator\ClassGenerator;
|
||||
use ProxyManager\Version;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Base factory common logic
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
abstract class AbstractBaseFactory
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\Configuration
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* Cached checked class names
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $checkedClasses = array();
|
||||
|
||||
/**
|
||||
* @param \ProxyManager\Configuration $configuration
|
||||
*/
|
||||
public function __construct(Configuration $configuration = null)
|
||||
{
|
||||
$this->configuration = $configuration ?: new Configuration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a proxy from a class name
|
||||
* @param string $className
|
||||
* @return string proxy class name
|
||||
*/
|
||||
protected function generateProxy($className)
|
||||
{
|
||||
if (isset($this->checkedClasses[$className])) {
|
||||
return $this->checkedClasses[$className];
|
||||
}
|
||||
|
||||
$proxyParameters = array(
|
||||
'className' => $className,
|
||||
'factory' => get_class($this),
|
||||
'proxyManagerVersion' => Version::VERSION
|
||||
);
|
||||
$proxyClassName = $this
|
||||
->configuration
|
||||
->getClassNameInflector()
|
||||
->getProxyClassName($className, $proxyParameters);
|
||||
|
||||
if (! class_exists($proxyClassName)) {
|
||||
$this->generateProxyClass($proxyClassName, $className, $proxyParameters);
|
||||
}
|
||||
|
||||
$this
|
||||
->configuration
|
||||
->getSignatureChecker()
|
||||
->checkSignature(new ReflectionClass($proxyClassName), $proxyParameters);
|
||||
|
||||
return $this->checkedClasses[$className] = $proxyClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \ProxyManager\ProxyGenerator\ProxyGeneratorInterface
|
||||
*/
|
||||
abstract protected function getGenerator();
|
||||
|
||||
/**
|
||||
* Generates the provided `$proxyClassName` from the given `$className` and `$proxyParameters`
|
||||
* @param string $proxyClassName
|
||||
* @param string $className
|
||||
* @param array $proxyParameters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function generateProxyClass($proxyClassName, $className, array $proxyParameters)
|
||||
{
|
||||
$className = $this->configuration->getClassNameInflector()->getUserClassName($className);
|
||||
$phpClass = new ClassGenerator($proxyClassName);
|
||||
|
||||
$this->getGenerator()->generate(new ReflectionClass($className), $phpClass);
|
||||
|
||||
$phpClass = $this->configuration->getClassSignatureGenerator()->addSignature($phpClass, $proxyParameters);
|
||||
|
||||
$this->configuration->getGeneratorStrategy()->generate($phpClass);
|
||||
$this->configuration->getProxyAutoloader()->__invoke($proxyClassName);
|
||||
}
|
||||
}
|
||||
46
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractLazyFactory.php
vendored
Normal file
46
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AbstractLazyFactory.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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\Factory;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Base factory common logic
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
abstract class AbstractLazyFactory extends AbstractBaseFactory
|
||||
{
|
||||
/**
|
||||
* Creates a new lazy proxy instance of the given class with
|
||||
* the given initializer
|
||||
*
|
||||
* @param string $className name of the class to be proxied
|
||||
* @param \Closure $initializer initializer to be passed to the proxy
|
||||
*
|
||||
* @return \ProxyManager\Proxy\LazyLoadingInterface
|
||||
*/
|
||||
public function createProxy($className, Closure $initializer)
|
||||
{
|
||||
$proxyClassName = $this->generateProxy($className);
|
||||
|
||||
return new $proxyClassName($initializer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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\Factory;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator;
|
||||
|
||||
/**
|
||||
* Factory responsible of producing proxy objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class AccessInterceptorScopeLocalizerFactory extends AbstractBaseFactory
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator|null
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* @param object $instance the object to be localized within the access interceptor
|
||||
* @param \Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called
|
||||
* before method logic is executed
|
||||
* @param \Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called
|
||||
* after method logic is executed
|
||||
*
|
||||
* @return \ProxyManager\Proxy\AccessInterceptorInterface
|
||||
*/
|
||||
public function createProxy($instance, array $prefixInterceptors = array(), array $suffixInterceptors = array())
|
||||
{
|
||||
$proxyClassName = $this->generateProxy(get_class($instance));
|
||||
|
||||
return new $proxyClassName($instance, $prefixInterceptors, $suffixInterceptors);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getGenerator()
|
||||
{
|
||||
return $this->generator ?: $this->generator = new AccessInterceptorScopeLocalizerGenerator();
|
||||
}
|
||||
}
|
||||
59
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php
vendored
Normal file
59
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Factory;
|
||||
|
||||
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator;
|
||||
|
||||
/**
|
||||
* Factory responsible of producing proxy objects
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class AccessInterceptorValueHolderFactory extends AbstractBaseFactory
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator|null
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* @param object $instance the object to be wrapped within the value holder
|
||||
* @param \Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called
|
||||
* before method logic is executed
|
||||
* @param \Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called
|
||||
* after method logic is executed
|
||||
*
|
||||
* @return \ProxyManager\Proxy\AccessInterceptorInterface|\ProxyManager\Proxy\ValueHolderInterface
|
||||
*/
|
||||
public function createProxy($instance, array $prefixInterceptors = array(), array $suffixInterceptors = array())
|
||||
{
|
||||
$proxyClassName = $this->generateProxy(get_class($instance));
|
||||
|
||||
return new $proxyClassName($instance, $prefixInterceptors, $suffixInterceptors);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getGenerator()
|
||||
{
|
||||
return $this->generator ?: $this->generator = new AccessInterceptorValueHolderGenerator();
|
||||
}
|
||||
}
|
||||
45
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingGhostFactory.php
vendored
Normal file
45
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingGhostFactory.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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\Factory;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator;
|
||||
|
||||
/**
|
||||
* Factory responsible of producing ghost instances
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @method \ProxyManager\Proxy\GhostObjectInterface createProxy($className, \Closure $initializer)
|
||||
*/
|
||||
class LazyLoadingGhostFactory extends AbstractLazyFactory
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator|null
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getGenerator()
|
||||
{
|
||||
return $this->generator ?: $this->generator = new LazyLoadingGhostGenerator();
|
||||
}
|
||||
}
|
||||
45
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php
vendored
Normal file
45
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/LazyLoadingValueHolderFactory.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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\Factory;
|
||||
|
||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
|
||||
|
||||
/**
|
||||
* Factory responsible of producing virtual proxy instances
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* @method \ProxyManager\Proxy\VirtualProxyInterface createProxy($className, \Closure $initializer)
|
||||
*/
|
||||
class LazyLoadingValueHolderFactory extends AbstractLazyFactory
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator|null
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getGenerator()
|
||||
{
|
||||
return $this->generator ?: $this->generator = new LazyLoadingValueHolderGenerator();
|
||||
}
|
||||
}
|
||||
56
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/NullObjectFactory.php
vendored
Normal file
56
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/NullObjectFactory.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\Factory;
|
||||
|
||||
use ProxyManager\ProxyGenerator\NullObjectGenerator;
|
||||
|
||||
/**
|
||||
* Factory responsible of producing proxy objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class NullObjectFactory extends AbstractBaseFactory
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\NullObjectGenerator|null
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* @param object $instanceOrClassName the object to be wrapped or interface to transform to null object
|
||||
*
|
||||
* @return \ProxyManager\Proxy\NullobjectInterface
|
||||
*/
|
||||
public function createProxy($instanceOrClassName)
|
||||
{
|
||||
$className = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName;
|
||||
$proxyClassName = $this->generateProxy($className);
|
||||
|
||||
return new $proxyClassName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getGenerator()
|
||||
{
|
||||
return $this->generator ?: $this->generator = new NullObjectGenerator();
|
||||
}
|
||||
}
|
||||
81
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/BaseAdapter.php
vendored
Normal file
81
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/BaseAdapter.php
vendored
Normal file
@@ -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\Factory\RemoteObject\Adapter;
|
||||
|
||||
use ProxyManager\Factory\RemoteObject\AdapterInterface;
|
||||
use Zend\Server\Client;
|
||||
|
||||
/**
|
||||
* Remote Object base adapter
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
abstract class BaseAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Adapter client
|
||||
*
|
||||
* @var \Zend\Server\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Service name mapping
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $map = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Client $client
|
||||
* @param array $map map of service names to their aliases
|
||||
*/
|
||||
public function __construct(Client $client, array $map = array())
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->map = $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function call($wrappedClass, $method, array $params = array())
|
||||
{
|
||||
$serviceName = $this->getServiceName($wrappedClass, $method);
|
||||
|
||||
if (isset($this->map[$serviceName])) {
|
||||
$serviceName = $this->map[$serviceName];
|
||||
}
|
||||
|
||||
return $this->client->call($serviceName, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the service name will be used by the adapter
|
||||
*
|
||||
* @param string $wrappedClass
|
||||
* @param string $method
|
||||
*
|
||||
* @return string Service name
|
||||
*/
|
||||
abstract protected function getServiceName($wrappedClass, $method);
|
||||
}
|
||||
36
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/JsonRpc.php
vendored
Normal file
36
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/JsonRpc.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Factory\RemoteObject\Adapter;
|
||||
|
||||
/**
|
||||
* Remote Object JSON RPC adapter
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class JsonRpc extends BaseAdapter
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getServiceName($wrappedClass, $method)
|
||||
{
|
||||
return $wrappedClass . '.' . $method;
|
||||
}
|
||||
}
|
||||
36
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/Soap.php
vendored
Normal file
36
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/Soap.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Factory\RemoteObject\Adapter;
|
||||
|
||||
/**
|
||||
* Remote Object SOAP adapter
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class Soap extends BaseAdapter
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getServiceName($wrappedClass, $method)
|
||||
{
|
||||
return (string) $method;
|
||||
}
|
||||
}
|
||||
36
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/XmlRpc.php
vendored
Normal file
36
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/Adapter/XmlRpc.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Factory\RemoteObject\Adapter;
|
||||
|
||||
/**
|
||||
* Remote Object XML RPC adapter
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class XmlRpc extends BaseAdapter
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getServiceName($wrappedClass, $method)
|
||||
{
|
||||
return $wrappedClass . '.' . $method;
|
||||
}
|
||||
}
|
||||
37
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/AdapterInterface.php
vendored
Normal file
37
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObject/AdapterInterface.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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\Factory\RemoteObject;
|
||||
|
||||
/**
|
||||
* Remote Object adapter interface
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Call remote object
|
||||
*
|
||||
* @param string $wrappedClass
|
||||
* @param string $method
|
||||
* @param array $params
|
||||
*/
|
||||
public function call($wrappedClass, $method, array $params = array());
|
||||
}
|
||||
76
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObjectFactory.php
vendored
Normal file
76
vendor/ocramius/proxy-manager/src/ProxyManager/Factory/RemoteObjectFactory.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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\Factory;
|
||||
|
||||
use ProxyManager\Configuration;
|
||||
use ProxyManager\Factory\RemoteObject\AdapterInterface;
|
||||
use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
|
||||
|
||||
/**
|
||||
* Factory responsible of producing remote proxy objects
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class RemoteObjectFactory extends AbstractBaseFactory
|
||||
{
|
||||
/**
|
||||
* @var AdapterInterface
|
||||
*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\ProxyGenerator\RemoteObjectGenerator|null
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param AdapterInterface $adapter
|
||||
* @param Configuration $configuration
|
||||
*/
|
||||
public function __construct(AdapterInterface $adapter, Configuration $configuration = null)
|
||||
{
|
||||
parent::__construct($configuration);
|
||||
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|object $instanceOrClassName
|
||||
*
|
||||
* @return \ProxyManager\Proxy\RemoteObjectInterface
|
||||
*/
|
||||
public function createProxy($instanceOrClassName)
|
||||
{
|
||||
$className = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName;
|
||||
$proxyClassName = $this->generateProxy($className);
|
||||
|
||||
return new $proxyClassName($this->adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getGenerator()
|
||||
{
|
||||
return $this->generator ?: $this->generator = new RemoteObjectGenerator();
|
||||
}
|
||||
}
|
||||
57
vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocator.php
vendored
Normal file
57
vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocator.php
vendored
Normal file
@@ -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\FileLocator;
|
||||
|
||||
use ProxyManager\Exception\InvalidProxyDirectoryException;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class FileLocator implements FileLocatorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $proxiesDirectory;
|
||||
|
||||
/**
|
||||
* @param string $proxiesDirectory
|
||||
*
|
||||
* @throws \ProxyManager\Exception\InvalidProxyDirectoryException
|
||||
*/
|
||||
public function __construct($proxiesDirectory)
|
||||
{
|
||||
$this->proxiesDirectory = realpath($proxiesDirectory);
|
||||
|
||||
if (false === $this->proxiesDirectory) {
|
||||
throw InvalidProxyDirectoryException::proxyDirectoryNotFound($proxiesDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getProxyFileName($className)
|
||||
{
|
||||
return $this->proxiesDirectory . DIRECTORY_SEPARATOR . str_replace('\\', '', $className) . '.php';
|
||||
}
|
||||
}
|
||||
37
vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocatorInterface.php
vendored
Normal file
37
vendor/ocramius/proxy-manager/src/ProxyManager/FileLocator/FileLocatorInterface.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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\FileLocator;
|
||||
|
||||
/**
|
||||
* Basic autoloader utilities required to work with proxy files
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface FileLocatorInterface
|
||||
{
|
||||
/**
|
||||
* Retrieves the file name for the given proxy
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProxyFileName($className);
|
||||
}
|
||||
54
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ClassGenerator.php
vendored
Normal file
54
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ClassGenerator.php
vendored
Normal file
@@ -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\Generator;
|
||||
|
||||
use Zend\Code\Generator\ClassGenerator as ZendClassGenerator;
|
||||
|
||||
/**
|
||||
* Class generator that ensures that interfaces/classes that are implemented/extended are FQCNs
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class ClassGenerator extends ZendClassGenerator
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setExtendedClass($extendedClass)
|
||||
{
|
||||
if ($extendedClass) {
|
||||
$extendedClass = '\\' . trim($extendedClass, '\\');
|
||||
}
|
||||
|
||||
return parent::setExtendedClass($extendedClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setImplementedInterfaces(array $interfaces)
|
||||
{
|
||||
foreach ($interfaces as & $interface) {
|
||||
$interface = '\\' . trim($interface, '\\');
|
||||
}
|
||||
|
||||
return parent::setImplementedInterfaces($interfaces);
|
||||
}
|
||||
}
|
||||
52
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MagicMethodGenerator.php
vendored
Normal file
52
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MagicMethodGenerator.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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\Generator;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Method generator for magic methods
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MagicMethodGenerator extends MethodGenerator
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __construct(ReflectionClass $originalClass, $name, array $parameters = array())
|
||||
{
|
||||
parent::__construct(
|
||||
$name,
|
||||
$parameters,
|
||||
static::FLAG_PUBLIC,
|
||||
null,
|
||||
$originalClass->hasMethod($name) ? '{@inheritDoc}' : null
|
||||
);
|
||||
|
||||
$this->setReturnsReference(strtolower($name) === '__get');
|
||||
|
||||
if ($originalClass->hasMethod($name)) {
|
||||
$this->setReturnsReference($originalClass->getMethod($name)->returnsReference());
|
||||
}
|
||||
}
|
||||
}
|
||||
161
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MethodGenerator.php
vendored
Normal file
161
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/MethodGenerator.php
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
<?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\Generator;
|
||||
|
||||
use Zend\Code\Generator\DocBlockGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator as ZendMethodGenerator;
|
||||
use Zend\Code\Reflection\MethodReflection;
|
||||
|
||||
/**
|
||||
* Method generator that fixes minor quirks in ZF2's method generator
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class MethodGenerator extends ZendMethodGenerator
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $returnsReference = false;
|
||||
|
||||
/**
|
||||
* @param boolean $returnsReference
|
||||
*/
|
||||
public function setReturnsReference($returnsReference)
|
||||
{
|
||||
$this->returnsReference = (bool) $returnsReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function returnsReference()
|
||||
{
|
||||
return $this->returnsReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override enforces generation of \ProxyManager\Generator\MethodGenerator
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function fromReflection(MethodReflection $reflectionMethod)
|
||||
{
|
||||
/* @var $method self */
|
||||
$method = new static();
|
||||
|
||||
$method->setSourceContent($reflectionMethod->getContents(false));
|
||||
$method->setSourceDirty(false);
|
||||
|
||||
if ($reflectionMethod->getDocComment() != '') {
|
||||
$method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock()));
|
||||
}
|
||||
|
||||
$method->setFinal($reflectionMethod->isFinal());
|
||||
$method->setVisibility(self::extractVisibility($reflectionMethod));
|
||||
|
||||
foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
|
||||
$method->setParameter(ParameterGenerator::fromReflection($reflectionParameter));
|
||||
}
|
||||
|
||||
$method->setStatic($reflectionMethod->isStatic());
|
||||
$method->setName($reflectionMethod->getName());
|
||||
$method->setBody($reflectionMethod->getBody());
|
||||
$method->setReturnsReference($reflectionMethod->returnsReference());
|
||||
|
||||
return $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the visibility for the given method reflection
|
||||
*
|
||||
* @param MethodReflection $reflectionMethod
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function extractVisibility(MethodReflection $reflectionMethod)
|
||||
{
|
||||
if ($reflectionMethod->isPrivate()) {
|
||||
return static::VISIBILITY_PRIVATE;
|
||||
}
|
||||
|
||||
if ($reflectionMethod->isProtected()) {
|
||||
return static::VISIBILITY_PROTECTED;
|
||||
}
|
||||
|
||||
return static::VISIBILITY_PUBLIC;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override fixes by-reference return value in zf2's method generator
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$output = '';
|
||||
$indent = $this->getIndentation();
|
||||
|
||||
if (null !== ($docBlock = $this->getDocBlock())) {
|
||||
$docBlock->setIndentation($indent);
|
||||
|
||||
$output .= $docBlock->generate();
|
||||
}
|
||||
|
||||
$output .= $indent . $this->generateMethodDeclaration() . self::LINE_FEED . $indent . '{' . self::LINE_FEED;
|
||||
|
||||
if ($this->body) {
|
||||
$output .= preg_replace('#^(.+?)$#m', $indent . $indent . '$1', trim($this->body))
|
||||
. self::LINE_FEED;
|
||||
}
|
||||
|
||||
$output .= $indent . '}' . self::LINE_FEED;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function generateMethodDeclaration()
|
||||
{
|
||||
$output = $this->generateVisibility()
|
||||
. ' function '
|
||||
. (($this->returnsReference()) ? '& ' : '')
|
||||
. $this->getName() . '(';
|
||||
|
||||
$parameterOutput = array();
|
||||
|
||||
foreach ($this->getParameters() as $parameter) {
|
||||
$parameterOutput[] = $parameter->generate();
|
||||
}
|
||||
|
||||
return $output . implode(', ', $parameterOutput) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function generateVisibility()
|
||||
{
|
||||
return $this->isAbstract() ? 'abstract ' : (($this->isFinal()) ? 'final ' : '')
|
||||
. ($this->getVisibility() . (($this->isStatic()) ? ' static' : ''));
|
||||
}
|
||||
}
|
||||
149
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ParameterGenerator.php
vendored
Normal file
149
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/ParameterGenerator.php
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
<?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\Generator;
|
||||
|
||||
use ReflectionException;
|
||||
use Zend\Code\Generator\ParameterGenerator as ZendParameterGenerator;
|
||||
use Zend\Code\Generator\ValueGenerator;
|
||||
use Zend\Code\Reflection\ParameterReflection;
|
||||
|
||||
/**
|
||||
* Parameter generator that ensures that the parameter type is a FQCN when it is a class
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class ParameterGenerator extends ZendParameterGenerator
|
||||
{
|
||||
/**
|
||||
* @override - uses `static` to instantiate the parameter
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function fromReflection(ParameterReflection $reflectionParameter)
|
||||
{
|
||||
/* @var $param self */
|
||||
$param = new static();
|
||||
|
||||
$param->setName($reflectionParameter->getName());
|
||||
$param->setPosition($reflectionParameter->getPosition());
|
||||
|
||||
$type = self::extractParameterType($reflectionParameter);
|
||||
|
||||
if (null !== $type) {
|
||||
$param->setType($type);
|
||||
}
|
||||
|
||||
self::setOptionalParameter($param, $reflectionParameter);
|
||||
|
||||
$param->setPassedByReference($reflectionParameter->isPassedByReference());
|
||||
|
||||
return $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the type of a reflection parameter (null if none is found)
|
||||
*
|
||||
* @param ParameterReflection $reflectionParameter
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private static function extractParameterType(ParameterReflection $reflectionParameter)
|
||||
{
|
||||
if ($reflectionParameter->isArray()) {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
if (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
|
||||
return 'callable';
|
||||
}
|
||||
|
||||
if ($typeClass = $reflectionParameter->getClass()) {
|
||||
return $typeClass->getName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
return $this->getGeneratedType()
|
||||
. (true === $this->passedByReference ? '&' : '')
|
||||
. '$' . $this->name
|
||||
. $this->generateDefaultValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function generateDefaultValue()
|
||||
{
|
||||
if (null === $this->defaultValue) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$defaultValue = $this->defaultValue instanceof ValueGenerator
|
||||
? $this->defaultValue
|
||||
: new ValueGenerator($this->defaultValue);
|
||||
|
||||
$defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE);
|
||||
|
||||
return ' = ' . $defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the generated parameter type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getGeneratedType()
|
||||
{
|
||||
if (! $this->type || in_array($this->type, static::$simple)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ('array' === $this->type || 'callable' === $this->type) {
|
||||
return $this->type . ' ';
|
||||
}
|
||||
|
||||
return '\\' . trim($this->type, '\\') . ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default value for a parameter (if it is optional)
|
||||
*
|
||||
* @param ZendParameterGenerator $parameterGenerator
|
||||
* @param ParameterReflection $reflectionParameter
|
||||
*/
|
||||
private static function setOptionalParameter(
|
||||
ZendParameterGenerator $parameterGenerator,
|
||||
ParameterReflection $reflectionParameter
|
||||
) {
|
||||
if ($reflectionParameter->isOptional()) {
|
||||
try {
|
||||
$parameterGenerator->setDefaultValue($reflectionParameter->getDefaultValue());
|
||||
} catch (ReflectionException $e) {
|
||||
$parameterGenerator->setDefaultValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/ClassGeneratorUtils.php
vendored
Normal file
53
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/ClassGeneratorUtils.php
vendored
Normal file
@@ -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\Generator\Util;
|
||||
|
||||
use ReflectionClass;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
use Zend\Code\Generator\MethodGenerator;
|
||||
|
||||
/**
|
||||
* Util class to help to generate code
|
||||
*
|
||||
* @author Jefersson Nathan <malukenho@phpse.net>
|
||||
* @license MIT
|
||||
*/
|
||||
final class ClassGeneratorUtils
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $originalClass
|
||||
* @param ClassGenerator $classGenerator
|
||||
* @param MethodGenerator $generatedMethod
|
||||
*
|
||||
* @return void|false
|
||||
*/
|
||||
public static function addMethodIfNotFinal(
|
||||
ReflectionClass $originalClass,
|
||||
ClassGenerator $classGenerator,
|
||||
MethodGenerator $generatedMethod
|
||||
) {
|
||||
$methodName = $generatedMethod->getName();
|
||||
|
||||
if ($originalClass->hasMethod($methodName) && $originalClass->getMethod($methodName)->isFinal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$classGenerator->addMethodFromGenerator($generatedMethod);
|
||||
}
|
||||
}
|
||||
53
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/UniqueIdentifierGenerator.php
vendored
Normal file
53
vendor/ocramius/proxy-manager/src/ProxyManager/Generator/Util/UniqueIdentifierGenerator.php
vendored
Normal file
@@ -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\Generator\Util;
|
||||
|
||||
/**
|
||||
* Utility class capable of generating unique
|
||||
* valid class/property/method identifiers
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
abstract class UniqueIdentifierGenerator
|
||||
{
|
||||
const VALID_IDENTIFIER_FORMAT = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/';
|
||||
const DEFAULT_IDENTIFIER = 'g';
|
||||
|
||||
/**
|
||||
* Generates a valid unique identifier from the given name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getIdentifier($name)
|
||||
{
|
||||
return str_replace(
|
||||
'.',
|
||||
'',
|
||||
uniqid(
|
||||
preg_match(static::VALID_IDENTIFIER_FORMAT, $name)
|
||||
? $name
|
||||
: static::DEFAULT_IDENTIFIER,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
38
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/BaseGeneratorStrategy.php
vendored
Normal file
38
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/BaseGeneratorStrategy.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\GeneratorStrategy;
|
||||
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
|
||||
/**
|
||||
* Generator strategy that generates the class body
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class BaseGeneratorStrategy implements GeneratorStrategyInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator)
|
||||
{
|
||||
return $classGenerator->generate();
|
||||
}
|
||||
}
|
||||
69
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/EvaluatingGeneratorStrategy.php
vendored
Normal file
69
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/EvaluatingGeneratorStrategy.php
vendored
Normal file
@@ -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\GeneratorStrategy;
|
||||
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
|
||||
/**
|
||||
* Generator strategy that produces the code and evaluates it at runtime
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class EvaluatingGeneratorStrategy implements GeneratorStrategyInterface
|
||||
{
|
||||
/**
|
||||
* @var bool flag indicating whether {@see eval} can be used
|
||||
*/
|
||||
private $canEval = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->canEval = ! ini_get('suhosin.executor.disable_eval');
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the generated code before returning it
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator)
|
||||
{
|
||||
$code = $classGenerator->generate();
|
||||
|
||||
if (! $this->canEval) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$fileName = sys_get_temp_dir() . '/EvaluatingGeneratorStrategy.php.tmp.' . uniqid('', true);
|
||||
|
||||
file_put_contents($fileName, "<?php\n" . $code);
|
||||
require $fileName;
|
||||
unlink($fileName);
|
||||
|
||||
return $code;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
eval($code);
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
105
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php
vendored
Normal file
105
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
<?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\GeneratorStrategy;
|
||||
|
||||
use ProxyManager\Exception\FileNotWritableException;
|
||||
use ProxyManager\FileLocator\FileLocatorInterface;
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
|
||||
/**
|
||||
* Generator strategy that writes the generated classes to disk while generating them
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class FileWriterGeneratorStrategy implements GeneratorStrategyInterface
|
||||
{
|
||||
/**
|
||||
* @var \ProxyManager\FileLocator\FileLocatorInterface
|
||||
*/
|
||||
protected $fileLocator;
|
||||
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
private $emptyErrorHandler;
|
||||
|
||||
/**
|
||||
* @param \ProxyManager\FileLocator\FileLocatorInterface $fileLocator
|
||||
*/
|
||||
public function __construct(FileLocatorInterface $fileLocator)
|
||||
{
|
||||
$this->fileLocator = $fileLocator;
|
||||
$this->emptyErrorHandler = function () {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Write generated code to disk and return the class code
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator)
|
||||
{
|
||||
$className = trim($classGenerator->getNamespaceName(), '\\')
|
||||
. '\\' . trim($classGenerator->getName(), '\\');
|
||||
$generatedCode = $classGenerator->generate();
|
||||
$fileName = $this->fileLocator->getProxyFileName($className);
|
||||
|
||||
set_error_handler($this->emptyErrorHandler);
|
||||
|
||||
try {
|
||||
$this->writeFile("<?php\n\n" . $generatedCode, $fileName);
|
||||
} catch (FileNotWritableException $fileNotWritable) {
|
||||
restore_error_handler();
|
||||
|
||||
throw $fileNotWritable;
|
||||
}
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
return $generatedCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the source file in such a way that race conditions are avoided when the same file is written
|
||||
* multiple times in a short time period
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $location
|
||||
*
|
||||
* @throws FileNotWritableException
|
||||
*/
|
||||
private function writeFile($source, $location)
|
||||
{
|
||||
$tmpFileName = $location . '.' . uniqid('', true);
|
||||
|
||||
if (! file_put_contents($tmpFileName, $source)) {
|
||||
throw FileNotWritableException::fromNonWritableLocation($tmpFileName);
|
||||
}
|
||||
|
||||
if (! rename($tmpFileName, $location)) {
|
||||
unlink($tmpFileName);
|
||||
|
||||
throw FileNotWritableException::fromInvalidMoveOperation($tmpFileName, $location);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/GeneratorStrategyInterface.php
vendored
Normal file
39
vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/GeneratorStrategyInterface.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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\GeneratorStrategy;
|
||||
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
|
||||
/**
|
||||
* Generator strategy interface - defines basic behavior of class generators
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface GeneratorStrategyInterface
|
||||
{
|
||||
/**
|
||||
* Generate the provided class
|
||||
*
|
||||
* @param ClassGenerator $classGenerator
|
||||
*
|
||||
* @return string the class body
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator);
|
||||
}
|
||||
98
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflector.php
vendored
Normal file
98
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflector.php
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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\Inflector;
|
||||
|
||||
use ProxyManager\Inflector\Util\ParameterHasher;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
final class ClassNameInflector implements ClassNameInflectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $proxyNamespace;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $proxyMarkerLength;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $proxyMarker;
|
||||
|
||||
/**
|
||||
* @var \ProxyManager\Inflector\Util\ParameterHasher
|
||||
*/
|
||||
private $parameterHasher;
|
||||
|
||||
/**
|
||||
* @param string $proxyNamespace
|
||||
*/
|
||||
public function __construct($proxyNamespace)
|
||||
{
|
||||
$this->proxyNamespace = (string) $proxyNamespace;
|
||||
$this->proxyMarker = '\\' . static::PROXY_MARKER . '\\';
|
||||
$this->proxyMarkerLength = strlen($this->proxyMarker);
|
||||
$this->parameterHasher = new ParameterHasher();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getUserClassName($className)
|
||||
{
|
||||
$className = ltrim($className, '\\');
|
||||
|
||||
if (false === $position = strrpos($className, $this->proxyMarker)) {
|
||||
return $className;
|
||||
}
|
||||
|
||||
return substr(
|
||||
$className,
|
||||
$this->proxyMarkerLength + $position,
|
||||
strrpos($className, '\\') - ($position + $this->proxyMarkerLength)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getProxyClassName($className, array $options = array())
|
||||
{
|
||||
return $this->proxyNamespace
|
||||
. $this->proxyMarker
|
||||
. $this->getUserClassName($className)
|
||||
. '\\Generated' . $this->parameterHasher->hashParameters($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isProxyClassName($className)
|
||||
{
|
||||
return false !== strrpos($className, $this->proxyMarker);
|
||||
}
|
||||
}
|
||||
61
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflectorInterface.php
vendored
Normal file
61
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/ClassNameInflectorInterface.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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\Inflector;
|
||||
|
||||
/**
|
||||
* Interface for a proxy- to user-class and user- to proxy-class name inflector
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface ClassNameInflectorInterface
|
||||
{
|
||||
/**
|
||||
* Marker for proxy classes - classes containing this marker are considered proxies
|
||||
*/
|
||||
const PROXY_MARKER = '__PM__';
|
||||
|
||||
/**
|
||||
* Retrieve the class name of a user-defined class
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserClassName($className);
|
||||
|
||||
/**
|
||||
* Retrieve the class name of the proxy for the given user-defined class name
|
||||
*
|
||||
* @param string $className
|
||||
* @param array $options arbitrary options to be used for the generated class name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProxyClassName($className, array $options = array());
|
||||
|
||||
/**
|
||||
* Retrieve whether the provided class name is a proxy
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isProxyClassName($className);
|
||||
}
|
||||
41
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/Util/ParameterEncoder.php
vendored
Normal file
41
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/Util/ParameterEncoder.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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\Inflector\Util;
|
||||
|
||||
/**
|
||||
* Encodes parameters into a class-name safe string
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class ParameterEncoder
|
||||
{
|
||||
/**
|
||||
* Converts the given parameters into a set of characters that are safe to
|
||||
* use in a class name
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encodeParameters(array $parameters)
|
||||
{
|
||||
return base64_encode(serialize($parameters));
|
||||
}
|
||||
}
|
||||
40
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/Util/ParameterHasher.php
vendored
Normal file
40
vendor/ocramius/proxy-manager/src/ProxyManager/Inflector/Util/ParameterHasher.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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\Inflector\Util;
|
||||
|
||||
/**
|
||||
* Converts given parameters into a likely unique hash
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class ParameterHasher
|
||||
{
|
||||
/**
|
||||
* Converts the given parameters into a likely-unique hash
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function hashParameters(array $parameters)
|
||||
{
|
||||
return md5(serialize($parameters));
|
||||
}
|
||||
}
|
||||
64
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/AccessInterceptorInterface.php
vendored
Normal file
64
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/AccessInterceptorInterface.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Access interceptor object marker
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface AccessInterceptorInterface extends ProxyInterface
|
||||
{
|
||||
/**
|
||||
* Set or remove the prefix interceptor for a method
|
||||
*
|
||||
* @link https://github.com/Ocramius/ProxyManager/blob/master/docs/access-interceptor-value-holder.md
|
||||
*
|
||||
* A prefix interceptor should have a signature like following:
|
||||
*
|
||||
* <code>
|
||||
* $prefixInterceptor = function ($proxy, $instance, $method, $params, & $returnEarly) {};
|
||||
* </code>
|
||||
*
|
||||
* @param string $methodName name of the intercepted method
|
||||
* @param \Closure|null $prefixInterceptor interceptor closure or null to unset the currently active interceptor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMethodPrefixInterceptor($methodName, \Closure $prefixInterceptor = null);
|
||||
|
||||
/**
|
||||
* Set or remove the suffix interceptor for a method
|
||||
*
|
||||
* @link https://github.com/Ocramius/ProxyManager/blob/master/docs/access-interceptor-value-holder.md
|
||||
*
|
||||
* A prefix interceptor should have a signature like following:
|
||||
*
|
||||
* <code>
|
||||
* $suffixInterceptor = function ($proxy, $instance, $method, $params, $returnValue, & $returnEarly) {};
|
||||
* </code>
|
||||
*
|
||||
* @param string $methodName name of the intercepted method
|
||||
* @param \Closure|null $suffixInterceptor interceptor closure or null to unset the currently active interceptor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMethodSuffixInterceptor($methodName, \Closure $suffixInterceptor = null);
|
||||
}
|
||||
31
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/Exception/RemoteObjectException.php
vendored
Normal file
31
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/Exception/RemoteObjectException.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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\Proxy\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Remote object exception
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
class RemoteObjectException extends RuntimeException
|
||||
{
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/FallbackValueHolderInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/FallbackValueHolderInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Fallback value holder object marker
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface FallbackValueHolderInterface extends ProxyInterface
|
||||
{
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/GhostObjectInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/GhostObjectInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Ghost object marker
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface GhostObjectInterface extends LazyLoadingInterface
|
||||
{
|
||||
}
|
||||
64
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/LazyLoadingInterface.php
vendored
Normal file
64
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/LazyLoadingInterface.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Lazy loading object identifier
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface LazyLoadingInterface extends ProxyInterface
|
||||
{
|
||||
/**
|
||||
* Set or unset the initializer for the proxy instance
|
||||
*
|
||||
* @link https://github.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-value-holder.md#lazy-initialization
|
||||
*
|
||||
* An initializer should have a signature like following:
|
||||
*
|
||||
* <code>
|
||||
* $initializer = function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) {};
|
||||
* </code>
|
||||
*
|
||||
* @param \Closure|null $initializer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setProxyInitializer(\Closure $initializer = null);
|
||||
|
||||
/**
|
||||
* @return \Closure|null
|
||||
*/
|
||||
public function getProxyInitializer();
|
||||
|
||||
/**
|
||||
* Force initialization of the proxy
|
||||
*
|
||||
* @return bool true if the proxy could be initialized
|
||||
*/
|
||||
public function initializeProxy();
|
||||
|
||||
/**
|
||||
* Retrieves current initialization status of the proxy
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isProxyInitialized();
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/NullObjectInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/NullObjectInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Null object marker
|
||||
*
|
||||
* @author Vincent Blanchon <blanchon.vincent@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface NullObjectInterface extends ProxyInterface
|
||||
{
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ProxyInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ProxyInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Base proxy marker
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface ProxyInterface
|
||||
{
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/RemoteObjectInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/RemoteObjectInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Remote object marker
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface RemoteObjectInterface extends ProxyInterface
|
||||
{
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/SmartReferenceInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/SmartReferenceInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Smart reference object marker
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface SmartReferenceInterface extends ProxyInterface
|
||||
{
|
||||
}
|
||||
33
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ValueHolderInterface.php
vendored
Normal file
33
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/ValueHolderInterface.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Value holder marker
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface ValueHolderInterface extends ProxyInterface
|
||||
{
|
||||
/**
|
||||
* @return object|null the wrapped value
|
||||
*/
|
||||
public function getWrappedValueHolderValue();
|
||||
}
|
||||
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/VirtualProxyInterface.php
vendored
Normal file
29
vendor/ocramius/proxy-manager/src/ProxyManager/Proxy/VirtualProxyInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Proxy;
|
||||
|
||||
/**
|
||||
* Virtual Proxy - a lazy initializing object wrapping around the proxied subject
|
||||
*
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
interface VirtualProxyInterface extends LazyLoadingInterface, ValueHolderInterface
|
||||
{
|
||||
}
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user