Ajout du FR

Ajout du FR + correction du "functions.php"
This commit is contained in:
Gauvain Boiché
2020-03-30 14:52:34 +02:00
commit 5e4c5f9418
4541 changed files with 608941 additions and 0 deletions

View 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);
}
}

View 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());
}
}
}

View 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' : ''));
}
}

View 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);
}
}
}
}

View 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);
}
}

View 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
)
);
}
}