Beispiel #1
0
 public static function join()
 {
     $args = func_get_args();
     if (empty($args)) {
         return '';
     }
     $paths = new Vector();
     foreach ($args as $arg) {
         if (is_string($arg)) {
             $arg = explode(self::delimiter, $arg);
         }
         if (is_an_array($arg)) {
             foreach ($arg as $fragment) {
                 $paths->push($fragment);
             }
             continue;
         }
         $paths->push($arg);
     }
     $paths = $paths->select(function ($path) {
         $str = strval($path);
         return !empty($str);
     });
     $joined_path = $paths->join(self::delimiter);
     if (S($args[0])->starts_with(self::delimiter)) {
         $joined_path->prependF(self::delimiter);
     }
     return $joined_path;
 }
Beispiel #2
0
 public function __construct($message = '', $code = 0, $previous = null)
 {
     if (is_an_array($message)) {
         $error = Ar($message);
         $this->column = $error->column;
         $this->message = $error->message;
     } else {
         $this->column = '(column not set)';
     }
     return parent::__construct($this->message, $code, $previous);
 }
Beispiel #3
0
 public function __construct($tests = [])
 {
     if ($tests instanceof \Grease\Should) {
         $this->tests = V();
         $this->tests->push($tests);
         return;
     }
     if ($tests instanceof \Grease\Aggregator || is_an_array($tests)) {
         $this->tests = V($tests);
         return;
     }
     $class = get_class($tests);
     throw new \InvalidArgumentException("Expected instance of \\Grease\\Should or \\Grease\\Aggregator. Got instance of {$class}");
 }
Beispiel #4
0
 public function __call($level, $messages)
 {
     $messages = V($messages);
     if (!$this->levels->keys()->includes(strtolower($level))) {
         throw new \BadMethodCallException("Method not found: {$level} (" . $messages->join(', ') . ")");
     }
     $level = $this->levels[strtolower($level)];
     if ($level > $this->level) {
         return;
     }
     foreach ($messages as $message) {
         if (is_an_array($message)) {
             $message = var_export($message, true);
         }
         $this->_write($level, $message);
     }
 }
Beispiel #5
0
 public function traverse($directory, $namespaces = [])
 {
     if (!is_an_array($directory)) {
         $path = \Sauce\Path::info($directory);
         $path->absolute = $directory;
         $path->dirname = basename(dirname($path->absolute));
         $path->is_dir = is_dir($path->absolute);
         $directory = $path;
     }
     $namespaces = V($namespaces);
     $namespaces->push($directory->filename);
     $entries = \Sauce\Path::ls($directory->absolute);
     // Add extensive path info to the listing
     $entries = $entries->map(function ($entry) use($directory) {
         $path = \Sauce\Path::info($entry);
         $path->absolute = \Sauce\Path::join($directory->absolute, $entry);
         $path->dirname = basename(dirname($path->absolute));
         $path->is_dir = is_dir($path->absolute);
         return $path;
     });
     $entries = $entries->map(function ($entry) use($namespaces) {
         if ($entry->is_dir) {
             return $entry;
         }
         $entry->class_name = "\\" . $namespaces->join("\\") . "\\" . $entry->filename;
         $entry->is_class = class_exists($entry->class_name);
         return $entry;
     });
     foreach ($entries->to_array() as $entry) {
         if ($entry->is_dir) {
             // Recurse!
             $entries->push($this->traverse($entry, $namespaces));
             continue;
         }
     }
     return $entries;
 }
Beispiel #6
0
 private function handle_upload()
 {
     $this->uploads = V([]);
     $upload_field = $this->upload_field();
     if ($this->params->has_key('files')) {
         foreach ($this->params->files->getArrayCopy() as $file) {
             if (empty($file->tmp_name)) {
                 continue;
             }
             // Handle old-school form upload
             if (!is_an_array($file->tmp_name)) {
                 $this->uploads->push(new Upload\Form($this->log, $file->tmp_name, $file->size, $file->type, $file->name));
             } else {
                 $i = count($file->tmp_name) - 1;
                 for (; $i >= 0; $i--) {
                     $this->uploads->push(new Upload\Form($this->log, $file->tmp_name[$i], $file->size, $file->type[$i], $file->name[$i]));
                 }
             }
         }
     } elseif (isset($this->params->{$upload_field})) {
         // Handle XHR upload
         $this->uploads->push(new Upload\XHR($this->log, 'php://input', $this->params->content_length, $this->params->content_type, $this->params->http_x_file_name));
     }
 }
Beispiel #7
0
 private function join_conditions()
 {
     $statement = ' ';
     $values = V();
     if (!empty($this->join_scope)) {
         foreach ($this->join_scope as $table_name => $condition) {
             $statement .= ' ' . $condition . ' ';
             continue;
             # XXX TODO: other cases than join strings
             if (is_an_array($condition)) {
                 // array('id' => array(1, 2, 3)) => 'id IN (1, 2, 3)'
                 $conditions->push($column_name . ' IN (' . str_repeat('?,', count($condition) - 1) . '?)');
                 $values->push($condition);
             } elseif (!$table_name) {
                 // String condition, for clauses that cover more complex conditions than simple ANDs.
                 $statement .= ' ' . $condition . ' ';
             } else {
                 if ($condition === null) {
                     $c = $column_name . ' IS NULL';
                 } else {
                     $c = $column_name . ' = ?';
                     $values->push($condition);
                 }
                 $conditions->push($c);
             }
         }
     }
     return A(['statement' => $statement, 'values' => $values]);
 }
Beispiel #8
0
 public function unshift($values = [])
 {
     if (!is_an_array($values) || $values instanceof \Sauce\Object) {
         $values = [$values];
     }
     $values = V($values);
     $storage = $this->storage;
     for ($i = $values->count() - 1; $i >= 0; $i--) {
         array_unshift($storage, $values[$i]);
     }
     $this->storage = $storage;
     return null;
 }
Beispiel #9
0
 /**
  * TODO: document parameters
  */
 public function mergeF()
 {
     $args = func_get_args();
     foreach ($args as $arg) {
         if (is_an_array($arg)) {
             if ($arg instanceof self) {
                 $arg = $arg->to_array();
             }
             foreach ($arg as $key => $value) {
                 $this->offsetSet(strtolower($key), $value);
             }
         } else {
             /* XXX: Do we really support this? Object instances are
              *      supposed to be hashes, Vector instances can be appended
              *      to. */
             $this->storage[] = $arg;
         }
     }
     return $this;
 }