composer update

This commit is contained in:
2019-12-01 06:37:45 +00:00
parent fa199eef05
commit 3115ab75a5
3650 changed files with 72361 additions and 147137 deletions

View File

@@ -1,6 +1,33 @@
CHANGELOG
---------
### v3.5.1, 2019.11.30
- Bugfix. See #47
### v3.5.0, 2019.11.29
- Added support for short closures (arrow functions)
- Added `isShortClosure` method to `Opis\Closure\ReflectionClosure`
### v3.4.2, 2019.11.29
- Added `stream_set_option()`
### v3.4.1, 2019.10.19
- Fixed a [bug](https://github.com/opis/closure/issues/40) that prevented serialization to work correctly.
### v3.4.0, 2019.09.03
- Added `createClosure` static method in `Opis\Closure\SerializableClosure`.
This method creates a new closure from arbitrary code, emulating `create_function`,
but without using eval
### v3.3.1, 2019.07.10
- Use `sha1` instead of `md5` for hashing file names in `Opis\Closure\ReflectionClosure` class
### v3.3.0, 2019.05.31
- Fixed a bug that prevented signed closures to properly work when the serialized string
@@ -29,7 +56,7 @@ Those properties are now ignored.
- 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.
backward compatibility is not guaranteed.
### v3.1.3, 2019.01.07

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.3"
"opis/closure": "^3.5"
}
}
```

View File

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

View File

@@ -41,6 +41,11 @@ class ClosureStream
return $this->pointer >= $this->length;
}
public function stream_set_option($option, $arg1, $arg2)
{
return false;
}
public function stream_stat()
{
$stat = stat(__FILE__);

View File

@@ -19,6 +19,7 @@ class ReflectionClosure extends ReflectionFunction
protected $isStaticClosure;
protected $isScopeRequired;
protected $isBindingRequired;
protected $isShortClosure;
protected static $files = array();
protected static $classes = array();
@@ -51,6 +52,19 @@ class ReflectionClosure extends ReflectionFunction
return $this->isStaticClosure;
}
public function isShortClosure()
{
if ($this->isShortClosure === null) {
$code = $this->getCode();
if ($this->isStatic()) {
$code = substr($code, 6);
}
$this->isShortClosure = strtolower(substr(trim($code), 0, 2)) === 'fn';
}
return $this->isShortClosure;
}
/**
* @return string
*/
@@ -70,6 +84,7 @@ class ReflectionClosure extends ReflectionFunction
}
$className = null;
$fn = false;
if (null !== $className = $this->getClosureScopeClass()) {
@@ -89,6 +104,7 @@ class ReflectionClosure extends ReflectionFunction
default:
$php7_types = array('string', 'int', 'bool', 'float', 'void', 'object');
}
$fn = PHP_MINOR_VERSION === 4;
}
$ns = $this->getNamespaceName();
@@ -107,6 +123,7 @@ class ReflectionClosure extends ReflectionFunction
$tokens = $this->getTokens();
$state = $lastState = 'start';
$inside_anonymous = false;
$isShortClosure = false;
$anonymous_mark = 0;
$open = 0;
$code = '';
@@ -124,6 +141,10 @@ class ReflectionClosure extends ReflectionFunction
if ($token[0] === T_FUNCTION || $token[0] === T_STATIC) {
$code .= $token[1];
$state = $token[0] === T_FUNCTION ? 'function' : 'static';
} elseif ($fn && $token[0] === T_FN) {
$isShortClosure = true;
$code .= $token[1];
$state = 'closure_args';
}
break;
case 'static':
@@ -132,6 +153,10 @@ class ReflectionClosure extends ReflectionFunction
if ($token[0] === T_FUNCTION) {
$state = 'function';
}
} elseif ($fn && $token[0] === T_FN) {
$isShortClosure = true;
$code .= $token[1];
$state = 'closure_args';
} else {
$code = '';
$state = 'start';
@@ -155,6 +180,10 @@ class ReflectionClosure extends ReflectionFunction
if($token[0] === T_FUNCTION || $token[0] === T_STATIC){
$code = $token[1];
$state = $token[0] === T_FUNCTION ? 'function' : 'static';
} elseif ($fn && $token[0] === T_FN) {
$isShortClosure = true;
$code .= $token[1];
$state = 'closure_args';
}
break;
case 'closure_args':
@@ -172,6 +201,12 @@ class ReflectionClosure extends ReflectionFunction
$code .= $token[1];
$state = 'use';
break;
case T_DOUBLE_ARROW:
$code .= $token[1];
if ($isShortClosure) {
$state = 'closure';
}
break;
case '=':
$code .= $token;
$lastState = 'closure_args';
@@ -226,6 +261,12 @@ class ReflectionClosure extends ReflectionFunction
$state = 'id_name';
$lastState = 'return';
break 2;
case T_DOUBLE_ARROW:
$code .= $token[1];
if ($isShortClosure) {
$state = 'closure';
}
break;
case '{':
$code .= '{';
$state = 'closure';
@@ -247,12 +288,36 @@ class ReflectionClosure extends ReflectionFunction
break;
case '}':
$code .= '}';
if(--$open === 0){
if(--$open === 0 && !$isShortClosure){
break 3;
} elseif ($inside_anonymous) {
$inside_anonymous = !($open === $anonymous_mark);
}
break;
case '(':
case '[':
$code .= $token[0];
if ($isShortClosure) {
$open++;
}
break;
case ')':
case ']':
if ($isShortClosure) {
if ($open === 0) {
break 3;
}
--$open;
}
$code .= $token[0];
break;
case ',':
case ';':
if ($isShortClosure && $open === 0) {
break 3;
}
$code .= $token[0];
break;
case T_LINE:
$code .= $token[2] - $line + $lineAdd;
break;
@@ -432,6 +497,9 @@ class ReflectionClosure extends ReflectionFunction
$id_name .= $token[1];
break;
case '(':
if ($isShortClosure) {
$open++;
}
if($context === 'new' || false !== strpos($id_name, '\\')){
if($id_start !== '\\'){
if ($classes === null) {
@@ -538,10 +606,17 @@ class ReflectionClosure extends ReflectionFunction
}
}
if ($isShortClosure) {
$code .= ';';
$this->useVariables = $this->getStaticVariables();
} else {
$this->useVariables = empty($use) ? $use : array_intersect_key($this->getStaticVariables(), array_flip($use));
}
$this->isShortClosure = $isShortClosure;
$this->isBindingRequired = $isUsingThisObject;
$this->isScopeRequired = $isUsingScope;
$this->code = $code;
$this->useVariables = empty($use) ? $use : array_intersect_key($this->getStaticVariables(), array_flip($use));
return $this->code;
}
@@ -615,7 +690,7 @@ class ReflectionClosure extends ReflectionFunction
protected function getHashedFileName()
{
if ($this->hashedName === null) {
$this->hashedName = md5($this->getFileName());
$this->hashedName = sha1($this->getFileName());
}
return $this->hashedName;

View File

@@ -370,8 +370,6 @@ class SerializableClosure implements Serializable
*/
public static function wrapClosures(&$data, SplObjectStorage $storage = null)
{
static::enterContext();
if($storage === null){
$storage = static::$context->scope;
}
@@ -431,8 +429,6 @@ class SerializableClosure implements Serializable
};
} while($reflection = $reflection->getParentClass());
}
static::exitContext();
}
/**
@@ -496,6 +492,20 @@ class SerializableClosure implements Serializable
}
}
/**
* Creates a new closure from arbitrary code,
* emulating create_function, but without using eval
*
* @param string$args
* @param string $code
* @return Closure
*/
public static function createClosure($args, $code)
{
ClosureStream::register();
return include(ClosureStream::STREAM_PROTO . '://function(' . $args. '){' . $code . '};');
}
/**
* Internal method used to map closure pointers
* @internal