本文整理汇总了PHP中Doctrine\ORM\EntityManagerInterface::getClassMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::getClassMetadata方法的具体用法?PHP EntityManagerInterface::getClassMetadata怎么用?PHP EntityManagerInterface::getClassMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::getClassMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param EntityManagerInterface $em
* @param string $class
* @param string $metaClass
*/
public function __construct(EntityManagerInterface $em, $class, $metaClass)
{
$this->em = $em;
$this->repository = $em->getRepository($class);
$this->class = $em->getClassMetadata($class)->name;
$this->metaClass = $em->getClassMetadata($metaClass)->name;
}
示例2: build
/**
* {@inheritdoc}
*/
public function build(MetadataInterface $metadata, FormBuilderInterface $formBuilder, array $options)
{
$classMetadata = $this->entityManager->getClassMetadata($metadata->getClass('model'));
if (1 < count($classMetadata->identifier)) {
throw new \RuntimeException('The default form factory does not support entity classes with multiple primary keys.');
}
$fields = (array) $classMetadata->fieldNames;
if (!$classMetadata->isIdentifierNatural()) {
$fields = array_diff($fields, $classMetadata->identifier);
}
foreach ($fields as $fieldName) {
$options = [];
if (in_array($fieldName, ['createdAt', 'updatedAt', 'deletedAt'])) {
continue;
}
if (Type::DATETIME === $classMetadata->getTypeOfField($fieldName)) {
$options = ['widget' => 'single_text'];
}
$formBuilder->add($fieldName, null, $options);
}
foreach ($classMetadata->getAssociationMappings() as $fieldName => $associationMapping) {
if (ClassMetadataInfo::ONE_TO_MANY !== $associationMapping['type']) {
$formBuilder->add($fieldName, null, ['property' => 'id']);
}
}
}
示例3: testCanBePutInLazyLoadingMode
public function testCanBePutInLazyLoadingMode()
{
$class = $this->_emMock->getClassMetadata('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct');
$collection = new PersistentCollection($this->_emMock, $class, new ArrayCollection());
$collection->setInitialized(false);
$this->assertFalse($collection->isInitialized());
}
示例4: deserializeRelation
public function deserializeRelation(JsonDeserializationVisitor $visitor, $relation, array $type, Context $context)
{
$className = isset($type['params'][0]['name']) ? $type['params'][0]['name'] : null;
if (!class_exists($className)) {
throw new \InvalidArgumentException('Class name should be explicitly set for deserialization');
}
/** @var ClassMetadata $metadata */
$metadata = $this->manager->getClassMetadata($className);
if (!is_array($relation)) {
return $this->manager->getReference($className, $relation);
}
$single = false;
if ($metadata->isIdentifierComposite) {
$single = true;
foreach ($metadata->getIdentifierFieldNames() as $idName) {
$single = $single && array_key_exists($idName, $relation);
}
}
if ($single) {
return $this->manager->getReference($className, $relation);
}
$objects = [];
foreach ($relation as $idSet) {
$objects[] = $this->manager->getReference($className, $idSet);
}
return $objects;
}
示例5: update
/**
* update tables from array of entity classes
* @param array $classes
* @param bool $saveMode
*/
public function update(array $classes, $saveMode = true)
{
$metaClasses = array();
foreach ($classes as $class) {
$metaClasses[] = $this->entityManager->getClassMetadata($class);
}
$this->tool->updateSchema($metaClasses, $saveMode);
}
示例6: getMetadataForEntity
/**
* @param object $entity
*
* @return ClassMetadata
*/
protected function getMetadataForEntity($entity)
{
$class = ClassUtils::getClass($entity);
if (!isset($this->metadataCache[$class])) {
$this->metadataCache[$class] = $this->entityManager->getClassMetadata($class);
}
return $this->metadataCache[$class];
}
示例7: setSectionHasChildren
public function setSectionHasChildren(Section $section = null, $pageCountModifier = 0)
{
if ($section !== null) {
$repo = $this->entityManager->getRepository('BackBee\\CoreDomain\\NestedNode\\Page');
$notDeletedDescendants = $repo->getNotDeletedDescendants($section->getPage(), 1, false, [], true, 0, 2);
$section->setHasChildren($notDeletedDescendants->getIterator()->count() + $pageCountModifier > 0);
$this->entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet($this->entityManager->getClassMetadata('BackBee\\CoreDomain\\NestedNode\\Section'), $section);
}
}
示例8: getMapping
/**
* @see MetadataCache::getMapping
*/
public function getMapping($className)
{
if (!is_string($className) && !is_object($className)) {
throw new \Exception(self::ERROR_MAPPING_EXPECTED_VALUE);
}
$this->stringify($className);
$metadata = $this->getMetadata($className);
if (empty($metadata->mapping)) {
$metadata->mapping = $this->entityManager->getClassMetadata($className);
}
return $metadata->mapping;
}
示例9: ApplyCriteria
/**
* @param Request $request
* @param ResourceInterface $resourceEmbed
* @param $data
*
* @return \Doctrine\Common\Collections\Collection|PersistentCollection
*/
public function ApplyCriteria(Request $request, ResourceInterface $resourceEmbed, $data)
{
if ($data instanceof PersistentCollection && $data->count() > 0) {
$embedClassMeta = $this->em->getClassMetadata($resourceEmbed->getEntityClass());
$criteria = Criteria::create();
foreach ($resourceEmbed->getFilters() as $filter) {
if ($filter instanceof FilterInterface) {
$this->applyFilter($request, $filter, $criteria, $embedClassMeta);
$data = $data->matching($criteria);
}
}
}
return $data;
}
示例10: guessFilterTypeFromArray
/**
* Determines the type of which filter class to instantiate, based on
* the structured array received and the given entity class.
*
* @param FilterOptions $filterOptions
* @param string $entity
*
* @return null|FilterInterface
*/
public function guessFilterTypeFromArray($filterOptions, $entity)
{
$filterType = null;
/* in case the attribute to filter by is situated in another entity,
parse the connected entities until you reach its entity */
if ($path = $filterOptions->getPathArray()) {
while ($path) {
$entity = $this->em->getClassMetadata($entity)->getAssociationMapping(array_shift($path))['targetEntity'];
}
}
if ($filter = $this->filterFieldReader->getFilter($entity, $attribute = $filterOptions->getName())) {
/* get the type of the attribute that corresponds to the filter */
$attributeType = isset($filter[$attribute]['options']['type']) ? $filter[$attribute]['options']['type'] : $this->em->getClassMetadata($entity)->getTypeOfField($filter[$attribute]['property']);
$filterOptions->setAttribute($filter[$attribute]['property']);
if (sizeof($filterOptions->getValues()) == 1) {
switch ($attributeType) {
case 'integer':
$filterType = FilterInterface::NUMERIC_FILTER;
break;
case 'text':
case 'string':
$filterType = FilterInterface::STRING_FILTER;
break;
case 'date':
$filterType = FilterInterface::DATE_FILTER;
break;
case 'checker':
$filterType = FilterInterface::CHECK_FILTER;
break;
}
} else {
switch ($attributeType) {
case 'integer':
$filterType = FilterInterface::NUMERIC_INTERVAL_FILTER;
break;
case 'date':
$filterType = FilterInterface::DATE_INTERVAL_FILTER;
break;
case 'string':
$filterType = FilterInterface::OR_STRING_FILTER;
break;
case 'date_check':
$filterType = FilterInterface::DATE_CHECK_FILTER;
break;
}
}
}
return $filterType;
}
示例11: getClassMetadata
/**
* Retrieve ClassMetadata associated to entity class name.
*
* @param string $className
*
* @return \Doctrine\ORM\Mapping\ClassMetadata
*/
protected function getClassMetadata($className)
{
if (!isset($this->_metadataCache[$className])) {
$this->_metadataCache[$className] = $this->_em->getClassMetadata($className);
}
return $this->_metadataCache[$className];
}
示例12: transform
public function transform($value)
{
// already transformed (or null)
if (is_array($value) || is_null($value)) {
return $value;
}
if (!is_object($value)) {
throw new TransformationFailedException(sprintf('Expected an object to transform, got "%s"', json_encode($value)));
}
// load object if it's a Proxy
if ($value instanceof Proxy) {
$value->__load();
}
$meta = $this->entityManager->getClassMetadata(get_class($value));
return $meta->getIdentifierValues($value);
}
示例13: getMutatedFields
/**
* Return the field names of fields that had their value/relation changed
*
* @param EntityManagerInterface $em
* @param mixed $entity
* @param mixed $original
* @return bool
*/
public function getMutatedFields(EntityManagerInterface $em, $entity, $original)
{
$mutation_data = [];
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
$metadata = $em->getClassMetadata(get_class($entity));
$fields = $metadata->getFieldNames();
$associations = $metadata->getAssociationNames();
if ($entity !== null && $original === null) {
return array_merge($fields, $associations);
}
for ($i = 0, $n = count($fields); $i < $n; $i++) {
$field = $fields[$i];
$left = $metadata->getFieldValue($entity, $field);
$right = $metadata->getFieldValue($original, $field);
if ($left !== $right) {
$mutation_data[] = $field;
}
}
for ($i = 0, $n = count($associations); $i < $n; $i++) {
$association = $associations[$i];
$association_meta = $metadata->getAssociationMapping($association);
if ($association_meta['type'] === ClassMetadataInfo::ONE_TO_ONE && !$association_meta['isOwningSide']) {
continue;
}
$association_target_meta = $em->getClassMetadata($metadata->getAssociationTargetClass($association));
$association_value_left = $metadata->getFieldValue($entity, $association);
$association_value_right = $metadata->getFieldValue($original, $association);
if ($this->hasAssociationChanged($association_target_meta, $association_value_left, $association_value_right)) {
$mutation_data[] = $association;
}
}
return $mutation_data;
}
示例14: generateSelectClause
/**
* Generates the Select clause from this ResultSetMappingBuilder.
*
* Works only for all the entity results. The select parts for scalar
* expressions have to be written manually.
*
* @param array $tableAliases
*
* @return string
*/
public function generateSelectClause($tableAliases = array())
{
$sql = "";
foreach ($this->columnOwnerMap as $columnName => $dqlAlias) {
$tableAlias = isset($tableAliases[$dqlAlias]) ? $tableAliases[$dqlAlias] : $dqlAlias;
if ($sql) {
$sql .= ", ";
}
$sql .= $tableAlias . ".";
if (isset($this->fieldMappings[$columnName])) {
$class = $this->em->getClassMetadata($this->declaringClasses[$columnName]);
$sql .= $class->fieldMappings[$this->fieldMappings[$columnName]]['columnName'];
} else {
if (isset($this->metaMappings[$columnName])) {
$sql .= $this->metaMappings[$columnName];
} else {
if (isset($this->discriminatorColumn[$columnName])) {
$sql .= $this->discriminatorColumn[$columnName];
}
}
}
$sql .= " AS " . $columnName;
}
return $sql;
}
示例15: prepare
private function prepare($data)
{
$metaDataClass = $this->entityManager->getClassMetadata(get_class($data));
$assocFields = $metaDataClass->getAssociationMappings();
foreach ($assocFields as $assoc) {
$relatedEntities = $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data);
if ($relatedEntities instanceof Collection) {
if ($relatedEntities === $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data)) {
continue;
}
if ($relatedEntities instanceof PersistentCollection) {
// Unwrap so that foreach() does not initialize
$relatedEntities = $relatedEntities->unwrap();
}
foreach ($relatedEntities as $relatedEntity) {
$relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
$metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntity));
}
}
} else {
if ($relatedEntities !== null) {
$relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
$metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntities));
}
}
}
}
}