updated packages

This commit is contained in:
2019-05-18 09:06:43 +00:00
parent 901d16349e
commit e9487fa58a
2025 changed files with 30366 additions and 49653 deletions

View File

@@ -1,6 +1,29 @@
CHANGELOG
---------
### v3.2.0, 2019.05.05
- Since an unsigned closure can be unserialized when no security provider is set,
there is no reason to treat differently a signed closure in the same situation.
Therefore, the `Opis\Closure\SecurityException` exception is no longer thrown when
unserializing a signed closure, if no security provider is set.
### v3.1.6, 2019.02.22
- Fixed a bug that occurred when trying to set properties of classes that were not defined in user-land.
Those properties are now ignored.
### v3.1.5, 2019.01.14
- Improved parser
### v3.1.4, 2019.01.14
- Added support for static methods that are named using PHP keywords or magic constants.
Ex: `A::new()`, `A::use()`, `A::if()`, `A::function()`, `A::__DIR__()`, etc.
- Used `@internal` to mark classes & methods that are for internal use only and
backward compatibility might be broken at some point.
### v3.1.3, 2019.01.07
- Fixed a bug that prevented traits to be correctly resolved when used by an

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2018 Zindex Software
Copyright (c) 2018-2019 Zindex Software
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View File

@@ -61,7 +61,7 @@ Or you could directly reference it into your `composer.json` file as a dependenc
```json
{
"require": {
"opis/closure": "^3.1"
"opis/closure": "^3.2"
}
}
```

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */

View File

