Esempio n. 1
0
 /**
  * @test
  * @covers \Sofa\Eloquence\ArgumentBag::isEmpty
  */
 public function is_empty()
 {
     $bag = $this->getBag();
     $empty = new ArgumentBag([]);
     $this->assertFalse($bag->isEmpty());
     $this->assertTrue($empty->isEmpty());
 }
Esempio n. 2
0
 /**
  * Determine the operator for count relation query and set 'not' appropriately.
  *
  * @param  string $method
  * @param  \Sofa\Eloquence\ArgumentBag $args
  * @return string
  */
 protected function getMappedOperator($method, ArgumentBag $args)
 {
     if ($not = $args->get('not')) {
         $args->set('not', false);
     }
     if ($null = $this->isWhereNull($method, $args)) {
         $args->set('not', true);
     }
     return $not ^ $null ? '<' : '>=';
 }
Esempio n. 3
0
 /**
  * Allow custom where method calls on the builder.
  *
  * @codeCoverageIgnore
  *
  * @param  \Sofa\Eloquence\Builder  $query
  * @param  string  $method
  * @param  \Sofa\Eloquence\ArgumentBag  $args
  * @return \Sofa\Eloquence\Builder
  */
 public function queryHook(Builder $query, $method, ArgumentBag $args)
 {
     $this->unwrapHooks(__FUNCTION__);
     $pipes = $this->unwrappedHooks[__FUNCTION__];
     return (new Pipeline($pipes))->send($query)->with(new ArgumentBag(['method' => $method, 'args' => $args]))->to(function ($query) use($method, $args) {
         return call_user_func_array([$query, 'callParent'], [$method, $args->all()]);
     });
 }
Esempio n. 4
0
 /**
  * Call custom handlers for where call.
  *
  * @param  string $method
  * @param  \Sofa\Eloquence\ArgumentBag $args
  * @return mixed
  */
 protected function callHook($method, ArgumentBag $args)
 {
     if ($this->hasHook($args->get('column')) || in_array($method, ['select', 'addSelect'])) {
         return $this->getModel()->queryHook($this, $method, $args);
     }
     return $this->callParent($method, $args->all());
 }
Esempio n. 5
0
 /**
  * Order query by meta attribute.
  *
  * @param  \Sofa\Eloquence\Builder $query
  * @param  \Sofa\Eloquence\ArgumentBag $args
  * @param  string $alias
  * @return \Sofa\Eloquence\Builder
  */
 protected function orderByMeta(Builder $query, $args, $alias)
 {
     $query->with('metaAttributes')->getQuery()->orderBy("{$alias}.meta_value", $args->get('direction'));
     return $query;
 }
Esempio n. 6
0
 /**
  * Get the relation constraint closure.
  *
  * @param  string $method
  * @param  \Sofa\Eloquence\ArgumentBag $args
  * @return \Closure
  */
 protected function getMetaWhereConstraint($method, ArgumentBag $args)
 {
     $column = $args->get('column');
     $args->set('column', 'meta_value');
     if ($method === 'whereBetween') {
         return $this->getMetaBetweenConstraint($column, $args->get('values'));
     }
     return function ($query) use($column, $method, $args) {
         $query->where('meta_key', $column);
         if ($args->get('value') || $args->get('values')) {
             call_user_func_array([$query, $method], $args->all());
         }
     };
 }