Exemplo n.º 1
0
 /**
  * @param PlaceholderAbstract $placeholder
  * @return void
  */
 public function addCustomPlaceholder(PlaceholderAbstract $placeholder)
 {
     if (!empty($this->adapter)) {
         $placeholder->setQuotePerformer($this->adapter);
     }
     $this->placeholders->addPlaceholder($placeholder);
 }
Exemplo n.º 2
0
 /**
  * @param $matches
  * @return mixed
  */
 private function transformCallback($matches)
 {
     $replacement = $matches[0];
     if (!empty($matches[1])) {
         $tmpPreparedValues = $this->preparedValues;
         $tmpNumberPlaceholder = $this->numberPlaceholder;
         $tmpIsHookSkipValue = $this->isHookSkipValue;
         $replacement = preg_replace_callback($this->getRegexpMain(), [$this, 'transformCallback'], $matches[1]);
         if ($this->isHookSkipValue) {
             $this->isHookSkipValue = $tmpIsHookSkipValue;
             $this->numberPlaceholder = $tmpNumberPlaceholder;
             $this->preparedValues = $tmpPreparedValues;
             return '';
         }
         return $replacement;
     }
     if (!empty($matches[2])) {
         $this->numberPlaceholder++;
         $placeholder = $this->placeholders->getPlaceholder($matches[0]);
         if (count($this->values) == 0) {
             return 'ERROR_NO_VALUE';
         }
         $value = array_shift($this->values);
         if ($value === Database::SKIP_VALUE) {
             $this->isHookSkipValue = true;
         }
         if ($this->isForceExpandValues) {
             $replacement = $placeholder->transformPlaceholder($value);
         } else {
             $replacement = $placeholder->transformPlaceholder($value, $this->adapter->getNativeCommonPlaceholder($this->numberPlaceholder));
             $preparedValue = $placeholder->transformValue($value);
             if ($preparedValue !== Database::SKIP_VALUE) {
                 if (is_array($preparedValue)) {
                     $this->preparedValues = array_merge($this->preparedValues, $preparedValue);
                 } else {
                     $this->preparedValues = array_merge($this->preparedValues, [$preparedValue]);
                 }
             }
         }
     }
     return $replacement;
 }
Exemplo n.º 3
0
 public function testTransformQuery_CustomAdapterCustomPlaceholderWithCommonNativePlaceholderWithoutExpandValueFewValues()
 {
     $myAdapter = Helper::getMockCustomAdapter();
     $placeholders = new PlaceholderCollection();
     $placeholders->addPlaceholder(Helper::getMockCustomPlaceholder('?m'));
     $transformer = new QueryTransformer($myAdapter, $placeholders);
     $result = $transformer->transformQuery(Query::create('SQL_TEXT ?m, ?m SQL_TEXT', ['in1']), false);
     $this->assertEquals('SQL_TEXT ?, ERROR_NO_VALUE SQL_TEXT', $result->getQueryAsText());
     $this->assertSame(['out1'], $result->getValues());
 }