本文整理汇总了PHP中Akeneo\Component\StorageUtils\Repository\IdentifiableObjectRepositoryInterface::getIdentifierProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP IdentifiableObjectRepositoryInterface::getIdentifierProperties方法的具体用法?PHP IdentifiableObjectRepositoryInterface::getIdentifierProperties怎么用?PHP IdentifiableObjectRepositoryInterface::getIdentifierProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Akeneo\Component\StorageUtils\Repository\IdentifiableObjectRepositoryInterface
的用法示例。
在下文中一共展示了IdentifiableObjectRepositoryInterface::getIdentifierProperties方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* {@inheritdoc}
*/
public function transform($model)
{
if (null === $model) {
return null;
}
if (count($this->repository->getIdentifierProperties()) > 1) {
throw new \InvalidArgumentException('Cannot transform object with multiple identifiers');
}
$identifierProperty = $this->repository->getIdentifierProperties()[0];
$propertyAccessor = PropertyAccess::createPropertyAccessor();
if ($this->multiple) {
if (!is_array($model)) {
throw new UnexpectedTypeException($model, 'array');
}
$identifiers = [];
foreach ($model as $object) {
$identifiers[] = $propertyAccessor->getValue($object, $identifierProperty);
}
return $identifiers;
}
if (!is_object($model)) {
throw new UnexpectedTypeException($model, 'object');
}
return $propertyAccessor->getValue($model, $identifierProperty);
}
示例2: let
function let(IdentifiableObjectRepositoryInterface $repository, \stdClass $entity)
{
$entity->code = 'foo';
$repository->getIdentifierProperties()->willReturn(['code']);
$repository->findOneByIdentifier('foo')->willReturn($entity);
$this->beConstructedWith($repository, ['multiple' => false]);
}
示例3: sort
/**
* {@inheritdoc}
*/
public function sort(array $columns, array $context = [])
{
$identifier = $this->productRepository->getIdentifierProperties()[0];
if (isset($context['filters']['structure']['attributes']) && !empty($context['filters']['structure']['attributes'])) {
$rawColumns = array_merge([$identifier], $this->firstDefaultColumns, array_map(function ($associationType) {
return $associationType->getCode();
}, $this->associationTypeRepository->findAll()), $context['filters']['structure']['attributes']);
$sortedColumns = [];
foreach ($rawColumns as $columnCode) {
$sortedColumns = array_merge($sortedColumns, array_filter($columns, function ($columnCandidate) use($columnCode) {
return 0 !== preg_match(sprintf('/^%s(-.*)*/', $columnCode), $columnCandidate);
}));
}
return $sortedColumns;
}
array_unshift($this->firstDefaultColumns, $identifier);
return parent::sort($columns);
}
示例4: findObject
/**
* Find an object according to its identifiers from a repository.
*
* @param IdentifiableObjectRepositoryInterface $repository the repository to search inside
* @param array $data the data that is currently processed
*
* @throws MissingIdentifierException in case the processed data do not allow to retrieve an object
* by its identifiers properly
*
* @return object|null
*/
protected function findObject(IdentifiableObjectRepositoryInterface $repository, array $data)
{
$properties = $repository->getIdentifierProperties();
$references = [];
foreach ($properties as $property) {
if (!isset($data[$property])) {
throw new MissingIdentifierException();
}
$references[] = $data[$property];
}
return $repository->findOneByIdentifier(implode('.', $references));
}
示例5: findObject
/**
* Find an object according to its identifiers from a repository.
*
* @param IdentifiableObjectRepositoryInterface $repository the repository to search inside
* @param array $data the data that is currently processed
*
* @throws MissingIdentifierException in case the processed data do not allow to retrieve an object
* by its identifiers properly
*
* @return object|null
*/
protected function findObject(IdentifiableObjectRepositoryInterface $repository, array $data)
{
$properties = $repository->getIdentifierProperties();
$references = [];
foreach ($properties as $property) {
if (!isset($data[$property])) {
throw new MissingIdentifierException(sprintf('Missing identifier column "%s". Columns found: %s.', $property, implode(', ', array_keys($data))));
}
$references[] = $data[$property];
}
return $repository->findOneByIdentifier(implode('.', $references));
}
示例6: getIdentifier
/**
* @param array $convertedItem
*
* @return string
*/
protected function getIdentifier(array $convertedItem)
{
$identifierProperty = $this->repository->getIdentifierProperties();
return $convertedItem[$identifierProperty[0]];
}
示例7: sort
/**
* {@inheritdoc}
*/
public function sort(array $columns)
{
$identifier = $this->productRepository->getIdentifierProperties()[0];
array_unshift($this->firstDefaultColumns, $identifier);
return parent::sort($columns);
}
示例8: getIdentifier
/**
* @param array $item
*
* @return string
*/
protected function getIdentifier(array $item)
{
$identifierProperty = $this->repository->getIdentifierProperties();
return $item[$identifierProperty[0]][0]['data'];
}