Example #1
0
 /**
  * Parses left join
  * @example: a.SampleRelationName b will be parsed to parentAlias: a, relationName: SampleRelationName, alias: b
  *
  * @param  string         $leftJoin
  * @param  QueryInterface $query
  * @throws QueryException
  * @return array
  */
 public function parseLeftJoin($leftJoin, QueryInterface $query)
 {
     $posParentAlias = strpos($leftJoin, '.');
     if ($posParentAlias === false) {
         throw new QueryException("Left join '{$leftJoin}' misses parent alias!");
     }
     $posAlias = strpos($leftJoin, ' ');
     if ($posAlias === false) {
         throw new QueryException("Left join '{$leftJoin}' misses alias!");
     }
     $explodePositions = array($posParentAlias, $posAlias);
     list($parentAlias, $relationName, $alias) = StringExplode::explodeAt($leftJoin, $explodePositions);
     if (!$query->hasQueryComponent($parentAlias)) {
         throw new QueryException("Parent alias '{$parentAlias}' is not defined in query!");
     }
     if ($query->hasQueryComponent($alias)) {
         throw new QueryException("Duplicate alias '{$alias}' in query!");
     }
     $parent = $query->getQueryComponent($parentAlias);
     $parentTableName = $parent['table'];
     $parentTable = $query->getRecordManager()->getTable($parentTableName);
     $relation = $parentTable->getRelation($relationName);
     return array('parent' => $parentAlias, 'alias' => $alias, 'relation' => $relationName, 'table' => $relation->getJoinTableName($relationName));
 }
Example #2
0
 /**
  * @param string $method
  * @param string $text
  * @param string $expected
  * @dataProvider provideRTrimMultiLine
  */
 public function testRTrimMultiLine($method, $text, $expected)
 {
     $actual = StringExplode::trimMultiLines($text, $method, PHP_EOL);
     $this->assertEquals($expected, $actual);
 }
Example #3
0
 /**
  * Sets from part for query
  *
  * @param  string        $from
  * @param  array|string  $params
  * @throws QueryException
  * @return $this
  */
 public function from($from, $params = array())
 {
     $pos = strpos($from, ' ');
     if ($pos === false) {
         throw new QueryException("Missing alias in query from '{$from}'!");
     }
     list($tableName, $alias) = StringExplode::explodeAt($from, $pos);
     $alias = trim($alias);
     $this->rootAlias = $alias;
     $this->queryComponents[$alias] = array('table' => $tableName);
     $quote = $this->getRecordManager()->getConnection()->getIdentifierQuote();
     $from = $quote . $tableName . $quote . ' ' . $alias;
     $this->setQueryPart(self::PART_FROM, $from, $params);
     return $this;
 }
Example #4
0
 /**
  * @param string $text
  * @param string $prefix
  * @param string $inlineCommentStart
  * @param string $suffix
  * @return string
  */
 private function formatComment($text, $prefix = '//', $inlineCommentStart = '//', $suffix = '')
 {
     $text = preg_replace('/^(.*?)$/m', $inlineCommentStart . ' $1', $text);
     $text = StringExplode::trimMultiLines($text, 'rTrim', $this->eol);
     return "{$prefix}{$text}{$suffix}";
 }