本文整理汇总了PHP中Doctrine\ORM\Query::setHint方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setHint方法的具体用法?PHP Query::setHint怎么用?PHP Query::setHint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query
的用法示例。
在下文中一共展示了Query::setHint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyTranslatorGedmoHints
/**
* @param Query $query
*/
protected function applyTranslatorGedmoHints(Query &$query)
{
if (BELCEBUR_GEDMO_TRANSLATION_LOCALE !== 'BELCEBUR_GEDMO_TRANSLATION_LOCALE') {
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, $this->gedmoWalker);
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, BELCEBUR_GEDMO_TRANSLATION_LOCALE);
$query->setHint(TranslatableListener::HINT_FALLBACK, TRUE);
}
}
示例2: setTranslatableQueryHints
/**
* @param Query $query
* @param string $locale
* @throws \Exception
*/
protected function setTranslatableQueryHints(Query $query, $locale)
{
if (!class_exists('Gedmo\\Translatable\\TranslatableListener')) {
throw new \Exception('"Translatable" extension missing. "stof/doctrine-extensions-bundle" needs to be installed');
}
$query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
$query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
$query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_FALLBACK, 1);
}
示例3: apply
/**
* {@inheritdoc}
*/
public function apply($fromAlias, $fromIdentifier, $resourcePrefix, array $requesterIdentifiers, $mask, array $orX = [])
{
$this->query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'AlexDpy\\Acl\\Database\\Filter\\DoctrineOrmAclWalker');
$this->query->setHint('acl_permissions_table_name', $this->getAclSchema()->getPermissionsTableName());
$this->query->setHint('acl_resource_prefix', $resourcePrefix);
$this->query->setHint('acl_requester_identifiers', $requesterIdentifiers);
$this->query->setHint('acl_mask', $mask);
$this->query->setHint('acl_from_alias', $fromAlias);
$this->query->setHint('acl_from_identifier', $fromIdentifier);
$this->query->setHint('acl_or_x', $orX);
return $this->query;
}
示例4: apply
/**
* Apply ACL filter
*
* @param QueryBuilder | Query $query
* @param array $permissions
* @param string | UserInterface $identity
* @param string $alias
* @param array|Query|QueryBuilder $extraCriteria
*
* @return Query
*/
public function apply($query, array $permissions = array('VIEW'), $identity = null, $alias = null, $extraCriteria = false)
{
if (null === $identity) {
$token = $this->securityContext->getToken();
$identity = $token->getUser();
}
$query->setHint(static::HINT_ACL_EXTRA_CRITERIA, $this->getExtraCriteria($extraCriteria));
if ($query instanceof QueryBuilder) {
$query = $this->cloneQuery($query->getQuery());
} elseif ($query instanceof Query) {
$query = $this->cloneQuery($query);
} else {
throw new \Exception();
}
$maskBuilder = new MaskBuilder();
foreach ($permissions as $permission) {
$mask = constant(get_class($maskBuilder) . '::MASK_' . strtoupper($permission));
$maskBuilder->add($mask);
}
$entity = $this->getEntityFromAlias($query, $alias);
$metadata = $entity['metadata'];
$alias = $entity['alias'];
$table = $metadata->getQuotedTableName($this->em->getConnection()->getDatabasePlatform());
$aclQuery = $this->getExtraQuery($this->getClasses($metadata), $this->getIdentifiers($identity), $maskBuilder->get());
$hintAclMetadata = false !== $query->getHint('acl.metadata') ? $query->getHint('acl.metadata') : array();
$hintAclMetadata[] = array('query' => $aclQuery, 'table' => $table, 'alias' => $alias);
$query->setHint('acl.metadata', $hintAclMetadata);
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, $this->aclWalker);
return $query;
}
示例5: addHint
/**
* Adds a hint to a query object
*
* @param Query $query
* @param string $name
* @param mixed $value
*
* @return bool TRUE if the hint is added; otherwise, FALSE
*/
public function addHint(Query $query, $name, $value)
{
$result = false;
if ($name === Query::HINT_CUSTOM_TREE_WALKERS) {
$walkers = $query->getHint(Query::HINT_CUSTOM_TREE_WALKERS);
if (false === $walkers) {
$walkers = [$value];
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $walkers);
$result = true;
} elseif (!in_array($value, $walkers, true)) {
$walkers[] = $value;
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $walkers);
$result = true;
}
} elseif ($name === Query::HINT_CUSTOM_OUTPUT_WALKER) {
if ($query->getHint($name) !== $value) {
$query->setHint($name, $value);
$result = true;
}
} else {
$query->setHint($name, $value);
$result = true;
}
return $result;
}
示例6: __construct
/**
* @param \Doctrine\ORM\Query $query The Doctrine Query
* @param array $fields Fields to export
* @param string $dateTimeFormat
*/
public function __construct(Query $query, array $fields, $dateTimeFormat = 'r')
{
$this->query = clone $query;
$this->query->setParameters($query->getParameters());
foreach ($query->getHints() as $name => $value) {
$this->query->setHint($name, $value);
}
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
$this->propertyPaths = array();
foreach ($fields as $name => $field) {
if (is_string($name) && is_string($field)) {
$this->propertyPaths[$name] = new PropertyPath($field);
} else {
$this->propertyPaths[$field] = new PropertyPath($field);
}
}
$this->dateTimeFormat = $dateTimeFormat;
}
示例7: updateQuery
/**
* Updates the configured query object with the where-clause and query-hints.
*
* @param string $prependQuery Prepends this string to the where-clause
* (" WHERE " or " AND " for example)
*
* @return self
*/
public function updateQuery($prependQuery = ' WHERE ')
{
$whereCase = $this->getWhereClause($prependQuery);
if ('' !== $whereCase) {
$this->query->setDQL($this->query->getDQL() . $whereCase);
$this->query->setHint($this->getQueryHintName(), $this->getQueryHintValue());
}
return $this;
}
示例8: addCustomTreeWalker
/**
* Add a custom TreeWalker $walker class name to
* be included in the CustomTreeWalker hint list
* of the given $query
*
* @param Query $query
* @param string $walker
* @return void
*/
public static function addCustomTreeWalker(Query $query, $walker)
{
$customTreeWalkers = $query->getHint(Query::HINT_CUSTOM_TREE_WALKERS);
if ($customTreeWalkers !== false && is_array($customTreeWalkers)) {
$customTreeWalkers = array_merge($customTreeWalkers, array($walker));
} else {
$customTreeWalkers = array($walker);
}
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $customTreeWalkers);
}
示例9: __construct
/**
* @param \Doctrine\ORM\Query $query The Doctrine Query
* @param array $fields Fields to export
* @param string $dateTimeFormat
*/
public function __construct(Query $query, array $fields, $dateTimeFormat = 'r')
{
$this->query = clone $query;
$this->query->setParameters($query->getParameters());
foreach ($query->getHints() as $name => $value) {
$this->query->setHint($name, $value);
}
// Note : will be deprecated in Symfony 3.0, conserved for 2.2 compatibility
// Use createPropertyAccessor() for 3.0
// @see Symfony\Component\PropertyAccess\PropertyAccess
$this->propertyAccessor = PropertyAccess::getPropertyAccessor();
$this->propertyPaths = array();
foreach ($fields as $name => $field) {
if (is_string($name) && is_string($field)) {
$this->propertyPaths[$name] = new PropertyPath($field);
} else {
$this->propertyPaths[$field] = new PropertyPath($field);
}
}
$this->dateTimeFormat = $dateTimeFormat;
}
示例10: setHint
public function setHint(\Doctrine\ORM\Query $query)
{
return $query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
}
示例11: appendTreeWalker
/**
* Appends a custom tree walker to the tree walkers hint.
*
* @param Query $query
* @param string $walkerClass
*/
private function appendTreeWalker(Query $query, $walkerClass)
{
$hints = $query->getHint(Query::HINT_CUSTOM_TREE_WALKERS);
if ($hints === false) {
$hints = array();
}
$hints[] = $walkerClass;
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $hints);
}
示例12: getAllowedEntityIds
/**
* Returns valid IDs for a specific entity with ACL restrictions for current user applied
*
* @param PermissionDefinition $permissionDef
*
* @throws InvalidArgumentException
*
* @return array
*/
public function getAllowedEntityIds(PermissionDefinition $permissionDef)
{
$rootEntity = $permissionDef->getEntity();
if (empty($rootEntity)) {
throw new InvalidArgumentException("You have to provide an entity class name!");
}
$builder = new MaskBuilder();
foreach ($permissionDef->getPermissions() as $permission) {
$mask = constant(get_class($builder) . '::MASK_' . strtoupper($permission));
$builder->add($mask);
}
$query = new Query($this->em);
$query->setHint('acl.mask', $builder->get());
$query->setHint('acl.root.entity', $rootEntity);
$sql = $this->getPermittedAclIdsSQLForUser($query);
$rsm = new ResultSetMapping();
$rsm->addScalarResult('id', 'id');
$nativeQuery = $this->em->createNativeQuery($sql, $rsm);
$transform = function ($item) {
return $item['id'];
};
$result = array_map($transform, $nativeQuery->getScalarResult());
return $result;
}
示例13: setQueryHints
/**
* Sets hints for result query
*
* @param Query $query
*/
protected function setQueryHints(Query $query)
{
if (!empty($this->queryHints)) {
foreach ($this->queryHints as $name => $value) {
if (defined("Doctrine\\ORM\\Query::{$name}")) {
$name = constant("Doctrine\\ORM\\Query::{$name}");
}
$query->setHint($name, $value);
}
}
}
示例14: setTranslatableHint
/**
* Add hints to the query
*
* @param Query $query Query
* @param string|null $locale Lecale to which fallback
*
* @return Query
*/
public function setTranslatableHint(Query $query, $locale = null)
{
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
$query->setHint(TranslatableListener::HINT_INNER_JOIN, false);
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
$query->setHint(TranslatableListener::HINT_FALLBACK, true);
return $query;
}
示例15: addHintToQuery
/**
* Adds a Query hint to a Query Object
* @param \Doctrine\ORM\Query $query
* @return \Doctrine\ORM\Query
*/
public function addHintToQuery(\Doctrine\ORM\Query $query)
{
return $query->setHint($this->getConfiguration()->GetQueryHintName(), $this->getConfiguration()->GetQueryHintValue());
}