Пример #1
0
 public function __construct($class, $test_func)
 {
     // buffer output and collect it for later use.
     $this->test_start($class);
     $this->test_start("Reflection", true);
     // create the reflector
     $this->reflector = new ReflectionClass($class);
     Reflection::export($this->reflector);
     echo $this->test_end("Reflection");
     // run test function
     $this->test_set_success($class, $test_func($this, $this->reflector));
     $this->buffer = $this->test_end($class);
     //var_dump($this->tests);
     //$this->buffer = $this->tests[$class]['buffer'];
 }
 /**
  * This method calls functions on the implementation class and returns the output or Fault object in case of error to client
  *
  * @return unknown
  */
 function serve()
 {
     if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) {
         if (empty($_REQUEST['method'])) {
             echo '<pre>';
             Reflection::export(new ReflectionClass(get_class($this->implementation)));
         } else {
             $er = new SoapError();
             $er->set_error('invalid_call');
             $this->fault($er);
         }
     } else {
         $method = $_REQUEST['method'];
         return $this->implementation->{$method}();
     }
     // else
 }
Пример #3
0
 function _update(KISS_DataObject $pKDO)
 {
     $keys = $pKDO->get_keys();
     foreach ($keys['primary'] as $key => $value) {
         $sub_sql[] = "{$value['column']}=:{$value['column']}";
     }
     $columns = $pKDO->get_columns();
     foreach ($columns as $key => $value) {
         $sub_sql1[] = "{$key}=:{$key}";
     }
     $sql = sprintf(self::SQL_UPDATE, 'student', implode(',', $sub_sql1), implode(' and ', $sub_sql));
     $db = new PDO('mysql:host=127.0.0.1;dbname=test', 'web', 'develop');
     $stmt = $db->prepare($sql);
     foreach ($columns as $key => $value) {
         $stmt->bindParam($key, $pKDO->{$key});
     }
     Reflection::export(new ReflectionObject($stmt));
     //$stmt->execute();
 }
Пример #4
0
<?php

class CdProduct
{
    public $data;
    public function test()
    {
        return true;
    }
}
//
print_r(get_class_methods('CdProduct'));
//反射
$prod_class = new ReflectionClass('CdProduct');
Reflection::export($prod_class);
Пример #5
0
<?php

/**
 * Created by PhpStorm.
 * User: Nigel
 * Date: 2016/1/14
 * Time: 20:46
 */
use Nigel\NEU\AAO;
include "autoload.php";
Reflection::export(new ReflectionClass(new stdClass()));
Пример #6
0
<?php

class just_constants
{
    const BOOLEAN_CONSTANT = true;
    const NULL_CONSTANT = null;
    const STRING_CONSTANT = 'This is a string';
    const INTEGER_CONSTANT = 1000;
    const FLOAT_CONSTANT = 3.14159265;
}
Reflection::export(new ReflectionClass('just_constants'));
Пример #7
0
 public static function classInfo($classname)
 {
     echo "<pre>";
     Reflection::export(new ReflectionClass($classname));
     echo "</pre>";
 }
<?php

function foo()
{
}
class bar
{
    private function foo()
    {
    }
}
Reflection::export(new ReflectionFunction('foo'));
Reflection::export(new ReflectionMethod('bar', 'foo'));
?>
===DONE===
Пример #9
0
<?php

