isInstanceOf() публичный статический Метод

public static isInstanceOf ( $value, $class, $message = '' )
 /**
  * {@inheritdoc}
  */
 public function onCheckoutComplete(GenericEvent $event)
 {
     /** @var OrderInterface $order */
     $order = $event->getSubject();
     Assert::isInstanceOf($order, OrderInterface::class);
     $this->session->set('sylius_order_id', $order->getId());
 }
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     /** @var ProductInterface $product */
     $product = $event->getData();
     Assert::isInstanceOf($product, ProductInterface::class);
     $this->generator->generate($product);
 }
 /**
  * {@inheritdoc}
  */
 public function supports(OrderInterface $order, ZoneInterface $zone)
 {
     $channel = $order->getChannel();
     /** @var ChannelInterface $channel */
     Assert::isInstanceOf($channel, ChannelInterface::class);
     return $channel->getTaxCalculationStrategy() === $this->type;
 }
Пример #4
0
 /**
  * @param GenericEvent $event
  */
 public function uploadTaxonImage(GenericEvent $event)
 {
     $subject = $event->getSubject();
     Assert::isInstanceOf($subject, TaxonInterface::class);
     if ($subject->hasFile()) {
         $this->uploader->upload($subject);
     }
 }
Пример #5
0
 /**
  * @param GenericEvent $event
  */
 public function sendVerificationEmail(GenericEvent $event)
 {
     $customer = $event->getSubject();
     Assert::isInstanceOf($customer, CustomerInterface::class);
     $user = $customer->getUser();
     Assert::notNull($user);
     $this->handleUserVerificationToken($user);
 }
 /**
  * @param int $id
  */
 private function selectElementFromAttributesDropdown($id)
 {
     /** @var Selenium2Driver $driver */
     $driver = $this->getDriver();
     Assert::isInstanceOf($driver, Selenium2Driver::class);
     $driver->executeScript('$(\'[name="sylius_product_attribute_choice"]\').dropdown(\'show\');');
     $driver->executeScript(sprintf('$(\'[name="sylius_product_attribute_choice"]\').dropdown(\'set selected\', %s);', $id));
 }
 /**
  * {@inheritdoc}
  */
 public function transform($value)
 {
     if (null === $value) {
         return null;
     }
     Assert::isInstanceOf($value, $this->repository->getClassName());
     return PropertyAccess::createPropertyAccessor()->getValue($value, $this->identifier);
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function isEligible(PromotionSubjectInterface $subject, array $configuration)
 {
     Assert::isInstanceOf($subject, OrderInterface::class);
     $channelCode = $subject->getChannel()->getCode();
     if (!isset($configuration[$channelCode])) {
         return false;
     }
     return $this->itemTotalRuleChecker->isEligible($subject, $configuration[$channelCode]);
 }
 /**
  * {@inheritdoc}
  */
 public function process(OrderInterface $order)
 {
     /** @var CoreOrderInterface $order */
     Assert::isInstanceOf($order, CoreOrderInterface::class);
     if (OrderInterface::STATE_CANCELLED === $order->getState()) {
         return;
     }
     $this->exchangeRateUpdater->update($order);
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 public function render(Field $field, $data, array $options)
 {
     $value = $this->dataExtractor->get($field, $data);
     if (null === $value) {
         return null;
     }
     Assert::isInstanceOf($value, \DateTime::class);
     return $value->format($options['format']);
 }
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (null === $value) {
         return null;
     }
     $class = $this->repository->getClassName();
     Assert::isInstanceOf($value, $class);
     $accessor = PropertyAccess::createPropertyAccessor();
     return $accessor->getValue($value, $this->identifier);
 }
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     /** @var ProductInterface $product */
     $product = $event->getData();
     Assert::isInstanceOf($product, ProductInterface::class);
     $form = $event->getForm();
     /** Options should be disabled for configurable product if it has at least one defined variant */
     $disableOptions = null !== $product->getFirstVariant() && false === $product->hasVariants();
     $form->add('options', 'sylius_product_option_choice', ['required' => false, 'disabled' => $disableOptions, 'multiple' => true, 'label' => 'sylius.form.product.options']);
 }
Пример #13
0
 /**
  * @param GenericEvent $event
  *
  * @throws \InvalidArgumentException
  */
 public function deleteUser(GenericEvent $event)
 {
     $user = $event->getSubject();
     Assert::isInstanceOf($user, UserInterface::class);
     $token = $this->tokenStorage->getToken();
     if (null !== $token && ($loggedUser = $token->getUser()) && $loggedUser->getId() === $user->getId()) {
         $event->stopPropagation();
         $this->session->getBag('flashes')->add('error', 'Cannot remove currently logged in user.');
     }
 }
