本文整理汇总了PHP中TYPO3\Flow\Persistence\PersistenceManagerInterface::createQueryForType方法的典型用法代码示例。如果您正苦于以下问题:PHP PersistenceManagerInterface::createQueryForType方法的具体用法?PHP PersistenceManagerInterface::createQueryForType怎么用?PHP PersistenceManagerInterface::createQueryForType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\Flow\Persistence\PersistenceManagerInterface
的用法示例。
在下文中一共展示了PersistenceManagerInterface::createQueryForType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptions
/**
*/
public function getOptions()
{
$classSchema = $this->reflectionService->getClassSchema($this->getRelationClass());
if ($classSchema->getRepositoryClassName() !== NULL) {
$repository = $this->objectManager->get($classSchema->getRepositoryClassName());
$query = call_user_func(array($repository, $this->settings['QueryMethod']));
} else {
$query = $this->persistenceManager->createQueryForType($this->getRelationClass());
}
$options = $query->execute()->toArray();
if ($this->settings['LabelPath'] !== NULL) {
$options = array();
foreach ($query->execute() as $option) {
$identifier = $this->persistenceManager->getIdentifierByObject($option);
$label = ObjectAccess::getPropertyPath($option, $this->settings['LabelPath']);
$options[$identifier] = $label;
}
}
if ($this->settings['EmptyOption'] !== NULL) {
$newOptions = array('' => $this->settings['EmptyOption']);
foreach ($options as $key => $value) {
$newOptions[$key] = $value;
}
$options = $newOptions;
}
return $options;
}
示例2: findObjectByIdentityProperties
/**
* Finds an object from the repository by searching for its identity properties.
*
* @param array $identityProperties Property names and values to search for
* @param string $type The object type to look for
* @return object Either the object matching the identity or NULL if no object was found
* @throws DuplicateObjectException if more than one object was found
*/
protected function findObjectByIdentityProperties(array $identityProperties, $type)
{
$query = $this->persistenceManager->createQueryForType($type);
$classSchema = $this->reflectionService->getClassSchema($type);
$equals = array();
foreach ($classSchema->getIdentityProperties() as $propertyName => $propertyType) {
if (isset($identityProperties[$propertyName])) {
if ($propertyType === 'string') {
$equals[] = $query->equals($propertyName, $identityProperties[$propertyName], FALSE);
} else {
$equals[] = $query->equals($propertyName, $identityProperties[$propertyName]);
}
}
}
if (count($equals) === 1) {
$constraint = current($equals);
} else {
$constraint = $query->logicalAnd(current($equals), next($equals));
while (($equal = next($equals)) !== FALSE) {
$constraint = $query->logicalAnd($constraint, $equal);
}
}
$objects = $query->matching($constraint)->execute();
$numberOfResults = $objects->count();
if ($numberOfResults === 1) {
return $objects->getFirst();
} elseif ($numberOfResults === 0) {
return NULL;
} else {
throw new DuplicateObjectException('More than one object was returned for the given identity, this is a constraint violation.', 1259612399);
}
}
示例3: createQuery
/**
* Returns a query for objects of this repository
*
* @return \TYPO3\Flow\Persistence\QueryInterface
* @api
*/
public function createQuery()
{
$query = $this->persistenceManager->createQueryForType($this->entityClassName);
if ($this->defaultOrderings !== array()) {
$query->setOrderings($this->defaultOrderings);
}
return $query;
}
示例4: getModificationsNeededStatesAndIdentifiers
/**
* @param Client $client
* @param string $className
*
* @return array
*/
protected function getModificationsNeededStatesAndIdentifiers(Client $client, $className)
{
$query = $this->persistenceManager->createQueryForType($className);
$states = array(ObjectIndexer::ACTION_TYPE_CREATE => array(), ObjectIndexer::ACTION_TYPE_UPDATE => array(), ObjectIndexer::ACTION_TYPE_DELETE => array());
foreach ($query->execute() as $object) {
$state = $this->objectIndexer->objectIndexActionRequired($object, $client);
$states[$state][] = $this->persistenceManager->getIdentifierByObject($object);
}
return $states;
}
示例5: isValid
/**
* Checks if the given value is a unique entity depending on it's identity properties or
* custom configured identity properties.
*
* @param mixed $value The value that should be validated
* @return void
* @throws \TYPO3\Flow\Validation\Exception\InvalidValidationOptionsException
* @api
*/
protected function isValid($value)
{
if (!is_object($value)) {
throw new InvalidValidationOptionsException('The value supplied for the UniqueEntityValidator must be an object.', 1358454270);
}
$classSchema = $this->reflectionService->getClassSchema($value);
if ($classSchema === NULL || $classSchema->getModelType() !== \TYPO3\Flow\Reflection\ClassSchema::MODELTYPE_ENTITY) {
throw new InvalidValidationOptionsException('The object supplied for the UniqueEntityValidator must be an entity.', 1358454284);
}
if ($this->options['identityProperties'] !== NULL) {
$identityProperties = $this->options['identityProperties'];
foreach ($identityProperties as $propertyName) {
if ($classSchema->hasProperty($propertyName) === FALSE) {
throw new InvalidValidationOptionsException(sprintf('The custom identity property name "%s" supplied for the UniqueEntityValidator does not exists in "%s".', $propertyName, $classSchema->getClassName()), 1358960500);
}
}
} else {
$identityProperties = array_keys($classSchema->getIdentityProperties());
}
if (count($identityProperties) === 0) {
throw new InvalidValidationOptionsException('The object supplied for the UniqueEntityValidator must have at least one identity property.', 1358459831);
}
$identifierProperties = $this->reflectionService->getPropertyNamesByAnnotation($classSchema->getClassName(), 'Doctrine\\ORM\\Mapping\\Id');
if (count($identifierProperties) > 1) {
throw new InvalidValidationOptionsException('The object supplied for the UniqueEntityValidator must only have one identifier property @ORM\\Id.', 1358501745);
}
$identifierPropertyName = count($identifierProperties) > 0 ? array_shift($identifierProperties) : 'Persistence_Object_Identifier';
$query = $this->persistenceManager->createQueryForType($classSchema->getClassName());
$constraints = array($query->logicalNot($query->equals($identifierPropertyName, $this->persistenceManager->getIdentifierByObject($value))));
foreach ($identityProperties as $propertyName) {
$constraints[] = $query->equals($propertyName, ObjectAccess::getProperty($value, $propertyName));
}
if ($query->matching($query->logicalAnd($constraints))->count() > 0) {
$this->addError('Another entity with the same unique identifiers already exists', 1355785874);
}
}
示例6: createQuery
/**
* @return QueryInterface
*/
protected function createQuery()
{
return $this->persistenceManager->createQueryForType($this->projectionClassName);
}