function my_error_handler($errno, $errstr, $errfile, $errline)
{
    echo "Error: {$errstr}\n";
}
set_error_handler('my_error_handler');
class Setting extends ReflectionObject
{
}
Reflection::export(simplexml_load_string('<test/>', 'Setting'));
Reflection::export(simplexml_load_file('data:,<test/>', 'Setting'));
?>
===DONE===
printf("%s is %sabstract.<br />\n", $rc->getName(), $rc->isAbstract() ? '' : 'not ');
printf("%s is %sfinal.</p>\n", $rc->getName(), $rc->isFinal() ? '' : 'not ');
$constants = $rc->getConstants();
$num_constants = count($constants);
printf("%s defines %d constant%s", $rc->getName(), $num_constants == 0 ? 'no' : $num_constants, $num_constants != 1 ? 's' : '');
if ($num_constants > 0) {
    printf(":<pre>%s</pre>", print_r($constants, TRUE));
}
$props = $rc->getProperties();
$num_props = count($props);
printf("%s defines %d propert%s", $rc->getName(), $num_props == 0 ? 'no' : $num_props, $num_props == 1 ? 'y' : 'ies');
if ($num_props > 0) {
    print ':';
    foreach ($props as $prop) {
        print "<pre>";
        Reflection::export($prop);
        print "</pre>";
    }
}
$methods = $rc->getMethods();
$num_methods = count($methods);
printf("%s defines %d method%s<br />\n", $rc->getName(), $num_methods == 0 ? 'no' : $num_methods, $num_methods != 1 ? 's' : '');
if ($num_methods > 0) {
    print '<p>';
    foreach ($methods as $method) {
        printf("%s%s%s%s%s%s() ", $method->isFinal() ? 'final ' : '', $method->isAbstract() ? 'abstract ' : '', $method->isPublic() ? 'public ' : '', $method->isPrivate() ? 'private ' : '', $method->isProtected() ? 'protected ' : '', $method->getName());
        $params = $method->getParameters();
        $num_params = count($params);
        printf("has %s parameter%s%s", $num_params == 0 ? 'no' : $num_params, $num_params != 1 ? 's' : '', $num_params > 0 ? ': ' : '');
        if ($num_params > 0) {
            $names = array();
<pre>
<?php 
function sayHello($name, $h)
{
    static $count = 0;
    return "<h{$h}>Hello, {$name}</h{$h}>";
}
// Обзор функции
Reflection::export(new ReflectionFunction('sayHello'));
// Создание экземпляра класса ReflectionFunction
$func = new ReflectionFunction('sayHello');
// Вывод основной информации
printf("<p>===> %s функция '%s'\n" . "     объявлена в %s\n" . "     строки с %d по %d\n", $func->isInternal() ? 'Internal' : 'User-defined', $func->getName(), $func->getFileName(), $func->getStartLine(), $func->getEndline());
// Вывод статических переменных, если они есть
if ($statics = $func->getStaticVariables()) {
    printf("<p>---> Статическая переменная: %s\n", var_export($statics, 1));
}
// Вызов функции
printf("<p>---> Результат вызова: ");
$result = $func->invoke("John", "1");
echo $result;
?>
</pre>
<?php

Reflection::export(new ReflectionFunction('htmlspecialchars'));
Reflection::export(new ReflectionFunction('get_html_translation_table'));
    /**
     * My constructor
     * @param string $name
     */
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function getName()
    {
        return $this->name;
    }
    public function setSpouse(Person $spouse)
    {
        $this->spouse = $spouse;
    }
    private function setPassword($password)
    {
        $this->password = $password;
    }
}
$reflectionClass = new ReflectionClass('Person');
echo Reflection::export($reflectionClass, true);
$firstMethod = $reflectionClass->getMethods()[0];
$firstProperty = $reflectionClass->getProperties()[0];
var_dump($reflectionClass->getMethods(), $reflectionClass->hasMethod('getName'), $firstMethod->getDocComment(), $firstMethod->getParameters(), $reflectionClass->getProperties(), $firstProperty->isPublic());
echo '<hr />';
ReflectionObject::export(new Person('Reflection'));
?>
</pre>
Пример #14
0
<pre>
<?php 
abstract class MyClass
{
    public $a = 1;
    protected $b = 2;
    private $c = 3;
    public static $cnt = 0;
    const HANDS = 2;
    abstract function foo();
    public static function bar()
    {
        //Что-то делаем
    }
    public function sayHello($name, $h = "1")
    {
        static $count = 0;
        return "<h{$h}>Hello, {$name}</h{$h}>";
    }
}
// Обзор пользовательского класса
Reflection::export(new ReflectionClass('MyClass'));
exit;
// Обзор встроенного класса
Reflection::export(new ReflectionClass('Exception'));
?>
</pre>
Пример #15
0
 /**
  * Возвращает структуру класса
  *
  * @param string $var
  *
  * @return string
  */
 protected function reflectionClass($var)
 {
     $classInfo = new \ReflectionClass($var);
     return \Reflection::export($classInfo, true);
 }
Пример #16
0
<?php

/**
*@name :PHP利用反射机制获取用户自声明的类--反射API
*/
class UserClass
{
    public function userMethod($userParameter = 'default')
    {
    }
}
foreach (get_declared_classes() as $class) {
    $reflection = new ReflectionClass($class);
    if ($reflection->isUserDefined()) {
        //判断是否是自声明的类
        Reflection::export($reflection);
        //打印出该类的一些资料
    }
}
Пример #17
0
<?php

echo '<pre>';
//Reflection::export(new ReflectionExtension('reflection'));
echo '<hr/>';
// get_declared_classes() 返回由已定义类(PHP系统类)的名字所组成的数组
foreach (get_declared_classes() as $class) {
    Reflection::export(new ReflectionClass($class));
}
Пример #18
0
        echo 'Invoked' . PHP_EOL;
        print 'Name: ' . $name . ', DOB: ' . $dob . PHP_EOL;
        $currYear = date('Y');
        $dobYear = date('Y', strtotime($dob));
        echo "C : {$currYear}, D : {$dobYear}" . PHP_EOL;
        $currAge = $currYear - $dobYear;
        return $currAge;
    }
}
/* ReflectionClass -- class details */
$rc = Reflection::export(new ReflectionClass('Album'));
echo "<pre>";
print_r($rc, true);
echo "" . PHP_EOL;
/* ReflectionMethod -- method details*/
$rm = Reflection::export(new ReflectionMethod('Album', 'getPath'));
echo "<pre>";
print_r($rm, true);
echo "" . PHP_EOL;
/* Class methods by get_class_methods */
$rm1 = get_class_methods(new Album());
echo "<pre>";
foreach ($rm1 as $method_name) {
    echo "{$method_name}" . PHP_EOL;
}
/* ReflectionMethod -- ivoking method using ReflectionMethod API*/
$albumObj = new Album();
$rm2 = new ReflectionMethod('Album', 'getCurrentAge');
$currAge = $rm2->invokeArgs($albumObj, ['1976-01-22', 'Dhananjay']);
echo "Current Age : " . $currAge . PHP_EOL;
echo "" . PHP_EOL;
<?php

