Exemple #1
0
 public function testResponseAccessors()
 {
     $response = \r8\Env::Response();
     $this->assertThat($response, $this->isInstanceOf('\\r8\\iface\\Env\\Response'));
     $this->assertSame($response, \r8\Env::Response());
     $this->assertSame($response, \r8\Env::Response());
     $this->assertSame($response, \r8\Env::Response());
 }
Exemple #2
0
 /**
  * A helper method that dumps the current backtrace to the client
  *
  * @return NULL
  */
 public static function dump()
 {
     if (\r8\Env::request()->isCLI()) {
         $format = new \r8\Backtrace\Formatter\Text();
     } else {
         $format = new \r8\Backtrace\Formatter\HTML();
     }
     echo r8(new \r8\Backtrace\Formatter($format))->format(self::create()->popEvent());
 }
Exemple #3
0
/**
 * Dumps the content of a variable to the output buffer
 *
 * This works exactly like var_dump, except it detects if it needs to wrap the output in <pre> tags
 *
 * @param mixed $value The value to dump
 */
function dump($value)
{
    if (\r8\Env::request()->isCLI()) {
        var_dump($value);
    } else {
        echo "<pre>";
        var_dump($value);
        echo "</pre>";
    }
}
Exemple #4
0
 public function testFormat()
 {
     $formatter = new \r8\Error\Formatter\HTML(\r8\Env::request());
     $exception = new \r8\Exception("Test", 5050);
     $exception->addData("key", "data");
     $exception->addData("test", new stdClass());
     $error = new \r8\Error\Exception($exception);
     $result = $formatter->format($error);
     $this->assertType("string", $result);
     $this->assertGreaterThan(0, strlen($result));
 }
Exemple #5
0
 public function testResponseAccessors()
 {
     $root = new \r8\Page($this->getMock("r8\\iface\\Page"));
     $this->assertSame(\r8\Env::Response(), $root->getResponse());
     $this->assertSame(\r8\Env::Response(), $root->getResponse());
     $this->assertSame(\r8\Env::Response(), $root->getResponse());
     $response = $this->getMock('r8\\iface\\Env\\Response');
     $this->assertSame($root, $root->setResponse($response));
     $this->assertSame($response, $root->getResponse());
     $this->assertSame($response, $root->getResponse());
     $this->assertSame($response, $root->getResponse());
 }
Exemple #6
0
 /**
  * Returns the response object that will be sent to the client
  *
  * @return \r8\iface\Env\Response
  */
 public function getResponse()
 {
     if (isset($this->response)) {
         return $this->response;
     } else {
         return \r8\Env::Response();
     }
 }
Exemple #7
0
 /**
  * Constructor...
  *
  * @param String $name The name of this form field
  * @param String|NULL $label The label that describes this input field
  * @param \r8\Validator\FileUpload $validator The validator to use
  *      for checking the uploaded file. If left empty, a default
  *      instance will be created
  * @param \r8\Input\Files $files The list of uploaded files to pull
  *      this fields value from. If left empty, the File list from
  *      the global Request will be used
  */
 public function __construct($name, $label = null, \r8\Validator\FileUpload $validator = null, \r8\Input\Files $files = null)
 {
     parent::__construct($name, $label);
     $this->validator = $validator ?: new \r8\Validator\FileUpload();
     $this->files = $files ?: \r8\Env::request()->getFiles();
 }
Exemple #8
0
 /**
  * Constructor... Sets the initial state of the instance
  */
 public function __construct()
 {
     // Set the default action URI to the current page
     $this->action = \r8\Env::Request()->getURL()->__toString();
 }
Exemple #9
0
 /**
  * Returns a string about this exception
  *
  * @return String
  */
 public function __toString()
 {
     if (\r8\Env::request()->isCLI()) {
         $formatter = new \r8\Error\Formatter\Text(\r8\Env::request());
     } else {
         $formatter = new \r8\Error\Formatter\HTML(\r8\Env::request());
     }
     return $formatter->format($this);
 }
Exemple #10
0
 /**
  * Dumps the results of this test suite to the client
  *
  * @return \r8\Benchmark\Suite
  */
 public function dump()
 {
     return \r8\Env::Request()->isCLI() ? $this->dumpCLI() : $this->dumpHTML();
 }
Exemple #11
0
 */
\r8\Autoload::getInstance()->register('r8', r8_DIR_CLASSES)->register('r8\\iface', r8_DIR_INTERFACES)->register('r8\\Test', r8_DIR_TEST);
spl_autoload_register(array(\r8\Autoload::getInstance(), "load"));
/**
 * Take a snapshot of the environment
 */
\r8\Env::Request();
/**
 * Set up error handling, but only if it isn't being suppressed by the including code
 */
if (!defined("r8_SUPPRESS_HANDLERS")) {
    // Register the error handler
    set_error_handler(function ($code, $message, $file, $line) {
        $level = (int) ini_get('error_reporting');
        $code = (int) $code;
        if (!($code & $level)) {
            return TRUE;
        }
        $backtrace = \r8\Backtrace::create()->popEvent();
        \r8\Error::getInstance()->handle(new \r8\Error\PHP($file, $line, $code, $message, $backtrace));
    });
    // Register an exception handler
    set_exception_handler(function ($exception) {
        \r8\Error::getInstance()->handle(new \r8\Error\Exception($exception));
    });
    // Hook in the error handler to the error log
    \r8\Error::getInstance()->register(new \r8\Error\Handler\Stream(new \r8\Error\Formatter\JSON(\r8\Env::request()), new \r8\Stream\Out\ErrorLog()));
    // Hook in the error handler to output the error to the client
    \r8\Error::getInstance()->register(new \r8\Error\Handler\IniDisplay(new \r8\Error\Handler\Stream(\r8\Env::request()->isCLI() ? new \r8\Error\Formatter\Text(\r8\Env::request()) : new \r8\Error\Formatter\HTML(\r8\Env::request()), new \r8\Stream\Out\StdOut())));
}
// @codeCoverageIgnoreEnd
Exemple #12
0
 /**
  * Processes a list of input arguments
  *
  * @param \r8\CLI\Input $input If left empty, this will pull the input
  *      from the environment
  * @return \r8\CLI\Result
  */
 public function process(\r8\CLI\Input $input = NULL)
 {
     if (empty($input)) {
         $input = \r8\Env::request()->getCLIArgs();
     }
     $firstError = NULL;
     foreach ($this->forms as $form) {
         try {
             $input->rewind();
             return $form->process($input);
         } catch (\r8\Exception\Data $err) {
             if (!isset($firstError)) {
                 $firstError = $err;
             }
         }
     }
     throw $firstError;
 }