本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::getIdentifierFieldNames方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getIdentifierFieldNames方法的具体用法?PHP ClassMetadata::getIdentifierFieldNames怎么用?PHP ClassMetadata::getIdentifierFieldNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getIdentifierFieldNames方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
/**
* Finds an object by its primary key / identifier.
*
* @param mixed $id The identifier.
*
* @return object The object.
*/
public function find($id)
{
if (!is_array($id)) {
$idFields = $this->classMetadata->getIdentifierFieldNames();
$idField = reset($idFields);
$id = [$idField => $id];
}
return $this->persister->loadById($id);
}
示例2: __construct
/**
* Creates a new entity choice list.
*
* @param ObjectManager $manager An EntityManager instance
* @param string $class The class name
* @param string $labelPath The property path used for the label
* @param EntityLoaderInterface $entityLoader An optional query builder
* @param array $entities An array of choices
* @param string $groupPath A property path pointing to the property used
* to group the choices. Only allowed if
* the choices are given as flat array.
*/
public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, $groupPath = null)
{
$this->em = $manager;
$this->entityLoader = $entityLoader;
$this->classMetadata = $manager->getClassMetadata($class);
$this->class = $this->classMetadata->getName();
$this->identifier = $this->classMetadata->getIdentifierFieldNames();
$this->loaded = is_array($entities) || $entities instanceof \Traversable;
if (!$this->loaded) {
// Make sure the constraints of the parent constructor are
// fulfilled
$entities = array();
}
parent::__construct($entities, $labelPath, array(), $groupPath);
}
示例3: __construct
/**
* Creates a new entity choice list.
*
* @param ObjectManager $manager An EntityManager instance
* @param string $class The class name
* @param string $labelPath The property path used for the label
* @param EntityLoaderInterface $entityLoader An optional query builder
* @param array $entities An array of choices
* @param string $groupPath A property path pointing to the property used
* to group the choices. Only allowed if
* the choices are given as flat array.
*/
public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, $groupPath = null)
{
$this->em = $manager;
$this->entityLoader = $entityLoader;
$this->classMetadata = $manager->getClassMetadata($class);
$this->class = $this->classMetadata->getName();
$this->loaded = is_array($entities) || $entities instanceof \Traversable;
$identifier = $this->classMetadata->getIdentifierFieldNames();
if (1 === count($identifier)) {
$this->idField = $identifier[0];
$this->idAsValue = true;
if ('integer' === $this->classMetadata->getTypeOfField($this->idField)) {
$this->idAsIndex = true;
}
}
if (!$this->loaded) {
// Make sure the constraints of the parent constructor are
// fulfilled
$entities = array();
}
if (version_compare(Kernel::VERSION, '2.1') <= 0) {
$this->labelPath = $labelPath ? new DepPropertyPath($labelPath) : null;
$this->groupPath = $groupPath ? new DepPropertyPath($groupPath) : null;
} else {
$this->labelPath = $labelPath ? new PropertyPath($labelPath) : null;
$this->groupPath = $groupPath ? new PropertyPath($groupPath) : null;
}
parent::__construct($entities, array(), array());
}
示例4: getDefaultOrderBy
/**
* Get default order by.
*
* @return array|null
*/
protected function getDefaultOrderBy()
{
$ids = $this->metadata->getIdentifierFieldNames();
$orderBy = $ids ? [] : null;
foreach ($ids as $pk) {
$orderBy[$pk] = 'ASC';
}
return $orderBy;
}
示例5: __construct
public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
{
$ids = $classMetadata->getIdentifierFieldNames();
$idType = $classMetadata->getTypeOfField(current($ids));
$this->om = $om;
$this->classMetadata = $classMetadata;
$this->singleId = 1 === count($ids);
$this->intId = $this->singleId && in_array($idType, array('integer', 'smallint', 'bigint'));
$this->idField = current($ids);
}
示例6: tryConvertArrayToObject
/**
* This function tries, given an array of data, to convert it to an object if the given array contains
* an identifier for the object. This is useful in a context of updating existing entities, without ugly
* tricks like setting manually the existing id directly into the entity
*
* @param array $data
* @param object $object
* @return object
*/
protected function tryConvertArrayToObject($data, $object)
{
$identifierNames = $this->metadata->getIdentifierFieldNames($object);
$identifierValues = array();
if (empty($identifierNames)) {
return $object;
}
foreach ($identifierNames as $identifierName) {
if (!isset($data[$identifierName]) || empty($data[$identifierName])) {
return $object;
}
$identifierValues[$identifierName] = $data[$identifierName];
}
return $this->find(get_class($object), $identifierValues);
}
示例7: __construct
public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
{
$ids = $classMetadata->getIdentifierFieldNames();
$idType = $classMetadata->getTypeOfField(current($ids));
$this->om = $om;
$this->classMetadata = $classMetadata;
$this->singleId = 1 === count($ids);
$this->intId = $this->singleId && in_array($idType, array('integer', 'smallint', 'bigint'));
$this->idField = current($ids);
// single field association are resolved, since the schema column could be an int
if ($this->singleId && $classMetadata->hasAssociation($this->idField)) {
$this->associationIdReader = new self($om, $om->getClassMetadata($classMetadata->getAssociationTargetClass($this->idField)));
$this->singleId = $this->associationIdReader->isSingleId();
$this->intId = $this->associationIdReader->isIntId();
}
}
示例8: __construct
/**
* Constructor.
*
* @param ObjectManager $manager An EntityManager instance
* @param string $class The class name
* @param string $property The property name
* @param EntityLoaderInterface $entityLoader An optional query builder
* @param array|\Closure $choices An array of choices or a function returning an array
* @param string $groupBy
*/
public function __construct(ObjectManager $manager, $class, $property = null, EntityLoaderInterface $entityLoader = null, $choices = null, $groupBy = null)
{
$this->em = $manager;
$this->class = $class;
$this->entityLoader = $entityLoader;
$this->classMetadata = $manager->getClassMetadata($class);
$this->identifier = $this->classMetadata->getIdentifierFieldNames();
$this->groupBy = $groupBy;
// The property option defines, which property (path) is used for
// displaying entities as strings
if ($property) {
$this->propertyPath = new PropertyPath($property);
} elseif (!method_exists($this->class, '__toString')) {
// Otherwise expect a __toString() method in the entity
throw new FormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).');
}
if (!is_array($choices) && !$choices instanceof \Closure && !is_null($choices)) {
throw new UnexpectedTypeException($choices, 'array or \\Closure or null');
}
$this->choices = $choices;
}
示例9: __construct
/**
* Creates a new entity choice list.
*
* @param ObjectManager $manager An EntityManager instance
* @param string $class The class name
* @param string $labelPath The property path used for the label
* @param EntityLoaderInterface $entityLoader An optional query builder
* @param array $entities An array of choices
* @param array $preferredEntities An array of preferred choices
* @param string $groupPath A property path pointing to the property used
* to group the choices. Only allowed if
* the choices are given as flat array.
* @param PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
*/
public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, array $preferredEntities = array(), $groupPath = null, PropertyAccessorInterface $propertyAccessor = null)
{
$this->em = $manager;
$this->entityLoader = $entityLoader;
$this->classMetadata = $manager->getClassMetadata($class);
$this->class = $this->classMetadata->getName();
$this->loaded = is_array($entities) || $entities instanceof \Traversable;
$this->preferredEntities = $preferredEntities;
$identifier = $this->classMetadata->getIdentifierFieldNames();
if (1 === count($identifier)) {
$this->idField = $identifier[0];
$this->idAsValue = true;
if (in_array($this->classMetadata->getTypeOfField($this->idField), array('integer', 'smallint', 'bigint'))) {
$this->idAsIndex = true;
}
}
if (!$this->loaded) {
// Make sure the constraints of the parent constructor are
// fulfilled
$entities = array();
}
parent::__construct($entities, $labelPath, $preferredEntities, $groupPath, null, $propertyAccessor);
}
示例10: getIdentifierInfoForClass
/**
* Get identifier information for a class.
*
* @param ClassMetadata $classMetadata The entity metadata
*
* @return array Return an array with idAsIndex, idAsValue and identifier
*/
private function getIdentifierInfoForClass(ClassMetadata $classMetadata)
{
$identifier = null;
$idAsIndex = false;
$idAsValue = false;
$identifiers = $classMetadata->getIdentifierFieldNames();
if (1 === count($identifiers)) {
$identifier = $identifiers[0];
if (!$classMetadata->hasAssociation($identifier)) {
$idAsValue = true;
if (in_array($classMetadata->getTypeOfField($identifier), array('integer', 'smallint', 'bigint'))) {
$idAsIndex = true;
}
}
}
return array($idAsIndex, $idAsValue, $identifier);
}