本文整理汇总了PHP中Sylius\Component\Resource\Repository\RepositoryInterface::find方法的典型用法代码示例。如果您正苦于以下问题:PHP RepositoryInterface::find方法的具体用法?PHP RepositoryInterface::find怎么用?PHP RepositoryInterface::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sylius\Component\Resource\Repository\RepositoryInterface
的用法示例。
在下文中一共展示了RepositoryInterface::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preSubmit
/**
* @param FormEvent $event
*/
public function preSubmit(FormEvent $event)
{
$attributeValue = $event->getData();
Assert::keyExists($attributeValue, 'attribute', 'Cannot create an attribute value form on pre submit event without an "attribute" key in data.');
$form = $event->getForm();
$attribute = $this->attributeRepository->find($attributeValue['attribute']);
$this->addValueField($form, $attribute);
}
示例2: createForTaxonomy
/**
* {@inheritdoc}
*/
public function createForTaxonomy($taxonomyId)
{
if (null === ($taxonomy = $this->taxonomyRepository->find($taxonomyId))) {
throw new \InvalidArgumentException(sprintf('Taxonomy with id "%s" does not exist.', $taxonomyId));
}
$coupon = $this->factory->createNew();
$coupon->setTaxonomy($taxonomy);
return $coupon;
}
示例3: createForSubject
/**
* {@inheritdoc}
*/
public function createForSubject($subjectId)
{
if (null === ($subject = $this->subjectRepository->find($subjectId))) {
throw new \InvalidArgumentException(sprintf('Review subject with id "%s" does not exist.', $subjectId));
}
$review = $this->factory->createNew();
$review->setReviewSubject($subject);
return $review;
}
示例4: createForProduct
/**
* {@inheritdoc}
*/
public function createForProduct($productId)
{
if (null === ($product = $this->productRepository->find($productId))) {
throw new \InvalidArgumentException(sprintf('Product with id "%s" does not exist.', $productId));
}
$coupon = $this->factory->createNew();
$coupon->setProduct($product);
return $coupon;
}
示例5: createForProductWithId
/**
* {@inheritdoc}
*/
public function createForProductWithId($id)
{
$product = $this->productRepository->find($id);
if (null === $product) {
throw new \InvalidArgumentException(sprintf('Product with id "%s" does not exist.', $id));
}
$variant = $this->createNew();
$variant->setProduct($product);
return $variant;
}
示例6: reverseTransform
/**
* {@inheritdoc}
*/
public function reverseTransform($value)
{
if (empty($value)) {
return null;
}
if ('id' === $this->identifier) {
return $this->repository->find($value);
}
return $this->repository->findOneBy([$this->identifier => $value]);
}
示例7: preSubmit
/**
* @param FormEvent $event
*/
public function preSubmit(FormEvent $event)
{
$attributeValue = $event->getData();
if (!isset($attributeValue['value']) || !isset($attributeValue['attribute'])) {
throw new \InvalidArgumentException('Cannot create an attribute value form on pre submit event without "attribute" and "value" keys in data.');
}
$form = $event->getForm();
$attribute = $this->attributeRepository->find($attributeValue['attribute']);
$this->addValueField($form, $attribute);
}
示例8: preSubmit
/**
* @param FormEvent $event
*/
public function preSubmit(FormEvent $event)
{
$attributeValue = $event->getData();
$form = $event->getForm();
if (empty($attributeValue) || !isset($attributeValue['value'])) {
return;
}
$attribute = $this->attributeRepository->find($attributeValue['attribute']);
$type = $attribute->getType();
$storageType = $attribute->getStorageType();
$options = array('auto_initialize' => false);
$form->add($this->formFactory->createNamed('value', 'sylius_attribute_type_' . $type, $this->provideAttributeValue($storageType, $attributeValue['value']), $options));
}
示例9:
function it_creates_a_taxon_and_assigns_a_taxonomy_to_id(FactoryInterface $factory, RepositoryInterface $taxonomyRepository, TaxonomyInterface $taxonomy, TaxonInterface $taxon)
{
$factory->createNew()->willReturn($taxon);
$taxonomyRepository->find(13)->willReturn($taxonomy);
$taxon->setTaxonomy($taxonomy)->shouldBeCalled();
$this->createForTaxonomy(13)->shouldReturn($taxon);
}
示例10:
function it_creates_a_variant_and_assigns_a_product_to_id(FactoryInterface $factory, RepositoryInterface $productRepository, ProductInterface $product, VariantInterface $variant)
{
$factory->createNew()->willReturn($variant);
$productRepository->find(13)->willReturn($product);
$variant->setProduct($product)->shouldBeCalled();
$this->createForProduct(13)->shouldReturn($variant);
}
示例11: moveAfter
/**
* Moves resource directly behind the position of existing object with id $target
*
* @param RequestConfiguration $requestConfiguration
* @param MetadataInterface $metadataInterface
* @param $resource
* @param RepositoryInterface $repository
* @param int $target
*/
public function moveAfter(RequestConfiguration $requestConfiguration, MetadataInterface $metadataInterface, $resource, RepositoryInterface $repository, $target)
{
$property = $requestConfiguration->getSortablePosition();
$targetResource = $repository->find($target);
$accessor = PropertyAccess::createPropertyAccessor();
$strategy = $requestConfiguration->getSortingStrategy();
$resourceValue = $accessor->getValue($resource, $property);
$targetValue = $accessor->getValue($targetResource, $property);
if ($resourceValue === null || $targetValue === null || $resourceValue == $targetValue) {
// Errors in value consistency: recalculate all position values for this entity
$this->recalculateSortingProperty($property, $repository);
$resourceValue = $accessor->getValue($resource, $property);
$targetValue = $accessor->getValue($targetResource, $property);
}
// Adjust target position based on the resources position relative to the targets position
if (($strategy == self::STRATEGY_ASC_LAST || $strategy == self::STRATEGY_ASC_FIRST) && $resourceValue > $targetValue) {
// Resource is below target
// To get to position one below target, we don't need to move target, only get to position one below, which means to position + 1 in asc strategies.
$targetPosition = $targetValue + 1;
} elseif (($strategy == self::STRATEGY_DESC_LAST || $strategy == self::STRATEGY_DESC_FIRST) && $resourceValue < $targetValue) {
// Resource is below target
// To get to position one below target, we don't need to move target, only get to position one below, which means to position - 1 in desc strategies.
$targetPosition = $targetValue - 1;
} else {
// Resource is above target, we need to move target as well to get to the position one below
$targetPosition = $targetValue;
}
// Execute movement
$this->moveToPosition($resource, $targetPosition, $property, $strategy, $repository);
}
示例12:
function it_creates_a_review_with_subject_and_reviewer(FactoryInterface $factory, RepositoryInterface $subjectRepository, ReviewableInterface $subject, ReviewInterface $review, ReviewerInterface $reviewer)
{
$factory->createNew()->willReturn($review);
$subjectRepository->find(10)->willReturn($subject);
$review->setReviewSubject($subject)->shouldBeCalled();
$review->setAuthor($reviewer)->shouldBeCalled();
$this->createForSubjectWithReviewer(10, $reviewer);
}
示例13:
function it_resets_current_cart_identifier_in_storage_when_abandoning_cart(CartContextInterface $cartContext, RepositoryInterface $cartRepository, EventDispatcherInterface $eventDispatcher, CartInterface $cart)
{
$cartContext->getCurrentCartIdentifier()->willReturn(123);
$cartRepository->find(123)->willReturn($cart);
$cartContext->resetCurrentCartIdentifier()->shouldBeCalled();
$eventDispatcher->dispatch(SyliusCartEvents::CART_ABANDON, Argument::type(GenericEvent::class))->shouldBeCalled();
$this->abandonCart();
}
示例14: createItem
/**
* Create promotion item
*
* @param array $configuration
*
* @return OrderItemInterface
*/
protected function createItem(array $configuration)
{
$variant = $this->variantRepository->find($configuration['variant']);
$promotionItem = $this->itemRepository->createNew();
$promotionItem->setVariant($variant);
$promotionItem->setQuantity((int) $configuration['quantity']);
$promotionItem->setUnitPrice((int) $configuration['price']);
return $promotionItem;
}
示例15: resolve
public function resolve(CartItemInterface $item, $request)
{
$productId = $request->get('product');
$quantity = intval($request->get('quantity'));
if ($quantity < 1) {
throw new ItemResolvingException('Quantity must be 1 or higher');
}
// If no product id given, or product not found, we throw exception with nice message.
if (!$productId || !($product = $this->productRepository->find($productId))) {
throw new ItemResolvingException('Requested product was not found');
}
/** @var $product ProductInterface */
$item->setUnitPrice($product->getPrice());
/** @var $item OrderItem */
$item->setProduct($product);
$this->modifier->modify($item, $quantity);
// Everything went fine, return the item.
return $item;
}