Example #1
0
 /**
  * Get a modifier customised to work on this datatype
  */
 public function getQueryModifier(QuoteInterface $quoting, $cast = true)
 {
     $modifier = new Modifier($quoting, $this->data['type'], false);
     // nullify
     if ($this->data['isNullable']) {
         $modifier->add('pre', '\\Bond\\nullify');
     }
     // datatypes which aren't all lower case need to be identifier quoted
     if ($cast) {
         // datatypes which aren't all lower case need to be identifier quoted
         if (strtolower($this->data['type']) !== $this->data['type']) {
             $type = $quoting->quoteIdent($this->data['type']);
         } else {
             $type = $this->data['type'];
         }
         $modifier->add('post', $modifier->generateCastClosure($type));
     }
     return $modifier;
 }
Example #2
0
 /**
  * Helper method for the parse query regex callback which converts the a string like 'cast(text)|null' or '|null'
  * Into processoer callbacks for Modifier
  * @param string Transformer string we're going to process
  * @param Modifier $modifier
  */
 private function processStringTransformers($string, Modifier $modifier)
 {
     // there can be multiple transformers are separated by |
     foreach (explode('|', $string) as $fragment) {
         switch (true) {
             case $fragment === 'null':
                 $modifier->add('pre', '\\Bond\\nullify');
                 break;
             case substr($fragment, 0, 4) === 'cast':
                 // extract type type from a modifier of the type cast(int), cast(text)
                 // default to the passed type if that doesn't work
                 $castTo = substr($fragment, 5, -1) ?: $modifier->type;
                 // $castTo = $modifier->quoteInterface->quoteIdent( $castTo );
                 $modifier->add('post', $modifier->generateCastClosure($castTo));
                 break;
             default:
                 throw new UnknownQueryModifier($modifier);
         }
     }
 }