Skip to content

Commit b3f7473

Browse files
committed
Make compatible with XP 12
1 parent ba8fc39 commit b3f7473

File tree

10 files changed

+23
-111
lines changed

10 files changed

+23
-111
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
18+
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
1919
os: [ubuntu-latest, windows-latest]
2020

2121
steps:
@@ -24,7 +24,7 @@ jobs:
2424
run: git config --system core.autocrlf false; git config --system core.eol lf
2525

2626
- name: Checkout
27-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4
2828

2929
- name: Set up PHP ${{ matrix.php-versions }}
3030
uses: shivammathur/setup-php@v2
@@ -40,7 +40,7 @@ jobs:
4040
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
4141

4242
- name: Cache dependencies
43-
uses: actions/cache@v3
43+
uses: actions/cache@v4
4444
with:
4545
path: ${{ steps.composer-cache.outputs.dir }}
4646
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ XP Reflection ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 3.0.0 / 2024-03-23
7+
8+
* Made this library compatible with XP 12, droppping support for all but
9+
the latest PHP 7 version. Minimum PHP version required is now **7.4**!
10+
(@thekid)
11+
612
## 2.14.1 / 2023-09-30
713

814
* Fixed `FromAttributes::imports()` for classes created inside `eval`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ XP Reflection
44
[![Build status on GitHub](https://github.com/xp-framework/reflection/workflows/Tests/badge.svg)](https://github.com/xp-framework/reflection/actions)
55
[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)
66
[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)
7-
[![Requires PHP 7.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_0plus.svg)](http://php.net/)
7+
[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)
88
[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)
99
[![Latest Stable Version](https://poser.pugx.org/xp-framework/reflection/version.png)](https://packagist.org/packages/xp-framework/reflection)
1010

composer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
"description" : "Reflection",
77
"keywords": ["module", "xp"],
88
"require" : {
9-
"xp-framework/core": "^11.0 | ^10.13",
10-
"xp-framework/ast": "^10.0 | ^9.0 | ^8.0 | ^7.6",
11-
"php" : ">=7.0.0"
12-
},
13-
"suggest" : {
9+
"xp-framework/core": "^12.0 | ^11.0 | ^10.13",
10+
"xp-framework/ast": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.6",
1411
"php" : ">=7.4.0"
1512
},
1613
"require-dev" : {
17-
"xp-framework/test": "^1.0"
14+
"xp-framework/test": "^2.0 | ^1.0"
1815
},
1916
"bin": ["bin/xp.xp-framework.reflection.reflect"],
2017
"autoload" : {

src/main/php/lang/reflection/Constants.class.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace lang\reflection;
22

3-
use Traversable;
3+
use Traversable, ReflectionClassConstant;
44

55
/**
66
* Type constants enumeration and lookup
@@ -15,24 +15,10 @@ class Constants extends Members {
1515
* @return iterable
1616
*/
1717
public function getIterator(): Traversable {
18-
if (PHP_VERSION_ID >= 70100) {
19-
foreach ($this->reflect->getReflectionConstants() as $constant) {
20-
if (0 !== strncmp($constant->name, '__', 2)) {
21-
yield $constant->name => new Constant($constant);
22-
}
18+
foreach ($this->reflect->getReflectionConstants() as $constant) {
19+
if (0 !== strncmp($constant->name, '__', 2)) {
20+
yield $constant->name => new Constant($constant);
2321
}
24-
} else {
25-
26-
// PHP 7.0 does not have getReflectionConstants(), enumerate constants
27-
// using name and values instead and use ReflectionClassConstant polyfill
28-
//
29-
// @codeCoverageIgnoreStart
30-
foreach ($this->reflect->getConstants() as $name => $_) {
31-
if (0 !== strncmp($name, '__', 2)) {
32-
yield $name => new Constant(new \ReflectionClassConstant($this->reflect->name, $name));
33-
}
34-
}
35-
// @codeCoverageIgnoreEnd
3622
}
3723
}
3824

@@ -44,7 +30,7 @@ public function getIterator(): Traversable {
4430
*/
4531
public function named($name) {
4632
return $this->reflect->hasConstant($name)
47-
? new Constant(new \ReflectionClassConstant($this->reflect->name, $name))
33+
? new Constant(new ReflectionClassConstant($this->reflect->name, $name))
4834
: null
4935
;
5036
}

src/main/php/lang/reflection/Method.class.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ public function invoke($instance, $args= [], $context= null) {
6262

6363
try {
6464
$pass= PHP_VERSION_ID < 80000 && $args ? self::pass($this->reflect, $args) : $args;
65-
66-
// PHP 7.0 still had warnings for arguments
67-
if (PHP_VERSION_ID < 70100 && sizeof($pass) < $this->reflect->getNumberOfRequiredParameters()) {
68-
throw new ReflectionException('Too few arguments');
69-
}
70-
7165
return $this->reflect->invokeArgs($instance, $pass);
7266
} catch (ReflectionException $e) {
7367
throw new CannotInvoke($this, $e);
@@ -126,7 +120,7 @@ public function toString() {
126120
}
127121
$returns= substr($name, 1);
128122
} else {
129-
$returns= strtr(PHP_VERSION_ID >= 70100 ? $t->getName() : $t->__toString(), '\\', '.');
123+
$returns= strtr($t->getName(), '\\', '.');
130124
$t->allowsNull() && $nullable= '?';
131125
}
132126

src/main/php/lang/reflection/Property.class.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function constraint() {
3535
};
3636

3737
$t= Type::resolve(
38-
PHP_VERSION_ID >= 70400 || '' === $this->reflect->name ? $this->reflect->getType() : null,
38+
$this->reflect->getType(),
3939
Member::resolve($this->reflect),
4040
$api
4141
);
@@ -103,8 +103,7 @@ public function set($instance, $value, $context= null) {
103103
public function toString() {
104104

105105
// Compile property type
106-
$t= PHP_VERSION_ID >= 70400 || '' === $this->reflect->name ? $this->reflect->getType() : null;
107-
if (null === $t) {
106+
if (null === ($t= $this->reflect->getType())) {
108107
$name= Reflection::meta()->propertyType($this->reflect) ?? 'var';
109108
} else if ($t instanceof ReflectionUnionType) {
110109
$name= '';

src/main/php/lang/reflection/Routine.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function signature($meta) {
4040
}
4141
$type= substr($name, 1);
4242
} else {
43-
$type= strtr(PHP_VERSION_ID >= 70100 ? $t->getName() : $t->__toString(), '\\', '.');
43+
$type= strtr($t->getName(), '\\', '.');
4444
$parameter->isVariadic() && $type.= '...';
4545
$t->allowsNull() && $nullable= '?';
4646
}

src/main/php/lang/reflection/Type.class.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,7 @@ public function class(): XPClass { return new XPClass($this->reflect); }
2828

2929
/** Returns this type's modifiers */
3030
public function modifiers(): Modifiers {
31-
if (PHP_VERSION_ID < 70400) {
32-
33-
// PHP 7.4 made type and member modifiers consistent. For versions before that,
34-
// map PHP reflection modifiers to generic form.
35-
//
36-
// @codeCoverageIgnoreStart
37-
$m= $this->reflect->getModifiers();
38-
$r= 0;
39-
$m & ReflectionClass::IS_EXPLICIT_ABSTRACT && $r|= Modifiers::IS_ABSTRACT;
40-
$m & ReflectionClass::IS_IMPLICIT_ABSTRACT && $r|= Modifiers::IS_ABSTRACT;
41-
$m & ReflectionClass::IS_FINAL && $r|= Modifiers::IS_FINAL;
42-
// @codeCoverageIgnoreEnd
43-
} else if (PHP_VERSION_ID >= 80200) {
31+
if (PHP_VERSION_ID >= 80200) {
4432

4533
// PHP 8.2 introduced readonly classes, but its modifier bit is different from
4634
// the one that properties use (65536 vs. 128), map this to generic form.

src/main/php/module.xp

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)