/** * Checks if the passed value is valid. * * @param string $value The value that should be validated * @param IsAvailable|Constraint $constraint The constraint for the validation */ public function validate($value, Constraint $constraint) { $available = $this->repository->getAvailability($value); if (!$available) { $this->context->buildViolation($constraint->message)->addViolation(); } }
public function onProductSave(ProductSavedEvent $event) { $product = $event->getProduct(); $this->repository->saveAvailability($product->getId()->getValue(), $product->isAvailable()); if ($this->persister->handlesObject($product)) { $this->persister->insertOne($product); } }
/** * @inheritDoc */ public function collect() : \Iterator { $generator = function () { foreach ($this->repository->findAllIds() as $id) { foreach ($this->locales as $locale) { (yield $this->router->generate('product', ['id' => $id, '_locale' => $locale], RouterInterface::ABSOLUTE_URL)); } } }; return $generator(); }
/** * Do the initialization logic * * @return void */ protected function doInitialize() { $collection = $this->collection; $ids = $collection->getKeys(); $products = $this->repository->findByIds($ids); $this->collection = new ArrayCollection(); foreach ($products as $product) { $lineItem = LineItemView::create($product, $collection->get($product->getId())); $this->collection->set($product->getId(), $lineItem); } }
/** * @inheritDoc */ public function findAllIds() { return $this->repository->findAllIds(); }
public function getProductAvailabilityById(GetProductAvailabilityByIdQuery $query) { $result = $this->viewRepository->getAvailability($query->getId()); $query->setResult($result); }