johannes Sat, 29 May 2010 20:40:58 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=299938
Log: - Make reflection aware of traits Changed paths: U php/php-src/trunk/ext/reflection/php_reflection.c U php/php-src/trunk/ext/reflection/tests/ReflectionClass_toString_001.phpt A php/php-src/trunk/ext/reflection/tests/traits001.phpt Modified: php/php-src/trunk/ext/reflection/php_reflection.c =================================================================== --- php/php-src/trunk/ext/reflection/php_reflection.c 2010-05-29 20:34:25 UTC (rev 299937) +++ php/php-src/trunk/ext/reflection/php_reflection.c 2010-05-29 20:40:58 UTC (rev 299938) @@ -355,7 +355,13 @@ if (obj) { string_printf(str, "%sObject of class [ ", indent); } else { - string_printf(str, "%s%s [ ", indent, (ce->ce_flags & ZEND_ACC_INTERFACE) ? "Interface" : "Class"); + char *kind = "Class"; + if (ce->ce_flags & ZEND_ACC_INTERFACE) { + kind = "Interface"; + } else if (ce->ce_flags & ZEND_ACC_TRAIT) { + kind = "Trait"; + } + string_printf(str, "%s%s [ ", indent, kind); } string_printf(str, (ce->type == ZEND_USER_CLASS) ? "<user" : "<internal"); if (ce->module) { @@ -367,6 +373,8 @@ } if (ce->ce_flags & ZEND_ACC_INTERFACE) { string_printf(str, "interface "); + } else if (ce->ce_flags & ZEND_ACC_TRAIT) { + string_printf(str, "trait "); } else { if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { string_printf(str, "abstract "); @@ -3974,6 +3982,14 @@ } /* }}} */ +/* {{{ proto public bool ReflectionClass::isTrait() + Returns whether this is a trait */ +ZEND_METHOD(reflection_class, isTrait) +{ + _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT); +} +/* }}} */ + /* {{{ proto public bool ReflectionClass::isFinal() Returns whether this class is final */ ZEND_METHOD(reflection_class, isFinal) @@ -5605,6 +5621,7 @@ ZEND_ME(reflection_class, getInterfaces, arginfo_reflection__void, 0) ZEND_ME(reflection_class, getInterfaceNames, arginfo_reflection__void, 0) ZEND_ME(reflection_class, isInterface, arginfo_reflection__void, 0) + ZEND_ME(reflection_class, isTrait, arginfo_reflection__void, 0) ZEND_ME(reflection_class, isAbstract, arginfo_reflection__void, 0) ZEND_ME(reflection_class, isFinal, arginfo_reflection__void, 0) ZEND_ME(reflection_class, getModifiers, arginfo_reflection__void, 0) Modified: php/php-src/trunk/ext/reflection/tests/ReflectionClass_toString_001.phpt =================================================================== --- php/php-src/trunk/ext/reflection/tests/ReflectionClass_toString_001.phpt 2010-05-29 20:34:25 UTC (rev 299937) +++ php/php-src/trunk/ext/reflection/tests/ReflectionClass_toString_001.phpt 2010-05-29 20:40:58 UTC (rev 299938) @@ -34,7 +34,7 @@ Property [ <default> public $name ] } - - Methods [43] { + - Methods [44] { Method [ <internal:Reflection> final private method __clone ] { - Parameters [0] { @@ -188,6 +188,12 @@ } } + Method [ <internal:Reflection> public method isTrait ] { + + - Parameters [0] { + } + } + Method [ <internal:Reflection> public method isAbstract ] { - Parameters [0] { Added: php/php-src/trunk/ext/reflection/tests/traits001.phpt =================================================================== --- php/php-src/trunk/ext/reflection/tests/traits001.phpt (rev 0) +++ php/php-src/trunk/ext/reflection/tests/traits001.phpt 2010-05-29 20:40:58 UTC (rev 299938) @@ -0,0 +1,71 @@ +--TEST-- +ReflectionClass and Traits +--FILE-- +<?php +trait Foo { + public function someMethod() { } +} + +class Bar { + use Foo; + + public function someOtherMethod() { } +} + +$rFoo = new ReflectionClass('Foo'); +$rBar = new ReflectionClass('Bar'); + +var_dump($rFoo->isTrait()); +var_dump($rBar->isTrait()); +echo $rFoo; +echo $rBar; +--EXPECTF-- +bool(true) +bool(false) +Trait [ <user> trait Foo ] { + @@ %straits001.php 2-4 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user> public method someMethod ] { + @@ %straits001.php 3 - 3 + } + } +} +Class [ <user> class Bar ] { + @@ %straits001.php 6-10 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [2] { + Method [ <user> public method someOtherMethod ] { + @@ %straits001.php 9 - 9 + } + + + Method [ <user> public method someMethod ] { + @@ %straits001.php 3 - 3 + } + } +} Property changes on: php/php-src/trunk/ext/reflection/tests/traits001.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php