本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::getAllAliases方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::getAllAliases方法的具体用法?PHP QueryBuilder::getAllAliases怎么用?PHP QueryBuilder::getAllAliases使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::getAllAliases方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: shouldJoin
/**
* Strips the key parts and creates a join if it does not exist yet.
*
* @param string $key
*/
protected function shouldJoin($key)
{
$parts = explode('.', $key);
if (!in_array($parts[0], $this->qb->getAllAliases())) {
$this->qb->leftJoin($this->getRootAlias() . '.' . $parts[0], $parts[0]);
}
}
示例2: safeLeftJoin
/**
* @param QueryBuilder $qb
* @param string $attribute
* @param string $aliasJoin
*/
protected function safeLeftJoin(QueryBuilder $qb, string $attribute, string $aliasJoin)
{
$aliases = $qb->getAllAliases();
if (!in_array($aliasJoin, $aliases)) {
$alias = $this->getAlias($qb);
$qb->leftJoin($alias . $attribute, $aliasJoin);
}
}
示例3: setQueryParam
/**
* @param string $field
* @param mixed $value
* @return array
*/
protected function setQueryParam($field)
{
$index = 0;
$rootAlias = $this->qb->getRootAliases()[$index];
if (false !== strpos($field, '.')) {
list($assoc, $subField) = explode('.', $field);
} else {
$assoc = $field;
}
$meta = $this->getClassMetadata($index);
if ($meta->hasAssociation($assoc)) {
$targetClass = $meta->getAssociationTargetClass($assoc);
if ($meta->isCollectionValuedAssociation($assoc)) {
$alias = "{$rootAlias}_{$assoc}";
if (!in_array($alias, $this->qb->getAllAliases())) {
$this->qb->leftJoin("{$rootAlias}.{$assoc}", $alias);
}
$assoc = $alias;
} else {
$alias = "{$rootAlias}_{$assoc}";
if (!in_array($alias, $this->qb->getAllAliases())) {
$this->qb->join("{$rootAlias}.{$assoc}", $alias);
}
$assoc = $alias;
}
$em = $this->qb->getEntityManager();
$targetMeta = $em->getClassMetadata($targetClass);
if (isset($subField) && !$targetMeta->hasField($subField) && $targetMeta->isInheritanceTypeJoined()) {
foreach ($targetMeta->discriminatorMap as $alias => $class) {
$joinedMeta = $em->getClassMetadata($class);
if ($joinedMeta->hasField($subField)) {
if (!in_array($alias, $this->qb->getAllAliases())) {
$this->qb->leftJoin($joinedMeta->getName(), $alias, 'WITH', "{$alias}.id = {$assoc}.id");
}
$assoc = $alias;
}
}
}
$alias = isset($subField) ? "{$assoc}.{$subField}" : $assoc;
} else {
$alias = "{$rootAlias}.{$field}";
}
$values = array_slice(func_get_args(), 1);
if ($values) {
$result = [$alias];
foreach ($values as $value) {
$paramName = $this->getParamName($field);
$this->qb->setParameter($paramName, $value);
$result[] = ":{$paramName}";
}
return $result;
}
return $alias;
}
示例4: visitComparison
/**
* {@inheritdoc}
*
* @throws InvalidArgumentException When a comparison expression is not supported.
*/
public function visitComparison(Expr\Comparison $comparison)
{
$property = $comparison->getProperty();
$path = explode('.', $property->getPath());
$expr = $this->builder->expr();
$aliases = $this->builder->getAllAliases();
$prefix = reset($aliases);
foreach (array_slice($path, 0, -1) as $alias) {
if (!in_array($alias, $aliases)) {
$this->builder->join(sprintf('%s.%s', $prefix, $alias), $alias);
}
$prefix = $alias;
}
$field = sprintf('%s.%s', $prefix, end($path));
$value = $comparison->getValue();
switch (true) {
case $comparison instanceof Expr\IdenticalTo:
case $comparison instanceof Expr\EqualTo:
return $expr->eq($field, $expr->literal($value));
case $comparison instanceof Expr\NotIdenticalTo:
case $comparison instanceof Expr\NotEqualTo:
return $expr->neq($field, $expr->literal($value));
case $comparison instanceof Expr\LessThan:
return $expr->lt($field, $expr->literal($value));
case $comparison instanceof Expr\LessThanOrEqualTo:
return $expr->lte($field, $expr->literal($value));
case $comparison instanceof Expr\GreaterThan:
return $expr->gt($field, $expr->literal($value));
case $comparison instanceof Expr\GreaterThanOrEqualTo:
return $expr->gte($field, $expr->literal($value));
case $comparison instanceof Expr\In:
return $expr->in($field, $expr->literal($value));
case $comparison instanceof Expr\NotIn:
return $expr->notIn($field, $expr->literal($value));
case $comparison instanceof Expr\Contains:
return $expr->like(sprintf('LOWER(%s)', $field), $expr->literal('%' . strtolower($value) . '%'));
}
throw new InvalidArgumentException(sprintf('Unsupported comparison operator "%s".', get_class($comparison)));
}
示例5: getAliases
/**
* {@inheritdoc}
*/
public function getAliases()
{
return $this->queryBuilder->getAllAliases();
}
示例6: getJoinColumnAlias
/**
* @param QueryBuilder $queryBuilder
* @param string $name
* @return string
*/
public function getJoinColumnAlias(QueryBuilder &$queryBuilder, $name)
{
$alias = $queryBuilder->getRootAliases()[0];
$allAliases = $queryBuilder->getAllAliases();
$joinParts = explode('.', $name);
while (count($joinParts) > 1) {
$joinName = array_shift($joinParts);
$joinAlias = $alias . '_' . $joinName;
if (!in_array($joinAlias, $allAliases)) {
$queryBuilder->leftJoin($alias . '.' . $joinName, $joinAlias);
$allAliases[] = $joinAlias;
}
$alias = $joinAlias;
}
return $alias . '.' . current($joinParts);
}