// learn about cars
Reflection::export(new ReflectionClass('car'));
Пример #20
0
/**
* Função para debugar com exibição da classe
* @param [mixed]
* @return [string]
*/
function debug3(objeto $var)
{
    echo '<link rel="stylesheet" href=".sistema/debug.css" />';
    echo '<div class="debug"><pre>';
    ob_start();
    Reflection::export(new ReflectionClass($var));
    $out = ob_get_clean();
    $out = highlight_string("<?php\n" . $out . "?>");
    echo '</div></pre>';
}
Пример #21
0
<?php

class userClass
{
    public function userMethod($userParameter = 'default')
    {
    }
}
echo '<pre>';
// get_declared_classes() 获得已定义的类(系统类&&用户自定义的类)
foreach (get_declared_classes() as $class) {
    $reflectionClass = new ReflectionClass($class);
    // isUserDefined() 检查是否是用户自定义的类
    if ($reflectionClass->isUserDefined()) {
        Reflection::export($reflectionClass);
    }
}
Пример #22
0
 function export_class()
 {
     echo '<pre>';
     Reflection::export(new ReflectionClass($this->router->getController()));
     exit;
 }
Пример #23
0
define('foobar', 1);
class Test
{
    function foo1($arg = foobar)
    {
    }
    function foo2($arg = null)
    {
    }
    function foo3($arg = false)
    {
    }
    function foo4($arg = 'foo')
    {
    }
    function foo5($arg = 1)
    {
    }
    function bar($arg)
    {
    }
    function foo()
    {
    }
}
Reflection::export(new ReflectionClass('Test'));
?>
===DONE===
<?php 
exit(0);
Пример #24
0
<?php

abstract class foobar
{
    private function test2()
    {
    }
}
class foo extends foobar
{
    private $foo = 1;
    private function test()
    {
    }
    protected function test3()
    {
    }
}
class bar extends foo
{
    private function foobar()
    {
    }
}
Reflection::export(new ReflectionClass(new bar()));