Esempio n. 1
0
 public function resolve($form)
 {
     if (is_subclass_of($form, Form::class)) {
         $this->form = Reflect::create($form);
         $this->request = context()->getOrCreate(Request::class);
         if (object_implements($form, ResolvesOnRequest::class)) {
             if ($this->request->isPost()) {
                 $this->response = context()->getOrCreate(Response::class);
                 $this->flash = context()->getOrCreate(Flash::class);
                 return $this->resolvePost();
             } elseif ($this->request->isGet()) {
                 return $this->resolveGet();
             }
         }
         return $this->form;
     }
 }
Esempio n. 2
0
 /**
  * @return array
  */
 public function __toArray($values = null, $depth = 6)
 {
     $return = [];
     if (!$depth) {
         return;
     }
     if (!$values) {
         $values = $this->collection;
     }
     if (is_array($values) || object_implements($values, CollectionInterface::class)) {
         foreach ($values as $key => $value) {
             /*if (is_object($value) && object_implements($object, RecordInterface::class)) {
                                 $return[$key] = $object->toArray($object, $depth - 1);
             
                             } else */
             if (is_object($value)) {
                 $return[$key] = $this->__toArray($value, $depth - 1);
             } else {
                 if (is_array($value)) {
                     $return[$key] = $this->__toArray($value, $depth - 1);
                 } else {
                     $return[$key] = $value;
                 }
             }
         }
     } elseif ($values instanceof Record) {
         $return = $values->__toArray(null, $depth - 1);
     }
     return $return;
 }
Esempio n. 3
0
 private function addCondition($key, $value = true, $operator = '=', $part)
 {
     if (is_object($key) && $key instanceof Raw) {
         $sql = $key->buildSQL();
         $this->{$part}->push($sql);
         if ($binds = $key->buildBinds()) {
             //$this->bind($binds, 'where');
             foreach ($binds as $bind) {
                 $this->bind($bind, $part);
             }
         }
         return $this;
     }
     if (is_object($value) && object_implements($value, ArrayAccess::class)) {
         $value = $value->__toArray();
     }
     if (is_array($value) && $operator == '=') {
         $operator = 'IN';
     }
     if (is_object($value) && $value instanceof Raw && $operator == '=') {
         $operator = 'IN';
     }
     if (is_callable($key)) {
         $key($this->{$part});
     } else {
         if ($operator == 'IN' || $operator == 'NOT IN') {
             if (is_string($value)) {
                 $value = [$value];
             }
             if (is_array($value)) {
                 if (!$value) {
                     /**
                      * This is probable not needed.
                      */
                     // $this->where->push($this->makeKey($key));
                     $this->{$part}->push('0 = 1');
                 } else {
                     $this->{$part}->push($this->makeKey($key) . ' ' . $operator . '(' . str_repeat('?, ', count($value) - 1) . '?)');
                     foreach ($value as $val) {
                         $this->bind($val, $part);
                     }
                 }
             } else {
                 if ($value instanceof Query) {
                     $this->{$part}->push($this->makeKey($key) . ' ' . $operator . '(' . $value->buildSQL() . ')');
                     if ($binds = $value->buildBinds()) {
                         $this->bind($binds, $part);
                     }
                 } else {
                     if ($value instanceof Entity) {
                         $this->{$part}->push($this->makeKey($key) . ' ' . $operator . '(' . $value->getQuery()->buildSQL() . ')');
                         if ($binds = $value->getQuery()->buildBinds()) {
                             $this->bind($binds, $part);
                         }
                     }
                 }
             }
         } elseif ($operator == 'IS' || $operator == 'IS NOT') {
             $this->{$part}->push($this->makeKey($key) . ($value ? $value === true ? '' : ' ' . $operator . ' ?' : ' ' . $operator . ' NULL'));
             if ($value && $value !== true) {
                 $this->bind($value, 'where');
             }
         } elseif ($operator == 'LIKE' || $operator == 'NOT LIKE') {
             $this->{$part}->push($this->makeKey($key) . ' ' . $operator . ' ?');
             $this->bind($value, $part);
         } else {
             $this->{$part}->push($this->makeKey($key) . ($value ? $value === true ? '' : ' ' . $operator . ' ?' : ' IS NULL'));
             if ($value && $value !== true) {
                 $this->bind($value, $part);
             }
         }
     }
     return $this;
 }
Esempio n. 4
0
 protected function transformCollection($collection)
 {
     $records = [];
     foreach ($collection as $key => $record) {
         if (is_object($record) && object_implements($record, \Iterator::class) || is_array($record)) {
             $records[$key] = $this->transformCollection($record);
         } else {
             $records[$key] = $this->transformRecord($record);
         }
     }
     return $records;
 }