-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix enums and new in initializers as default values on PHP 8.1
- Loading branch information
1 parent
c828ced
commit f256701
Showing
21 changed files
with
261 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ProxyManager\Generator; | ||
|
||
use Laminas\Code\Generator\ValueGenerator as LaminasValueGenerator; | ||
use Laminas\Code\Generator\Exception\RuntimeException; | ||
use ReflectionParameter; | ||
|
||
use function implode; | ||
use function is_array; | ||
use function preg_replace; | ||
use function preg_split; | ||
|
||
use const PREG_SPLIT_DELIM_CAPTURE; | ||
|
||
/** | ||
* @internal do not use this in your code: it is only here for internal use | ||
*/ | ||
class ValueGenerator extends LaminasValueGenerator | ||
{ | ||
private $reflection; | ||
|
||
public function __construct($value, ?ReflectionParameter $reflection = null) | ||
{ | ||
if ($value instanceof LaminasValueGenerator) { | ||
foreach ($value as $k => $v) { | ||
$this->$k = $v; | ||
} | ||
} else { | ||
parent::__construct($value, parent::TYPE_AUTO, parent::OUTPUT_SINGLE_LINE); | ||
} | ||
|
||
$this->reflection = $reflection; | ||
} | ||
|
||
public function generate(): string | ||
{ | ||
try { | ||
return parent::generate(); | ||
} catch (RuntimeException $e) { | ||
if ($this->reflection) { | ||
$value = rtrim(substr(explode('$' . $this->reflection->name . ' = ', (string) $this->reflection, 2)[1], 0, -2)); | ||
} else { | ||
$value = var_export($this->value, true); | ||
} | ||
|
||
return self::fixExport($value); | ||
} | ||
} | ||
|
||
private static function fixExport(string $value): string | ||
{ | ||
$parts = preg_split('{(\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')}', $value, -1, PREG_SPLIT_DELIM_CAPTURE); | ||
|
||
foreach ($parts as $i => &$part) { | ||
if ($part !== '' && $i % 2 === 0) { | ||
$part = preg_replace('/(?(DEFINE)(?<V>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+))(?<!\\\\)(?&V)(?:\\\\(?&V))*+::/', '\\\\$0', $part); | ||
} | ||
} | ||
|
||
return implode('', $parts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.