@@ -34,7 +34,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
"dev-master": "3.2.x-dev"
}
}
}

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */
@@ -9,6 +9,7 @@ namespace Opis\Closure;
/**
* Closure context class
* @internal
*/
class ClosureContext
{

View File

@@ -1,15 +1,15 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */
namespace Opis\Closure;
/**
* Closure scope class
* @internal
*/
class ClosureScope extends \SplObjectStorage
{

View File

@@ -1,12 +1,15 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */
namespace Opis\Closure;
/**
* @internal
*/
class ClosureStream
{
const STREAM_PROTO = 'closure';

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */
@@ -104,7 +104,6 @@ class ReflectionClosure extends ReflectionFunction
$_method = var_export($_method, true);
$_trait = null;
$hasTraitSupport = defined('T_TRAIT_C');
$tokens = $this->getTokens();
$state = $lastState = 'start';
$inside_anonymous = false;
@@ -335,43 +334,56 @@ class ReflectionClosure extends ReflectionFunction
$code .= $token[1];
$state = 'closure_args';
break;
default:
if ($hasTraitSupport && $token[0] == T_TRAIT_C) {
if ($_trait === null) {
$startLine = $this->getStartLine();
$endLine = $this->getEndLine();
$structures = $this->getStructures();
case T_TRAIT_C:
if ($_trait === null) {
$startLine = $this->getStartLine();
$endLine = $this->getEndLine();
$structures = $this->getStructures();
$_trait = '';
$_trait = '';
foreach ($structures as &$struct) {
if ($struct['type'] === 'trait' &&
$struct['start'] <= $startLine &&
$struct['end'] >= $endLine
) {
$_trait = ($ns == '' ? '' : $ns . '\\') . $struct['name'];
break;
}
foreach ($structures as &$struct) {
if ($struct['type'] === 'trait' &&
$struct['start'] <= $startLine &&
$struct['end'] >= $endLine
) {
$_trait = ($ns == '' ? '' : $ns . '\\') . $struct['name'];
break;
}
$_trait = var_export($_trait, true);
}
$token[1] = $_trait;
} else {
$code .= is_array($token) ? $token[1] : $token;
$_trait = var_export($_trait, true);
}
$code .= $_trait;
break;
default:
$code .= is_array($token) ? $token[1] : $token;
}
break;
case 'ignore_next':
switch ($token[0]){
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
$code .= $token[1];
break;
case T_CLASS:
case T_NEW:
case T_STATIC:
case T_VARIABLE:
case T_STRING:
case T_CLASS_C:
case T_FILE:
case T_DIR:
case T_METHOD_C:
case T_FUNC_C:
case T_FUNCTION:
case T_INSTANCEOF:
case T_LINE:
case T_NS_C:
case T_TRAIT_C:
case T_USE:
$code .= $token[1];
$state = $lastState;
break;
@@ -383,6 +395,8 @@ class ReflectionClosure extends ReflectionFunction
case 'id_start':
switch ($token[0]){
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
$code .= $token[1];
break;
case T_NS_SEPARATOR:
@@ -413,6 +427,8 @@ class ReflectionClosure extends ReflectionFunction
$id_name .= $token[1];
break;
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
$id_name .= $token[1];
break;
case '(':
@@ -728,6 +744,7 @@ class ReflectionClosure extends ReflectionFunction
$open = 0;
$state = 'start';
$lastState = '';
$prefix = '';
$name = '';
$alias = '';
@@ -737,114 +754,161 @@ class ReflectionClosure extends ReflectionFunction
$structType = $structName = '';
$structIgnore = false;
$hasTraitSupport = defined('T_TRAIT');
foreach ($tokens as $token) {
$is_array = is_array($token);
switch ($state) {
case 'start':
if ($is_array) {
switch ($token[0]) {
case T_CLASS:
case T_INTERFACE:
$state = 'before_structure';
$startLine = $token[2];
$structType = $token[0] == T_CLASS ? 'class' : 'interface';
break;
case T_USE:
$state = 'use';
$prefix = $name = $alias = '';
$isFunc = $isConst = false;
break;
case T_FUNCTION:
$state = 'structure';
$structIgnore = true;
break;
default:
if ($hasTraitSupport && $token[0] == T_TRAIT) {
$state = 'before_structure';
$startLine = $token[2];
$structType = 'trait';
}
break;
}
switch ($token[0]) {
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
$state = 'before_structure';
$startLine = $token[2];
$structType = $token[0] == T_CLASS
? 'class'
: ($token[0] == T_INTERFACE ? 'interface' : 'trait');
break;
case T_USE:
$state = 'use';
$prefix = $name = $alias = '';
$isFunc = $isConst = false;
break;
case T_FUNCTION:
$state = 'structure';
$structIgnore = true;
break;
case T_NEW:
$state = 'new';
break;
case T_OBJECT_OPERATOR:
case T_DOUBLE_COLON:
$state = 'invoke';
break;
}
break;
case 'use':
if ($is_array) {
switch ($token[0]) {
case T_FUNCTION:
$isFunc = true;
break;
case T_CONST:
$isConst = true;
break;
case T_NS_SEPARATOR:
$name .= $token[1];
break;
case T_STRING:
$name .= $token[1];
$alias = $token[1];
break;
case T_AS:
if ($name[0] !== '\\' && $prefix === '') {
$name = '\\' . $name;
}
$state = 'alias';
break;
}
} elseif ($name === '') {
$state = 'start';
} else {
if ($name[0] !== '\\' && $prefix === '') {
$name = '\\' . $name;
}
if($token == '{') {
switch ($token[0]) {
case T_FUNCTION:
$isFunc = true;
break;
case T_CONST:
$isConst = true;
break;
case T_NS_SEPARATOR:
$name .= $token[1];
break;
case T_STRING:
$name .= $token[1];
$alias = $token[1];
break;
case T_AS:
$lastState = 'use';
$state = 'alias';
break;
case '{':
$prefix = $name;
$name = '';
} else {
if($isFunc){
$functions[strtolower($alias)] = $prefix . $name;
} elseif ($isConst){
$constants[$alias] = $prefix . $name;
} else {
$classes[strtolower($alias)] = $prefix . $name;
$name = $alias = '';
$state = 'use-group';
break;
case ',':
case ';':
if ($name === '' || $name[0] !== '\\') {
$name = '\\' . $name;
}
$name = '';
$state = 'use';
}
if ($alias !== '') {
if ($isFunc) {
$functions[strtolower($alias)] = $name;
} elseif ($isConst) {
$constants[$alias] = $name;
} else {
$classes[strtolower($alias)] = $name;
}
}
$name = $alias = '';
$state = $token === ';' ? 'start' : 'use';
break;
}
break;
case 'use-group':
switch ($token[0]) {
case T_NS_SEPARATOR:
$name .= $token[1];
break;
case T_STRING:
$name .= $token[1];
$alias = $token[1];
break;
case T_AS:
$lastState = 'use-group';
$state = 'alias';
break;
case ',':
case '}':
if ($prefix === '' || $prefix[0] !== '\\') {
$prefix = '\\' . $prefix;
}
if ($alias !== '') {
if ($isFunc) {
$functions[strtolower($alias)] = $prefix . $name;
} elseif ($isConst) {
$constants[$alias] = $prefix . $name;
} else {
$classes[strtolower($alias)] = $prefix . $name;
}
}
$name = $alias = '';
$state = $token === '}' ? 'use' : 'use-group';
break;
}
break;
case 'alias':
if ($is_array) {
if($token[0] == T_STRING){
$alias = $token[1];
}
} else {
if($isFunc){
$functions[strtolower($alias)] = $prefix . $name;
} elseif ($isConst){
$constants[$alias] = $prefix . $name;
} else {
$classes[strtolower($alias)] = $prefix . $name;
}
$name = '';
$state = $token == ',' ? 'use' : 'start';
if ($token[0] === T_STRING) {
$alias = $token[1];
$state = $lastState;
}
break;
case 'new':
switch ($token[0]) {
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
break 2;
case T_CLASS:
$state = 'structure';
$structIgnore = true;
break;
default:
$state = 'start';
}
break;
case 'invoke':
switch ($token[0]) {
case T_WHITESPACE:
case T_COMMENT:
case T_DOC_COMMENT:
break 2;
default:
$state = 'start';
}
break;
case 'before_structure':
if ($is_array && $token[0] == T_STRING) {
if ($token[0] == T_STRING) {
$structName = $token[1];
$state = 'structure';
}
break;
case 'structure':
if (!$is_array) {
if ($token === '{') {
switch ($token[0]) {
case '{':
case T_CURLY_OPEN:
case T_DOLLAR_OPEN_CURLY_BRACES:
case T_STRING_VARNAME:
$open++;
} elseif ($token === '}') {
break;
case '}':
if (--$open == 0) {
if(!$structIgnore){
$structures[] = array(
@@ -857,14 +921,11 @@ class ReflectionClosure extends ReflectionFunction
$structIgnore = false;
$state = 'start';
}
}
} else {
if($token[0] === T_CURLY_OPEN ||
$token[0] === T_DOLLAR_OPEN_CURLY_BRACES ||
$token[0] === T_STRING_VARNAME){
$open++;
}
$endLine = $token[2];
break;
default:
if (is_array($token)) {
$endLine = $token[2];
}
}
break;
}
@@ -875,5 +936,4 @@ class ReflectionClosure extends ReflectionFunction
static::$constants[$key] = $constants;
static::$structures[$key] = $structures;
}
}

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */
@@ -10,6 +10,7 @@ namespace Opis\Closure;
/**
* Helper class used to indicate a reference to an object
* @internal
*/
class SelfReference
{

View File

@@ -1,6 +1,6 @@
<?php
/* ===========================================================================
* Copyright (c) 2018 Zindex Software
* Copyright (c) 2018-2019 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */
@@ -203,8 +203,13 @@ class SerializableClosure implements Serializable
$data = $data['closure'];
} elseif ($data[0] === '@') {
throw new SecurityException("The serialized closure is signed. ".
"Make sure you use a security provider for both serialization and unserialization.");
$data = json_decode(substr($data, 1), true);
if (!is_array($data) || !isset($data['closure']) || !isset($data['hash'])) {
throw new SecurityException('Invalid signed closure');
}
$data = $data['closure'];
}
$this->code = \unserialize($data);
@@ -332,6 +337,7 @@ class SerializableClosure implements Serializable
/**
* Wrap closures
*
* @internal
* @param $data
* @param ClosureScope|SplObjectStorage|null $storage
*/
@@ -386,7 +392,7 @@ class SerializableClosure implements Serializable
break;
}
foreach ($reflection->getProperties() as $property){
if($property->isStatic()){
if($property->isStatic() || !$property->getDeclaringClass()->isUserDefined()){
continue;
}
$property->setAccessible(true);
@@ -405,6 +411,7 @@ class SerializableClosure implements Serializable
/**
* Unwrap closures
*
* @internal
* @param $data
* @param SplObjectStorage|null $storage
*/
@@ -448,7 +455,7 @@ class SerializableClosure implements Serializable
break;
}
foreach ($reflection->getProperties() as $property){
if($property->isStatic()){
if($property->isStatic() || !$property->getDeclaringClass()->isUserDefined()){
continue;
}
$property->setAccessible(true);
@@ -464,6 +471,7 @@ class SerializableClosure implements Serializable
/**
* Internal method used to map closure pointers
* @internal
* @param $data
*/
protected function mapPointers(&$data)
@@ -514,7 +522,7 @@ class SerializableClosure implements Serializable
break;
}
foreach ($reflection->getProperties() as $property){
if($property->isStatic()){
if($property->isStatic() || !$property->getDeclaringClass()->isUserDefined()){
continue;
}
$property->setAccessible(true);
@@ -537,6 +545,7 @@ class SerializableClosure implements Serializable
/**
* Internal method used to map closures by reference
*
* @internal
* @param mixed &$data
*/
protected function mapByReference(&$data)
@@ -605,7 +614,7 @@ class SerializableClosure implements Serializable
break;
}
foreach ($reflection->getProperties() as $property){
if($property->isStatic()){
if($property->isStatic() || !$property->getDeclaringClass()->isUserDefined()){
continue;
}
$property->setAccessible(true);