Example #1
0
 public function main()
 {
     // Display some statistics
     $this->template->framework = Registry::$framework;
     // Load distribution-specific examples.
     $examples = new View_Component('examples');
     // You can embed template output into other templates...
     $this->template->examples = $examples->get_content();
 }
Example #2
0
 /**
  * Load and run a test.
  * 
  * @param string $name Name of test to run. This test should be located in {package}/tests
  * folder.
  * 
  * @return NULL
  */
 public function run($name)
 {
     // Ready the report.
     $report = new View_Component('test-result');
     $report->outcome = 'pass';
     $report->passes = 0;
     $report->fails = 0;
     $report->test_count = 0;
     $results = array();
     // Load test.
     $test = ucfirst(strtolower($name)) . '_Test';
     $report->test = $test;
     $reflector = new ReflectionClass($test);
     // Is it enabled?
     $constants = $reflector->getConstants();
     if ($constants['ENABLED'] === TRUE) {
         $report->status = 'Enabled';
         // Get the public methods, they are our tests.
         $public_methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);
         $runnable = array();
         foreach ($public_methods as $public_method) {
             $method = new ReflectionMethod($test, $public_method->name);
             // Constructor and Destructor should be used for setup/teardown only.
             if (!$method->isConstructor() && !$method->isDestructor()) {
                 $runnable[] = $method;
             }
         }
         // Run each test.
         $report->test_count = count($runnable);
         foreach ($runnable as $run) {
             $result = new stdClass();
             $result->test = $run->name;
             // Expectations will trigger Exceptions on failure.
             try {
                 $run->invoke(new $test());
                 $result->outcome = 'pass';
                 $report->passes++;
             } catch (Exception $e) {
                 $report->fails++;
                 $report->outcome = 'fail';
                 $result->outcome = 'fail';
                 $result->error = $e->getMessage();
             }
             array_push($results, $result);
         }
     } else {
         $report->status = 'Disabled';
     }
     $report->results = $results;
     $report->display_content();
 }
Example #3
0
 function init()
 {
     parent::init();
     if ($this->responsible_namespace == null) {
         throw $this->exception('Define class variable "responsible_namespace"');
     }
     if ($this->responsible_view == null) {
         throw $this->exception('Define class variable "responsible_view"');
     }
     $this->setAttr('data-responsible-namespace', $this->responsible_namespace);
     $this->setAttr('data-responsible-view', $this->responsible_view);
     $this->setAttr('data-is-serverside-component', 'true');
 }
Example #4
0
 /**
  * Accepts PHP Errors and Exceptions and displays custom debugger.
  * 
  * @param mixed $error Object if Exception, error_number if standard
  * PHP error.
  * @param string $string Optional for PHP Error
  * @param string $file Optional for PHP Error
  * @param integer $line Optional for PHP Error
  * 
  */
 public static function handler()
 {
     // Exceptions will contain only an object
     $args = func_get_args();
     // Build debugger
     $debugger = new View_Component('debugger');
     switch (count($args)) {
         // Errors will supply 2-5 parameters
         case 5:
             $debugger->context = $args[4];
         case 4:
             $debugger->line_number = $args[3];
         case 3:
             $debugger->file_name = $args[2];
         case 2:
             $debugger->message = $args[1];
             $debugger->error_type = self::get_error_type($args[0]);
             $debugger->backtrace = debug_backtrace();
             break;
             // Exceptions will supply only an object
         // Exceptions will supply only an object
         case 1:
             $exception = $args[0];
             $debugger->message = $exception->getMessage();
             $debugger->file_name = $exception->getFile();
             $debugger->line_number = $exception->getLine();
             $debugger->error_type = get_class($exception);
             $debugger->backtrace = $exception->getTrace();
             break;
         default:
             die('Invalid number of arguments supplied to Core Exception handler.');
             break;
     }
     // Flush any open output buffers. We only want to see errors.
     ob_get_clean();
     // Show error
     Core::$draw_enabled = FALSE;
     header('HTTP/1.1 500 Internal Server Error');
     $debugger->display_content();
     exit;
 }