Augmentation vers version 3.3.0
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ProxyManager\GeneratorStrategy;
|
||||
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
@@ -31,7 +33,7 @@ class BaseGeneratorStrategy implements GeneratorStrategyInterface
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator)
|
||||
public function generate(ClassGenerator $classGenerator) : string
|
||||
{
|
||||
return $classGenerator->generate();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ProxyManager\GeneratorStrategy;
|
||||
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
@@ -38,7 +40,9 @@ class EvaluatingGeneratorStrategy implements GeneratorStrategyInterface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
$this->canEval = ! ini_get('suhosin.executor.disable_eval');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,21 +50,22 @@ class EvaluatingGeneratorStrategy implements GeneratorStrategyInterface
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator)
|
||||
public function generate(ClassGenerator $classGenerator) : string
|
||||
{
|
||||
$code = $classGenerator->generate();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (! $this->canEval) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$fileName = sys_get_temp_dir() . '/EvaluatingGeneratorStrategy.php.tmp.' . uniqid('', true);
|
||||
$fileName = tempnam(sys_get_temp_dir(), 'EvaluatingGeneratorStrategy.php.tmp.');
|
||||
|
||||
file_put_contents($fileName, "<?php\n" . $code);
|
||||
/* @noinspection PhpIncludeInspection */
|
||||
require $fileName;
|
||||
unlink($fileName);
|
||||
|
||||
return $code;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
eval($code);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ProxyManager\GeneratorStrategy;
|
||||
|
||||
use ProxyManager\Exception\FileNotWritableException;
|
||||
@@ -56,8 +58,10 @@ class FileWriterGeneratorStrategy implements GeneratorStrategyInterface
|
||||
* Write generated code to disk and return the class code
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws FileNotWritableException
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator)
|
||||
public function generate(ClassGenerator $classGenerator) : string
|
||||
{
|
||||
$className = trim($classGenerator->getNamespaceName(), '\\')
|
||||
. '\\' . trim($classGenerator->getName(), '\\');
|
||||
@@ -68,15 +72,11 @@ class FileWriterGeneratorStrategy implements GeneratorStrategyInterface
|
||||
|
||||
try {
|
||||
$this->writeFile("<?php\n\n" . $generatedCode, $fileName);
|
||||
} catch (FileNotWritableException $fileNotWritable) {
|
||||
|
||||
return $generatedCode;
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
|
||||
throw $fileNotWritable;
|
||||
}
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
return $generatedCode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,13 +88,11 @@ class FileWriterGeneratorStrategy implements GeneratorStrategyInterface
|
||||
*
|
||||
* @throws FileNotWritableException
|
||||
*/
|
||||
private function writeFile($source, $location)
|
||||
private function writeFile(string $source, string $location) : void
|
||||
{
|
||||
$tmpFileName = $location . '.' . uniqid('', true);
|
||||
$tmpFileName = tempnam($location, 'temporaryProxyManagerFile');
|
||||
|
||||
if (! file_put_contents($tmpFileName, $source)) {
|
||||
throw FileNotWritableException::fromNonWritableLocation($tmpFileName);
|
||||
}
|
||||
file_put_contents($tmpFileName, $source);
|
||||
|
||||
if (! rename($tmpFileName, $location)) {
|
||||
unlink($tmpFileName);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
* and is licensed under the MIT license.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ProxyManager\GeneratorStrategy;
|
||||
|
||||
use Zend\Code\Generator\ClassGenerator;
|
||||
@@ -35,5 +37,5 @@ interface GeneratorStrategyInterface
|
||||
*
|
||||
* @return string the class body
|
||||
*/
|
||||
public function generate(ClassGenerator $classGenerator);
|
||||
public function generate(ClassGenerator $classGenerator) : string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user