本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::getClassMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::getClassMetadata方法的具体用法?PHP EntityManager::getClassMetadata怎么用?PHP EntityManager::getClassMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kdyby\Doctrine\EntityManager
的用法示例。
在下文中一共展示了EntityManager::getClassMetadata方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEntityPrimaryKeyName
/**
* Primary key name in entity
*
* @param object|string $entity
* @return string
* @throws \Doctrine\ORM\Mapping\MappingException
*/
protected function getEntityPrimaryKeyName($entity)
{
if (is_object($entity)) {
$entity = ClassUtils::getClass($entity);
}
$meta = $this->entityManager->getClassMetadata($entity);
return $meta->getSingleIdentifierFieldName();
}
示例2: isEntity
/**
* @param string
* @return bool
*/
private function isEntity($className)
{
try {
$this->em->getClassMetadata($className);
return TRUE;
} catch (Doctrine\Common\Persistence\Mapping\MappingException $e) {
return FALSE;
}
}
示例3: setIdentity
/**
* Sets the user identity.
* @return UserStorage Provides a fluent interface
*/
public function setIdentity(IIdentity $identity = null)
{
if ($identity !== NULL) {
$class = get_class($identity);
// we want to convert identity entities into fake identity
// so only the identifier fields are stored,
// but we are only interested in identities which are correctly
// mapped as doctrine entities
if ($this->entityManager->getMetadataFactory()->hasMetadataFor($class)) {
$cm = $this->entityManager->getClassMetadata($class);
$identifier = $cm->getIdentifierValues($identity);
$identity = new FakeIdentity($identifier, $class);
}
}
return parent::setIdentity($identity);
}
示例4: detectPrimaryKey
/**
* @param \Kdyby\Doctrine\Entities\BaseEntity $object
* @return string
*/
private function detectPrimaryKey(BaseEntity $object)
{
if ($object instanceof BaseEntity) {
$meta = $this->entityManager->getClassMetadata(get_class($object));
$name = $meta->getSingleIdentifierFieldName();
return $meta->getFieldValue($object, $name);
}
}
示例5: create
/**
* @param object|string
* @param bool|null
*/
public function create($entity, $createMapper = self::AUTO)
{
$className = is_string($entity) ? $entity : get_class($entity);
$classMetadata = $this->entityManager->getClassMetadata($className);
/** @var FormBuilder $builder */
$builder = $this->configuration->getHandler()->handle(NULL, [], $classMetadata, $this->configuration);
if (!$builder instanceof FormBuilder) {
throw new UnexpectedValueException("Builder created by root handler must be an instance of FormBuilder");
}
if ($createMapper === TRUE || $createMapper === self::AUTO && is_object($entity)) {
if (!is_object($entity)) {
throw new InvalidArgumentException("If you want to create mapper, you have to pass an entity.");
}
if (!$this->mapperFactory) {
throw new InvalidStateException("MapperFactory has not been injected.");
}
$form = $builder->getForm();
if (!$form instanceof IFormWithMapper) {
throw new InvalidStateException("Form does not implement \\Librette\\Forms\\IFormWithMapper");
}
$form->setMapper($this->mapperFactory->create($entity));
}
return $builder;
}
示例6: buildSelectForUpdateQuery
/**
* @param EntityRepository $repository
* @param ORMMetadata $class
* @return \Doctrine\ORM\QueryBuilder
*/
protected function buildSelectForUpdateQuery(EntityRepository $repository, ORMMetadata $class)
{
$qb = $repository->createQueryBuilder('e', 'e.id');
$i = 0;
foreach ($class->getAssociationMappings() as $assocMapping) {
if (!$class->isSingleValuedAssociation($assocMapping['fieldName'])) {
continue;
}
$targetClass = $this->entityManager->getClassMetadata($assocMapping['targetEntity']);
$alias = substr($assocMapping['fieldName'], 0, 1) . $i++;
$qb->leftJoin('e.' . $assocMapping['fieldName'], $alias)->addSelect($alias);
// todo: deeper!
}
return $qb;
}
示例7: getUniqueAndRequiredAssociations
private function getUniqueAndRequiredAssociations(ClassMetadata $meta, $entity)
{
$associations = array();
foreach ($meta->getAssociationNames() as $associationName) {
$mapping = $meta->getAssociationMapping($associationName);
if (!empty($mapping['id']) && $meta->usesIdGenerator()) {
// autogenerated id
continue;
}
if (!($mapping['type'] & ClassMetadata::TO_ONE)) {
// is not to one relation
continue;
}
if (empty($mapping['isOwningSide'])) {
// is not owning side
continue;
}
foreach ($mapping['joinColumns'] as $joinColumn) {
if (!empty($joinColumn['nullable']) && empty($joinColumn['unique'])) {
// is nullable and is not unique
continue;
}
$targetColumn = $joinColumn['referencedColumnName'];
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
$newVal = $meta->getFieldValue($entity, $associationName);
if ($newVal !== NULL) {
$newValId = $this->uow->getEntityIdentifier($newVal);
}
switch (TRUE) {
case $newVal === NULL:
$value = NULL;
break;
case $targetClass->containsForeignIdentifier:
$value = $newValId[$targetClass->getFieldForColumn($targetColumn)];
break;
default:
$value = $newValId[$targetClass->fieldNames[$targetColumn]];
break;
}
$sourceColumn = $joinColumn['name'];
$quotedColumn = $this->quotes->getJoinColumnName($joinColumn, $meta, $this->platform);
$associations[$sourceColumn]['value'] = $value;
$associations[$sourceColumn]['quotedColumn'] = $quotedColumn;
$associations[$sourceColumn]['type'] = $targetClass->getTypeOfColumn($targetColumn);
}
}
return $associations;
}
示例8: renderDefault
public function renderDefault()
{
$this->em->getClassMetadata(\Entities\ITag::class);
$this->template->anyVariable = 'any value';
}
示例9: getPrimaryKeyByObject
/**
* @param mixed $object
* @return string[]
*/
public function getPrimaryKeyByObject($object)
{
return array(self::ENTITY_CLASS => $this->entityManager->getClassMetadata(get_class($object))->name, self::PRIMARY_KEY => $this->entityManager->getUnitOfWork()->getSingleIdentifierValue($object));
}
示例10: addScope
/**
* @param EntityManager
* @param ISortableScope
* @param QueryBuilder
*/
private function addScope(EntityManager $em, ISortableScope $sortable, QueryBuilder $qb)
{
$meta = $em->getClassMetadata(get_class($sortable));
$rc = new \ReflectionClass($sortable);
foreach ($sortable->getSortableScope() as $field) {
if ($meta->hasField($field) || $meta->hasAssociation($field)) {
$rp = $rc->getProperty($field);
$rp->setAccessible(TRUE);
$qb->andWhere($qb->expr()->eq('e.' . $field, ':p_' . $field));
$qb->setParameter('p_' . $field, $rp->getValue($sortable));
} elseif ($meta->discriminatorColumn['name'] === $field) {
if (($type = array_search(get_class($sortable), $meta->discriminatorMap)) === FALSE) {
$type = get_class($sortable);
}
$qb->andWhere('e INSTANCE OF :discr_type')->setParameter('discr_type', $type);
} else {
throw new InvalidScopeException("Scope field {$field} is neither field, association nor discriminator");
}
}
}