Author: Elliot Levin (elliotlevin@hotmail.com)
Esempio n. 1
0
 public function removeRange($values)
 {
     if (!Utilities::isIterable($values)) {
         throw PinqException::invalidIterable(__METHOD__, $values);
     }
     $this->executeQuery($this->newMethod(__FUNCTION__, [$values]));
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  * @param Collection|null $source
  */
 public static function from($elements, Iterators\IIteratorScheme $scheme = null, Traversable $source = null)
 {
     if ($source !== null && !$source instanceof Collection) {
         throw new PinqException('Cannot construct %s: expecting source to be type %s or null, %s given', __CLASS__, __CLASS__, Utilities::getTypeOrClass($source));
     }
     return new static($elements, $scheme, $source);
 }
Esempio n. 3
0
 protected function compileCode(&$code)
 {
     if (self::isValueType($this->value)) {
         $code .= var_export($this->value, true);
     } else {
         throw new PinqException('Cannot compile %s to code: value must be a value type (scalar or array of scalars), currently %s', get_class($this), Utilities::getTypeOrClass($this->value));
     }
 }
 public function hash($value)
 {
     if (!$value instanceof IQueryable) {
         throw new PinqException('Cannot get hash of compiled request query: expecting type of %s, %s given', IQueryable::IQUERYABLE_TYPE, Utilities::getTypeOrClass($value));
     }
     $provider = $value->getProvider();
     if (!$provider instanceof DSL\QueryProvider) {
         throw new PinqException('Cannot get hash of compiled request query: invalid query provider, expecting type of %s, %s given', DSL\QueryProvider::getType(), Utilities::getTypeOrClass($value));
     }
     return $provider->getCompilerConfiguration()->getCompiledRequestQueryHash($value->getExpression(), $this->evaluationContext);
 }
Esempio n. 5
0
 protected final function visit(O\Expression $expression)
 {
     if ($expression instanceof O\ValueExpression) {
         $queryable = $expression->getValue();
         if (!$queryable instanceof IQueryable) {
             throw new PinqException('Invalid scope expression: must originate from %s, %s given', IQueryable::IQUERYABLE_TYPE, Utilities::getTypeOrClass($queryable));
         }
         if ($queryable->isSource()) {
             $this->addSegment(function () use($queryable) {
                 $this->interpretation->interpretScopeSource($queryable);
             });
             return;
         }
         $expression = $queryable->getExpression();
     }
     $methodName = $this->getMethodName($expression);
     $this->segmentCounter++;
     $this->segmentId = "{$this->segmentCounter}-{$methodName}";
     if (!method_exists($this, "visit{$methodName}")) {
         throw new PinqException('Cannot interpret query scope with method call \'%s\'', $methodName);
     }
     $this->{"visit{$methodName}"}($expression);
 }
Esempio n. 6
0
 /**
  * Compiles the expression tree into debug code.
  *
  * @return string
  */
 public final function compileDebug()
 {
     return (new DynamicExpressionWalker([ValueExpression::getType() => function (ValueExpression $expression) {
         $value = $expression->getValue();
         return !is_scalar($value) && $value !== null ? Expression::constant('{' . Utilities::getTypeOrClass($expression->getValue()) . '}') : $expression;
     }]))->walk($this)->compile();
 }