Exemplo n.º 1
0
 /**
  * Constructs a new Backtrace event from an array
  *
  * @param Array $backtrace The backtrace event array to build from
  * @return \r8\Backtrace\Event
  */
 public static function from(array $event)
 {
     $event = \r8\ary\hone($event, array("function", "line", "file", "class", "type", "args")) + array("function" => null, "line" => null, "file" => null, "class" => null, "type" => null, "args" => array());
     if ($event['function'] == '{closure}') {
         return new \r8\Backtrace\Event\Closure($event['file'], $event['line'], (array) $event['args']);
     } else {
         if (empty($event['class'])) {
             return new \r8\Backtrace\Event\Func($event['function'], $event['file'], $event['line'], (array) $event['args']);
         } else {
             if ($event['type'] == '::') {
                 return new \r8\Backtrace\Event\StaticMethod($event['class'], $event['function'], $event['file'], $event['line'], (array) $event['args']);
             } else {
                 if ($event['type'] == '->') {
                     return new \r8\Backtrace\Event\Method($event['class'], $event['function'], $event['file'], $event['line'], (array) $event['args']);
                 } else {
                     throw new \r8\Exception\Argument(0, "Event Array", "Invalid event format");
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Builds a new instance of this object from an array
  *
  * @param array $input The source data
  * @return \r8\Input\File|Array This could return an array of \r8\Input\File
  *      objects if the input array is multi-dimensional.
  */
 public static function fromArray(array $input)
 {
     $fields = array('name', 'tmp_name', 'error');
     // Narrow the array to only what is needed
     $input = \r8\ary\hone($input, $fields);
     // Check for missing fields
     $missing = array_diff($fields, array_keys($input));
     if (count($missing) > 0) {
         throw new \r8\Exception\Argument(0, "Input Array", "The following indexes are required and missing: " . implode(", ", $missing));
     }
     // If they only gave us a single file,
     if (!is_array($input['name'])) {
         return new self($input['name'], $input['error'], new \r8\FileSys\File($input['tmp_name']));
     }
     // Handle multiple files passed under one file name
     $result = array();
     foreach ($input['name'] as $key => $value) {
         if (isset($input['error'][$key]) && isset($input['tmp_name'][$key])) {
             $result[$key] = new self($input['name'][$key], $input['error'][$key], new \r8\FileSys\File($input['tmp_name'][$key]));
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 public function testHone()
 {
     $ary = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5);
     $this->assertEquals(array('five' => 5, 'three' => 3, 'six' => 1), \r8\ary\hone($ary, 'five', 'three', 'six'));
     $this->assertEquals(array('ten' => 1, 'eleven' => 2, 'twelve' => 3), \r8\ary\hone($ary, array('ten', 'eleven'), 'twelve'));
     $this->assertEquals(array('seven' => 1, 'six' => 2, 'five' => 5, 'four' => 4), \r8\ary\hone($ary, array('seven', 'six'), 'five', array(array('four'))));
 }