Пример #14
0
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     /** @var ProductInterface $product */
     $product = $event->getData();
     Assert::isInstanceOf($product, ProductInterface::class);
     if ($product->isSimple()) {
         $form = $event->getForm();
         $form->add('variant', 'sylius_product_variant', ['property_path' => 'variants[0]']);
         $form->remove('options');
     }
 }
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $form = $event->getForm();
     /** @var ReviewInterface $review */
     $review = $event->getData();
     $author = $form->getConfig()->getOption('author');
     Assert::isInstanceOf($review, ReviewInterface::class);
     if (null === $author && null === $review->getAuthor()) {
         $form->add('author', 'sylius_customer_guest');
     }
 }
 /**
  * @param AddToCartCommandInterface $addCartItemCommand
  *
  * {@inheritDoc}
  */
 public function validate($addCartItemCommand, Constraint $constraint)
 {
     Assert::isInstanceOf($addCartItemCommand, AddToCartCommandInterface::class);
     Assert::isInstanceOf($constraint, CartItemAvailability::class);
     /** @var OrderItemInterface $cartItem */
     $cartItem = $addCartItemCommand->getCartItem();
     $isStockSufficient = $this->availabilityChecker->isStockSufficient($cartItem->getVariant(), $cartItem->getQuantity() + $this->getExistingCartItemQuantityFromCart($addCartItemCommand->getCart(), $cartItem));
     if (!$isStockSufficient) {
         $this->context->addViolation($constraint->message, ['%itemName%' => $cartItem->getVariant()->getInventoryName()]);
     }
 }
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $form = $event->getForm();
     /** @var CustomerAwareInterface $subject */
     $resource = $event->getData();
     $customer = $form->getConfig()->getOption($this->field);
     Assert::isInstanceOf($resource, CustomerAwareInterface::class);
     if (null === $customer && null === $resource->getCustomer()) {
         $form->add($this->field, 'sylius_customer_guest');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($currency, Constraint $constraint)
 {
     Assert::isInstanceOf($currency, CurrencyInterface::class);
     Assert::isInstanceOf($constraint, CannotDisableCurrency::class);
     if ($currency->getCode() !== $this->baseCurrency) {
         return;
     }
     if ($currency->isEnabled()) {
         return;
     }
     $this->context->addViolation($constraint->message);
 }
Пример #19
0
 /**
  * @param FormEvent $event
  */
 public function submit(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $form->get('createUser')->getViewData()) {
         Assert::isInstanceOf($data, UserAwareInterface::class);
         $data->setUser(null);
         $event->setData($data);
         $form->remove('user');
         $form->add('user', $this->entryType, ['constraints' => [new Valid()]]);
     }
 }
Пример #20
0
 /**
  * {@inheritdoc}
  */
 public function process(BaseOrderInterface $order)
 {
     /** @var OrderInterface $order */
     Assert::isInstanceOf($order, OrderInterface::class);
     $channel = $order->getChannel();
     foreach ($order->getItems() as $item) {
         if ($item->isImmutable()) {
             continue;
         }
         $item->setUnitPrice($this->productVariantPriceCalculator->calculate($item->getVariant(), ['channel' => $channel]));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function aggregate(array $adjustments)
 {
     $aggregatedAdjustments = [];
     foreach ($adjustments as $adjustment) {
         Assert::isInstanceOf($adjustment, AdjustmentInterface::class);
         if (!isset($aggregatedAdjustments[$adjustment->getLabel()])) {
             $aggregatedAdjustments[$adjustment->getLabel()] = 0;
         }
         $aggregatedAdjustments[$adjustment->getLabel()] += $adjustment->getAmount();
     }
     return $aggregatedAdjustments;
 }
 /**
  * {@inheritdoc}
  */
 public function getDefaultShippingMethod(ShipmentInterface $shipment)
 {
     /** @var CoreShipmentInterface $shipment */
     Assert::isInstanceOf($shipment, CoreShipmentInterface::class);
     /** @var ChannelInterface $channel */
     $channel = $shipment->getOrder()->getChannel();
     $shippingMethods = $this->shippingMethodRepository->findEnabledForChannel($channel);
     if (empty($shippingMethods)) {
         throw new UnresolvedDefaultShippingMethodException();
     }
     return $shippingMethods[0];
 }
Пример #23
0
 /**
  * {@inheritdoc}
  */
 public function selectMainTaxon(TaxonInterface $taxon)
 {
     $this->openTaxonBookmarks();
     Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class);
     $this->getDriver()->executeScript(sprintf('$(\'input.search\').val(\'%s\')', $taxon->getName()));
     $this->getElement('search')->click();
     $this->getElement('search')->waitFor(10, function () {
         return $this->hasElement('search_item_selected');
     });
     $itemSelected = $this->getElement('search_item_selected');
     $itemSelected->click();
 }
Пример #24
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($options) {
         $form = $event->getForm();
         $review = $event->getData();
         Assert::isInstanceOf($review, ReviewInterface::class);
         if (null === $review->getAuthor()) {
             $form->add('author', CustomerGuestType::class, ['constraints' => [new Valid()]]);
         }
     });
 }
