Esempio n. 1
0
 protected function _getAggregate($method, ISelectExpression $expression)
 {
     $originalClause = $this->_query->getClause('SELECT');
     $this->_query->addClause((new SelectClause())->addExpression($expression));
     $result = Arrays::first(Arrays::first($this->_getDataStore()->getData($this->_query)));
     $this->_query->addClause($originalClause);
     return $result;
 }
Esempio n. 2
0
 private function _getNewSet(...$expressions)
 {
     $newPredicates = WhereClause::buildPredicates($expressions);
     if (count($newPredicates) === 1) {
         $newSet = Arrays::first($newPredicates);
     } else {
         $newSet = new PredicateSet();
         $newSet->setPredicates($newPredicates);
     }
     return $newSet;
 }
Esempio n. 3
0
 protected function _getAggregate($method, ISelectExpression $expression)
 {
     if ($this->isEmpty() && !$this->_isLoaded) {
         $orderBy = $this->_query->getClause('ORDER BY');
         //Remove order by for improved query performance
         if ($orderBy !== null) {
             $this->_query->removeClause('ORDER BY');
         }
         //Run a sub query if a limit is specified
         if ($this->_query->hasClause('LIMIT')) {
             $builder = $this->_getQueryBuilder();
             $aggregateQuery = $builder::select($expression)->from(SubQuerySelectExpression::create($this->_query, '_'));
             $result = Arrays::first(Arrays::first($this->_getDataStore()->getData($aggregateQuery)));
         } else {
             $originalClause = $this->_query->getClause('SELECT');
             $this->_query->addClause((new SelectClause())->addExpression($expression));
             $result = Arrays::first(Arrays::first($this->_getDataStore()->getData($this->_query)));
             $this->_query->addClause($originalClause);
         }
         if ($orderBy !== null) {
             $this->_query->addClause($orderBy);
         }
         return $result;
     }
     return parent::$method();
 }
Esempio n. 4
0
 public function testHeadLast()
 {
     $this->assertEquals('a', Arrays::first(explode('.', 'a.b')));
     $this->assertEquals('b', Arrays::last(explode('.', 'a.b')));
 }
Esempio n. 5
0
 /**
  * Retrieve the first available dao
  *
  * @param mixed $default
  *
  * @return IDao
  */
 public function first($default = null)
 {
     $this->_prepareDaos();
     if (empty($this->_daos)) {
         return $default;
     }
     return Arrays::first((array) $this->_daos);
 }
Esempio n. 6
0
 /**
  * Returns the first element of an array. Exactly like reset(), but doesn't
  * choke if you pass it some non-referenceable value like the return value of
  * a function.
  *
  * @param    array Array to retrieve the first element from.
  *
  * @return   mixed  The first value of the array.
  * @group util
  *
  * @deprecated
  */
 function head(array $arr)
 {
     return \Packaged\Helpers\Arrays::first($arr);
 }
Esempio n. 7
0
 /**
  * @param $reference
  *
  * @return CustomerResponse
  * @throws NotFoundException
  */
 public function retrieveCustomerByExternalReference($reference)
 {
     $ep = $this->_getEndpoint();
     $payload = new PaginatedDataNodePayload();
     $payload->filter = [AdvancedFilterPayload::create('externalReference', AdvancedFilterComparator::EQUAL, $reference)];
     $customers = $this->_processRequest($ep->all($payload));
     if (count($customers->items) >= 1) {
         return Arrays::first($customers->items);
     } else {
         throw new NotFoundException("No customer could be located with the reference {$reference}");
     }
 }
Esempio n. 8
0
 public function __call($method, $params)
 {
     if (Strings::startsWith($method, 'get')) {
         return $this->_getProperty(substr($method, 3), Arrays::first($params));
     } else {
         throw new \Exception("Method {$method} is not supported");
     }
 }
Esempio n. 9
0
 public static function generate($time = null)
 {
     return (ValueAs::nonempty($time, time()) << 32) + Arrays::first(unpack('L', Strings::randomString(4)));
 }
Esempio n. 10
0
 public function assemblePredicateClause(AbstractPredicateClause $clause)
 {
     if (!$clause->hasPredicates()) {
         return '';
     }
     if (count($clause->getPredicates()) === 1 && Arrays::first($clause->getPredicates()) instanceof PredicateSet) {
         $assembled = $this->getAssembler()->assembleSegment(Arrays::first($clause->getPredicates()));
         if (Strings::startsWith($assembled, '(') && Strings::endsWith($assembled, ')')) {
             $assembled = substr($assembled, 1, -1);
         }
         return $clause->getAction() . ' ' . $assembled;
     } else {
         return $clause->getAction() . ' ' . implode($clause->getGlue(), $this->assembleSegments($clause->getPredicates()));
     }
 }