Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed reflection deprecations for php 8.0 #76

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/zend-amf/library/Zend/Amf/Adobe/Introspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ protected function _addService(Zend_Server_Reflection_Class $refclass, DOMElemen
$arg->setAttribute('name', $param->getName());

$type = $param->getType();
if ($type == 'mixed' && ($pclass = $param->getClass())) {
$type = $pclass->getName();
if (PHP_VERSION_ID < 80000) {
if ($type == 'mixed' && ($pclass = $param->getClass())) {
$type = $pclass->getName();
}
}

$ptype = $this->_registerType($type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public static function fromReflection(Zend_Reflection_Parameter $reflectionParam
$param = new Zend_CodeGenerator_Php_Parameter();
$param->setName($reflectionParameter->getName());

if($reflectionParameter->isArray()) {
if (PHP_VERSION_ID >= 80000) {
$param->setType($reflectionParameter->getType());
} elseif ($reflectionParameter->isArray()) {
$param->setType('array');
} else {
$typeClass = $reflectionParameter->getClass();
Expand Down
36 changes: 27 additions & 9 deletions packages/zend-reflection/library/Zend/Reflection/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ public function getDeclaringClass($reflectionClass = 'Zend_Reflection_Class')
*/
public function getClass($reflectionClass = 'Zend_Reflection_Class')
{
$phpReflection = parent::getClass();
if($phpReflection == null) {
return null;
if (PHP_VERSION_ID < 80000) {
$phpReflection = parent::getClass();
if ($phpReflection == null) {
return null;
}

$phpReflectionClassName = $phpReflection->getName();
} else {
if (!parent::hasType()) {
return null;
}

$phpReflectionClassName = parent::getType();
}

$zendReflection = new $reflectionClass($phpReflection->getName());
$zendReflection = new $reflectionClass($phpReflectionClassName);
if (!$zendReflection instanceof Zend_Reflection_Class) {
// require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
Expand Down Expand Up @@ -109,13 +119,21 @@ public function getDeclaringFunction($reflectionClass = null)
*/
public function getType()
{
if ($docblock = $this->getDeclaringFunction()->getDocblock()) {
$params = $docblock->getTags('param');
try {
if ($docblock = $this->getDeclaringFunction()->getDocblock()) {
$params = $docblock->getTags('param');

if (isset($params[$this->getPosition()])) {
return $params[$this->getPosition()]->getType();
}
if (isset($params[$this->getPosition()])) {
return $params[$this->getPosition()]->getType();
}

}
} catch (Zend_Reflection_Exception $e) {
if (PHP_VERSION_ID >= 80000) {
return parent::getType();
} else {
throw $e;
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,13 @@ protected function _reflect()
// Try and auto-determine type, based on reflection
$paramTypesTmp = array();
foreach ($parameters as $i => $param) {
$paramType = 'mixed';
if ($param->isArray()) {
$paramType = 'array';
if (PHP_VERSION_ID < 80000) {
$paramType = 'mixed';
if ($param->isArray()) {
$paramType = 'array';
}
} else {
$paramType = $param->hasType() ? $param->getType() : 'mixed';
}
$paramTypesTmp[$i] = $paramType;
}
Expand Down
5 changes: 0 additions & 5 deletions tests/Zend/CodeGenerator/Php/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public function testNameAccessors()

}

public function testClassDocblockAccessors()
{
$this->markTestSkipped();
}

public function testAbstractAccessors()
{
$codeGenClass = new Zend_CodeGenerator_Php_Class();
Expand Down
12 changes: 8 additions & 4 deletions tests/Zend/CodeGenerator/Php/ParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ public function testFromReflection_GetWithNativeType()
$reflParam = $this->getFirstReflectionParameter('hasNativeDocTypes');
$codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);

$this->assertNotEquals('int', $codeGenParam->getType());
$this->assertEquals('', $codeGenParam->getType());
if (PHP_VERSION_ID < 80000) {
$this->assertEquals('', $codeGenParam->getType());
$this->assertNotEquals('int', $codeGenParam->getType());
} else {
$this->assertEquals('int', $codeGenParam->getType());
}
}

static public function dataFromReflection_Generate()
public static function dataFromReflection_Generate()
{
return array(
array('name', '$param'),
Expand All @@ -147,7 +151,7 @@ static public function dataFromReflection_Generate()
array('defaultValue', '$value = \'foo\''),
array('defaultNull', '$value = null'),
array('fromArray', 'array $array'),
array('hasNativeDocTypes', '$integer'),
array('hasNativeDocTypes', PHP_VERSION_ID >= 80000 ? 'int $integer' : '$integer'),
array('defaultArray', '$array = array ()'),
array('defaultArrayWithValues', '$array = array ( 0 => 1, 1 => 2, 2 => 3,)'),
array('defaultFalse', '$val = false'),
Expand Down