Пример #25
0
 /**
  * {@inheritdoc}
  *
  * @param mixed $value
  * @param Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value) {
         return;
     }
     Assert::isInstanceOf($value, PromotionInterface::class);
     if (null === $value->getStartsAt() || null === $value->getEndsAt()) {
         return;
     }
     if ($value->getStartsAt()->getTimestamp() > $value->getEndsAt()->getTimestamp()) {
         $this->context->buildViolation($constraint->message)->atPath('endsAt')->addViolation();
     }
 }
Пример #26
0
 /**
  * {@inheritdoc}
  */
 public function validate($productVariant, Constraint $constraint)
 {
     Assert::isInstanceOf($constraint, HasAllPricesDefined::class);
     $channels = $productVariant->getProduct()->getChannels();
     foreach ($channels as $channel) {
         /** @var ChannelPricingInterface $channelPricing */
         $channelPricing = $productVariant->getChannelPricingForChannel($channel);
         if (null === $channelPricing || null === $channelPricing->getPrice()) {
             $this->context->buildViolation($constraint->message)->atPath('channelPricings')->addViolation();
             return;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($instruction, Constraint $constraint)
 {
     if (null === $instruction->getCodeLength() || null === $instruction->getAmount()) {
         return;
     }
     /** @var PromotionCouponGeneratorInstructionInterface $value */
     Assert::isInstanceOf($instruction, PromotionCouponGeneratorInstructionInterface::class);
     /** @var CouponPossibleGenerationAmount $constraint */
     Assert::isInstanceOf($constraint, CouponPossibleGenerationAmount::class);
     if (!$this->generationPolicy->isGenerationPossible($instruction)) {
         $this->context->addViolation($constraint->message, array('%expectedAmount%' => $instruction->getAmount(), '%codeLength%' => $instruction->getCodeLength(), '%possibleAmount%' => $this->generationPolicy->getPossibleGenerationAmount($instruction)));
     }
 }
Пример #28
0
 /**
  * @param FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     $data = $event->getData();
     $normData = $event->getForm()->getNormData();
     if (!isset($data['user'])) {
         $this->removeUserField($event);
         return;
     }
     Assert::isInstanceOf($normData, UserAwareInterface::class);
     if ($this->isUserDataEmpty($data) && null === $normData->getUser()) {
         unset($data['user']);
         $event->setData($data);
         $this->removeUserField($event);
     }
 }
Пример #29
0
 /**
  * @param array $configuration
  * @param array $context
  *
  * @return int|null
  */
 private function getPriceForConfigurationAndContext(array $configuration, array $context)
 {
     if (!array_key_exists($this->getParameterName(), $context)) {
         return null;
     }
     $price = null;
     foreach ($context[$this->getParameterName()] as $object) {
         Assert::isInstanceOf($object, $this->getClassName());
         $id = $object->getId();
         if (array_key_exists($id, $configuration) && (null === $price || $configuration[$id] < $price)) {
             $price = (int) round($configuration[$id]);
         }
     }
     return $price;
 }
Пример #30
0
 /**
  * {@inheritdoc}
  */
 public function process(BaseOrderInterface $order)
 {
     /** @var OrderInterface $order */
     Assert::isInstanceOf($order, OrderInterface::class);
     if (OrderInterface::STATE_CANCELLED === $order->getState()) {
         return;
     }
     $newPayment = $order->getLastNewPayment();
     if (null !== $newPayment) {
         $newPayment->setCurrencyCode($order->getCurrencyCode());
         $newPayment->setAmount($order->getTotal());
         return;
     }
     $this->createNewPayment($order);
 }