Added reflection class

This commit is contained in:
Timothy Warren 2012-01-10 12:45:04 -05:00
parent 343d390377
commit 1f2cafdead
4 changed files with 75 additions and 1 deletions

View File

@ -23,4 +23,13 @@ class Welcome extends MM_Controller {
$this->output->set_output($output); $this->output->set_output($output);
} }
function reflect()
{
$this->r = new R($this);
$obj = $this->r->get_all();
$this->output->set_output($this->__toString('print_r', $obj));
}
} }

View File

@ -1,6 +1,6 @@
<?php <?php
class Welcome_Model { class Welcome_Model extends MM_Model{
function __construct(){} function __construct(){}
} }

View File

@ -397,5 +397,6 @@ require_once('miniMVC.php');
require_once('output.php'); require_once('output.php');
require_once('page.php'); require_once('page.php');
require_once('db.php'); require_once('db.php');
require_once('r.php');
// End of common.php // End of common.php

64
sys/r.php Normal file
View File

@ -0,0 +1,64 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Class for examining other classes
*
* @extends ReflectionClass
*/
class R extends ReflectionClass {
public $methods, $properties, $doc_comments, $parent_class, $static_properties, $internal;
/**
* ReflectionClass Constructor
*
* @param mixed $var
*/
public function __construct($var)
{
parent::__construct($var);
}
/**
* Attempt to run static functions in non-static context
*/
public function __call($name, $args)
{
if(is_callable($this->$name))
{
//Add $this object to args
array_push($args, $this);
//Call the dynamic function
return call_user_func_array($this->$name, $args);
}
}
/**
* Retrieve as much information about the class as possible
*/
public function get_all()
{
$this->methods = $this->getMethods();
$this->properties = $this->getProperties();
$this->doc_comments = $this->getDocComment();
$this->parent_class = $this->getParentClass();
$this->static_properties = $this->getStaticProperties();
$this->internal = (int)$this->isInternal();
return $this;
}
}