Skip to content

Commit

Permalink
Make compatible with XP 12
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 23, 2024
1 parent ba8fc39 commit b3f7473
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 111 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
os: [ubuntu-latest, windows-latest]

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

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

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

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ XP Reflection ChangeLog

## ?.?.? / ????-??-??

## 3.0.0 / 2024-03-23

* Made this library compatible with XP 12, droppping support for all but
the latest PHP 7 version. Minimum PHP version required is now **7.4**!
(@thekid)

## 2.14.1 / 2023-09-30

* Fixed `FromAttributes::imports()` for classes created inside `eval`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ XP Reflection
[![Build status on GitHub](https://github.com/xp-framework/reflection/workflows/Tests/badge.svg)](https://github.com/xp-framework/reflection/actions)
[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)
[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[![Requires PHP 7.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_0plus.svg)](http://php.net/)
[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)
[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)
[![Latest Stable Version](https://poser.pugx.org/xp-framework/reflection/version.png)](https://packagist.org/packages/xp-framework/reflection)

Expand Down
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
"description" : "Reflection",
"keywords": ["module", "xp"],
"require" : {
"xp-framework/core": "^11.0 | ^10.13",
"xp-framework/ast": "^10.0 | ^9.0 | ^8.0 | ^7.6",
"php" : ">=7.0.0"
},
"suggest" : {
"xp-framework/core": "^12.0 | ^11.0 | ^10.13",
"xp-framework/ast": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.6",
"php" : ">=7.4.0"
},
"require-dev" : {
"xp-framework/test": "^1.0"
"xp-framework/test": "^2.0 | ^1.0"
},
"bin": ["bin/xp.xp-framework.reflection.reflect"],
"autoload" : {
Expand Down
24 changes: 5 additions & 19 deletions src/main/php/lang/reflection/Constants.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace lang\reflection;

use Traversable;
use Traversable, ReflectionClassConstant;

/**
* Type constants enumeration and lookup
Expand All @@ -15,24 +15,10 @@ class Constants extends Members {
* @return iterable
*/
public function getIterator(): Traversable {
if (PHP_VERSION_ID >= 70100) {
foreach ($this->reflect->getReflectionConstants() as $constant) {
if (0 !== strncmp($constant->name, '__', 2)) {
yield $constant->name => new Constant($constant);
}
foreach ($this->reflect->getReflectionConstants() as $constant) {
if (0 !== strncmp($constant->name, '__', 2)) {
yield $constant->name => new Constant($constant);
}
} else {

// PHP 7.0 does not have getReflectionConstants(), enumerate constants
// using name and values instead and use ReflectionClassConstant polyfill
//
// @codeCoverageIgnoreStart
foreach ($this->reflect->getConstants() as $name => $_) {
if (0 !== strncmp($name, '__', 2)) {
yield $name => new Constant(new \ReflectionClassConstant($this->reflect->name, $name));
}
}
// @codeCoverageIgnoreEnd
}
}

Expand All @@ -44,7 +30,7 @@ public function getIterator(): Traversable {
*/
public function named($name) {
return $this->reflect->hasConstant($name)
? new Constant(new \ReflectionClassConstant($this->reflect->name, $name))
? new Constant(new ReflectionClassConstant($this->reflect->name, $name))
: null
;
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/php/lang/reflection/Method.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ public function invoke($instance, $args= [], $context= null) {

try {
$pass= PHP_VERSION_ID < 80000 && $args ? self::pass($this->reflect, $args) : $args;

// PHP 7.0 still had warnings for arguments
if (PHP_VERSION_ID < 70100 && sizeof($pass) < $this->reflect->getNumberOfRequiredParameters()) {
throw new ReflectionException('Too few arguments');
}

return $this->reflect->invokeArgs($instance, $pass);
} catch (ReflectionException $e) {
throw new CannotInvoke($this, $e);
Expand Down Expand Up @@ -126,7 +120,7 @@ public function toString() {
}
$returns= substr($name, 1);
} else {
$returns= strtr(PHP_VERSION_ID >= 70100 ? $t->getName() : $t->__toString(), '\\', '.');
$returns= strtr($t->getName(), '\\', '.');
$t->allowsNull() && $nullable= '?';
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/php/lang/reflection/Property.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function constraint() {
};

$t= Type::resolve(
PHP_VERSION_ID >= 70400 || '' === $this->reflect->name ? $this->reflect->getType() : null,
$this->reflect->getType(),
Member::resolve($this->reflect),
$api
);
Expand Down Expand Up @@ -103,8 +103,7 @@ public function set($instance, $value, $context= null) {
public function toString() {

// Compile property type
$t= PHP_VERSION_ID >= 70400 || '' === $this->reflect->name ? $this->reflect->getType() : null;
if (null === $t) {
if (null === ($t= $this->reflect->getType())) {
$name= Reflection::meta()->propertyType($this->reflect) ?? 'var';
} else if ($t instanceof ReflectionUnionType) {
$name= '';
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/reflection/Routine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function signature($meta) {
}
$type= substr($name, 1);
} else {
$type= strtr(PHP_VERSION_ID >= 70100 ? $t->getName() : $t->__toString(), '\\', '.');
$type= strtr($t->getName(), '\\', '.');
$parameter->isVariadic() && $type.= '...';
$t->allowsNull() && $nullable= '?';
}
Expand Down
14 changes: 1 addition & 13 deletions src/main/php/lang/reflection/Type.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,7 @@ public function class(): XPClass { return new XPClass($this->reflect); }

/** Returns this type's modifiers */
public function modifiers(): Modifiers {
if (PHP_VERSION_ID < 70400) {

// PHP 7.4 made type and member modifiers consistent. For versions before that,
// map PHP reflection modifiers to generic form.
//
// @codeCoverageIgnoreStart
$m= $this->reflect->getModifiers();
$r= 0;
$m & ReflectionClass::IS_EXPLICIT_ABSTRACT && $r|= Modifiers::IS_ABSTRACT;
$m & ReflectionClass::IS_IMPLICIT_ABSTRACT && $r|= Modifiers::IS_ABSTRACT;
$m & ReflectionClass::IS_FINAL && $r|= Modifiers::IS_FINAL;
// @codeCoverageIgnoreEnd
} else if (PHP_VERSION_ID >= 80200) {
if (PHP_VERSION_ID >= 80200) {

// PHP 8.2 introduced readonly classes, but its modifier bit is different from
// the one that properties use (65536 vs. 128), map this to generic form.
Expand Down
58 changes: 0 additions & 58 deletions src/main/php/module.xp

This file was deleted.

0 comments on commit b3f7473

Please sign in to comment.