Devuelve la primera fila de una consulta
@author Carlos Garcia
@param Closure $closure
@return Object
349182
final public function first($closure=NULL) {
      if(!$this->find_first_data) {
         $this->limit( 1 );
         $this->get();
      }

      if(is_array($this->data) && count($this->data) >= 1) {
         $this->find_save_data = TRUE;
         $this->data = $this->data[0];
      }
      
      if ($this->find_first_data===TRUE && $closure instanceof \Closure) {
         $this->data = $closure( $this->data, $this );
      }

      $this->find_first_data = FALSE;

      return $this->data ?: [];
   }
1051145
public function reject(\Closure $closure): self
    {
        // init
        $filtered = [];

        foreach ($this->getGenerator() as $key => $value) {
            if (!$closure($value, $key)) {
                $filtered[$key] = $value;
            }
        }

        return static::create(
            $filtered,
            $this->iteratorClass,
            false
        );
    }
27407
final protected function ensureAccessible(\Closure $closure)
    {
        return \Closure::bind($closure, null, $this->property->getAccessibility()->getDeclaredClass());
    }
819277
public function serializeClosure(\Closure $closure)
    {
        if ($this->isSingle()) {
            return SerializeHelper::component()->serializeClosure($closure);
        }

        return null;
    }
220163
public function sort(Closure $closure)
    {
        $sorted = clone $this;

        $sorted->models = Objects::sort($sorted->models, $closure);

        return $sorted;
    }
516736
public function client($name, Closure $closure = null)
    {
        if ($this->has($name)) {
            /** @var Service $service */
            $service = $this->services[$name];

            if (is_null($service->getClient())) {
                $client = new Client($service->getWsdl(), $service->getOptions(), $service->getHeaders());
              
                $service->client($client);
            } else {
                $client = $service->getClient();
            }

            return $closure($client);
        }

        throw new ServiceNotFound("Service '" . $name . "' not found.");
    }
51799
public function foldrWithKeys(callable $closure, $initial)
    {
        return $this
            ->reverse()
            ->foldlWithKeys(
                function ($acc, $key, $x) use ($closure) {
                    return $closure($key, $x, $acc);
                },
                $initial
            );
    }
466259
public function parallel(Closure $closure)
    {
        $processId = $this->fork();

        if ($processId) {
            $process = new Process($processId, $this->master);
            $this->master->addChild($process);

            return $process;
        }

        $process = new Process($this->posix->getpid(), $this->master);
        $this->master->addChild($process);
        if (false === is_null($closure)) {
            call_user_func($closure, $process);
        }
        $this->terminateProcess($process);

        return $this;
    }
807565
final public function getArray($closure=NULL) {
      $type_fetch = $this->type_fetch;
      $this->type_fetch = 'assoc';
      $this->get();
      $this->type_fetch = $type_fetch;
      // $this->data = array_map(function($v){return(array)$v;},$this->data);
      if ($closure instanceof \Closure) {
         $this->data = $closure( $this->data, $this );
      }
      return $this->data ?: [];
   }
1026575
final public function get($closure=NULL) {
      $this->connection();
      if ($this->table===NULL) {
         if ( !preg_match('/^ *FROM +\(/', $this->from) ) {
            $this->from = '';
         }
      }
      else {
         if (preg_match('/\./', $this->table) || !$this->schema ) {
            $this->from = str_replace("_table_", $this->table, $this->from);
         }
         else {
            $this->from = str_replace("_table_", $this->schema.'.'.$this->table, $this->from);
         }
      }

      $this->last_sql = $this->sql = $this->select.' '.$this->from.' '.$this->join.' '.$this->where.' '.$this->union.' '.$this->groupBy.' '.$this->having.' '.$this->orderBy.' '.$this->limit.' '.$this->offset;

      if ($closure===FALSE) return $this->sql;

      $this->fetch();

      $this->data = $this->rows;

      $this->reset();

      if ( $this->tableOrig!==NULL ) {
         $this->table = $this->tableOrig;
      }

      if ($closure instanceof \Closure) {
         $this->data = $closure( $this->data, $this );
      }

      return $this->data ?: [];
   }
607990
public function callWithDisabledAuth(Closure $closure)
    {
        if ($this->isDisabledAuth()) {
            return call_user_func($closure);
        }

        try {
            $this->disableAuth();

            return call_user_func($closure);
        } finally {
            $this->enableAuth();
        }
    }
115063
public function map(Closure $func)
    {
        $clone = clone $this;

        $clone->data = array_map($func, $this->data);
        $clone->updateBody();

        return $clone;
    }
572255
public function set($name, \Closure $closure)
    {
        $this->extensions->set($name, $closure);
        
        return $this;
    }
1242167
public function closure($closure)
    {
        // Retrieving the class and method to launch.
        if (!is_callable($closure)) {
            return null;
        }

        $injections = $this->injectorForClosure($closure);

        return [
            'action' => $closure,
            'injection' => $injections
        ];
    }
307206
public function each(Closure $closure)
    {
        foreach ($this->stack as &$item) {
            $closure($item);
        }

        return $this;
    }
195740
public function map($closure)
    {
        $data = [];
        foreach ($this as $val) {
            $data[] = $closure($val);
        }
        return new Collection(compact('data'));
    }
400911
public static function runInTrans(\Closure $closure) {
        /* @var $connection Connection */
        $connection = Pool::get(Connection::class);
        $pool = ResourcePool::instance();
        //加锁保证事物内使用的是同一连接
        $pool->lock($connection);
        try {
            $value = $connection->runInTrans($closure);
            //释放锁
            $pool->unLock($connection);
            //释放连接
            $pool->release($connection);
            return $value;
        } catch (\RuntimeException $e) {
            $pool->unLock($connection);
            $pool->release($connection);
            throw $e;
        } catch (\Error $e) {
            $pool->unLock($connection);
            $pool->release($connection);
            throw $e;
        }
    }