MDL-32250 import latest SimpleTest 1.1.0
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* base include file for SimpleTest
|
||||
* @package SimpleTest
|
||||
* @subpackage UnitTester
|
||||
* @version $Id$
|
||||
* @version $Id: reflection_php5.php 2011 2011-04-29 08:22:48Z pp11 $
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -12,15 +12,15 @@
|
||||
* @subpackage UnitTester
|
||||
*/
|
||||
class SimpleReflection {
|
||||
var $_interface;
|
||||
private $interface;
|
||||
|
||||
/**
|
||||
* Stashes the class/interface.
|
||||
* @param string $interface Class or interface
|
||||
* to inspect.
|
||||
*/
|
||||
function SimpleReflection($interface) {
|
||||
$this->_interface = $interface;
|
||||
function __construct($interface) {
|
||||
$this->interface = $interface;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,10 +31,10 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function classExists() {
|
||||
if (! class_exists($this->_interface)) {
|
||||
if (! class_exists($this->interface)) {
|
||||
return false;
|
||||
}
|
||||
$reflection = new ReflectionClass($this->_interface);
|
||||
$reflection = new ReflectionClass($this->interface);
|
||||
return ! $reflection->isInterface();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function classExistsSansAutoload() {
|
||||
return class_exists($this->_interface, false);
|
||||
return class_exists($this->interface, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function classOrInterfaceExists() {
|
||||
return $this->_classOrInterfaceExistsWithAutoload($this->_interface, true);
|
||||
return $this->classOrInterfaceExistsWithAutoload($this->interface, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function classOrInterfaceExistsSansAutoload() {
|
||||
return $this->_classOrInterfaceExistsWithAutoload($this->_interface, false);
|
||||
return $this->classOrInterfaceExistsWithAutoload($this->interface, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,13 +76,13 @@ class SimpleReflection {
|
||||
* @return boolean True if interface defined.
|
||||
* @access private
|
||||
*/
|
||||
function _classOrInterfaceExistsWithAutoload($interface, $autoload) {
|
||||
protected function classOrInterfaceExistsWithAutoload($interface, $autoload) {
|
||||
if (function_exists('interface_exists')) {
|
||||
if (interface_exists($this->_interface, $autoload)) {
|
||||
if (interface_exists($this->interface, $autoload)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return class_exists($this->_interface, $autoload);
|
||||
return class_exists($this->interface, $autoload);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function getMethods() {
|
||||
return array_unique(get_class_methods($this->_interface));
|
||||
return array_unique(get_class_methods($this->interface));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,11 +103,11 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function getInterfaces() {
|
||||
$reflection = new ReflectionClass($this->_interface);
|
||||
$reflection = new ReflectionClass($this->interface);
|
||||
if ($reflection->isInterface()) {
|
||||
return array($this->_interface);
|
||||
return array($this->interface);
|
||||
}
|
||||
return $this->_onlyParents($reflection->getInterfaces());
|
||||
return $this->onlyParents($reflection->getInterfaces());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ class SimpleReflection {
|
||||
* @returns boolean True if enforced.
|
||||
* @access private
|
||||
*/
|
||||
function _isInterfaceMethod($method) {
|
||||
protected function isInterfaceMethod($method) {
|
||||
return in_array($method, $this->getInterfaceMethods());
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function getParent() {
|
||||
$reflection = new ReflectionClass($this->_interface);
|
||||
$reflection = new ReflectionClass($this->interface);
|
||||
$parent = $reflection->getParentClass();
|
||||
if ($parent) {
|
||||
return $parent->getName();
|
||||
@@ -155,7 +155,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function isAbstract() {
|
||||
$reflection = new ReflectionClass($this->_interface);
|
||||
$reflection = new ReflectionClass($this->interface);
|
||||
return $reflection->isAbstract();
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function isInterface() {
|
||||
$reflection = new ReflectionClass($this->_interface);
|
||||
$reflection = new ReflectionClass($this->interface);
|
||||
return $reflection->isInterface();
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ class SimpleReflection {
|
||||
* @access public
|
||||
*/
|
||||
function hasFinal() {
|
||||
$reflection = new ReflectionClass($this->_interface);
|
||||
$reflection = new ReflectionClass($this->interface);
|
||||
foreach ($reflection->getMethods() as $method) {
|
||||
if ($method->isFinal()) {
|
||||
return true;
|
||||
@@ -193,7 +193,7 @@ class SimpleReflection {
|
||||
* @returns array List of parent interface names.
|
||||
* @access private
|
||||
*/
|
||||
function _onlyParents($interfaces) {
|
||||
protected function onlyParents($interfaces) {
|
||||
$parents = array();
|
||||
$blacklist = array();
|
||||
foreach ($interfaces as $interface) {
|
||||
@@ -218,8 +218,8 @@ class SimpleReflection {
|
||||
* @return bool true if method is abstract, else false
|
||||
* @access private
|
||||
*/
|
||||
function _isAbstractMethod($name) {
|
||||
$interface = new ReflectionClass($this->_interface);
|
||||
protected function isAbstractMethod($name) {
|
||||
$interface = new ReflectionClass($this->interface);
|
||||
if (! $interface->hasMethod($name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -232,8 +232,8 @@ class SimpleReflection {
|
||||
* @return bool true if method is the constructor
|
||||
* @access private
|
||||
*/
|
||||
function _isConstructor($name) {
|
||||
return ($name == '__construct') || ($name == $this->_interface);
|
||||
protected function isConstructor($name) {
|
||||
return ($name == '__construct') || ($name == $this->interface);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,8 +242,8 @@ class SimpleReflection {
|
||||
* @return bool true if method is abstract in parent, else false
|
||||
* @access private
|
||||
*/
|
||||
function _isAbstractMethodInParents($name) {
|
||||
$interface = new ReflectionClass($this->_interface);
|
||||
protected function isAbstractMethodInParents($name) {
|
||||
$interface = new ReflectionClass($this->interface);
|
||||
$parent = $interface->getParentClass();
|
||||
while($parent) {
|
||||
if (! $parent->hasMethod($name)) {
|
||||
@@ -263,8 +263,8 @@ class SimpleReflection {
|
||||
* @return bool true if method is static, else false
|
||||
* @access private
|
||||
*/
|
||||
function _isStaticMethod($name) {
|
||||
$interface = new ReflectionClass($this->_interface);
|
||||
protected function isStaticMethod($name) {
|
||||
$interface = new ReflectionClass($this->interface);
|
||||
if (! $interface->hasMethod($name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -294,13 +294,19 @@ class SimpleReflection {
|
||||
if ($name == '__toString') {
|
||||
return "function $name()";
|
||||
}
|
||||
if ($this->_isInterfaceMethod($name) ||
|
||||
$this->_isAbstractMethod($name) ||
|
||||
$this->_isAbstractMethodInParents($name) ||
|
||||
$this->_isStaticMethod($name)) {
|
||||
return $this->_getFullSignature($name);
|
||||
|
||||
// This wonky try-catch is a work around for a faulty method_exists()
|
||||
// in early versions of PHP 5 which would return false for static
|
||||
// methods. The Reflection classes work fine, but hasMethod()
|
||||
// doesn't exist prior to PHP 5.1.0, so we need to use a more crude
|
||||
// detection method.
|
||||
try {
|
||||
$interface = new ReflectionClass($this->interface);
|
||||
$interface->getMethod($name);
|
||||
} catch (ReflectionException $e) {
|
||||
return "function $name()";
|
||||
}
|
||||
return "function $name()";
|
||||
return $this->getFullSignature($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,13 +317,13 @@ class SimpleReflection {
|
||||
* bracket.
|
||||
* @access private
|
||||
*/
|
||||
function _getFullSignature($name) {
|
||||
$interface = new ReflectionClass($this->_interface);
|
||||
protected function getFullSignature($name) {
|
||||
$interface = new ReflectionClass($this->interface);
|
||||
$method = $interface->getMethod($name);
|
||||
$reference = $method->returnsReference() ? '&' : '';
|
||||
$static = $method->isStatic() ? 'static ' : '';
|
||||
return "{$static}function $reference$name(" .
|
||||
implode(', ', $this->_getParameterSignatures($method)) .
|
||||
implode(', ', $this->getParameterSignatures($method)) .
|
||||
")";
|
||||
}
|
||||
|
||||
@@ -329,7 +335,7 @@ class SimpleReflection {
|
||||
* a snippet of code.
|
||||
* @access private
|
||||
*/
|
||||
function _getParameterSignatures($method) {
|
||||
protected function getParameterSignatures($method) {
|
||||
$signatures = array();
|
||||
foreach ($method->getParameters() as $parameter) {
|
||||
$signature = '';
|
||||
@@ -342,8 +348,8 @@ class SimpleReflection {
|
||||
if ($parameter->isPassedByReference()) {
|
||||
$signature .= '&';
|
||||
}
|
||||
$signature .= '$' . $this->_suppressSpurious($parameter->getName());
|
||||
if ($this->_isOptional($parameter)) {
|
||||
$signature .= '$' . $this->suppressSpurious($parameter->getName());
|
||||
if ($this->isOptional($parameter)) {
|
||||
$signature .= ' = null';
|
||||
}
|
||||
$signatures[] = $signature;
|
||||
@@ -359,7 +365,7 @@ class SimpleReflection {
|
||||
* @return string Cleaner name.
|
||||
* @access private
|
||||
*/
|
||||
function _suppressSpurious($name) {
|
||||
protected function suppressSpurious($name) {
|
||||
return str_replace(array('[', ']', ' '), '', $name);
|
||||
}
|
||||
|
||||
@@ -370,11 +376,11 @@ class SimpleReflection {
|
||||
* @return boolean True if optional.
|
||||
* @access private
|
||||
*/
|
||||
function _isOptional($parameter) {
|
||||
protected function isOptional($parameter) {
|
||||
if (method_exists($parameter, 'isOptional')) {
|
||||
return $parameter->isOptional();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
Reference in New Issue
Block a user