public function onUpdate(GenericEvent $event) { $entity = $event->getSubject(); if ($entity instanceof Routeable && $entity->getRoute() != null) { $this->updateRoute($entity->getRoute()); } }
public function onMeta(Event $event) { $page = $event->getSubject(); if (null !== ($redirect = $page->getMeta('redirect'))) { throw new PageRedirectedException($page->getName(), $redirect); } }
function it_send_password_reset_pin_mail($sender, GenericEvent $event, UserInterface $user) { $event->getSubject()->willReturn($user); $user->getEmail()->willReturn('*****@*****.**'); $sender->send('reset_password_pin', ['*****@*****.**'], Argument::any())->shouldBeCalled(); $this->sendResetPasswordPinEmail($event); }
function it_resolves_order_states(StateResolverInterface $stateResolver, GenericEvent $event, OrderInterface $order) { $event->getSubject()->willReturn($order); $stateResolver->resolveShippingState($order)->shouldBeCalled(); $stateResolver->resolvePaymentState($order)->shouldBeCalled(); $this->resolveOrderStates($event); }
function it_does_not_proceed_order_channel_if_it_is_already_set(GenericEvent $event, OrderInterface $order, ChannelInterface $channel) { $event->getSubject()->willReturn($order); $order->getChannel()->willReturn($channel); $order->setChannel($channel)->shouldNotBeCalled(); $this->processOrderChannel($event); }
function it_proccess_order_channel_successfully(GenericEvent $event, OrderInterface $order, ChannelContextInterface $channelContext, ChannelInterface $channel) { $event->getSubject()->shouldBeCalled()->willReturn($order); $channelContext->getChannel()->shouldBeCalled()->willReturn($channel); $order->setChannel($channel)->shouldBeCalled(); $this->processOrderChannel($event); }
/** * {@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 GenericEvent $event */ public function updateChannel(GenericEvent $event) { $channel = $event->getSubject(); if (!$channel instanceof ChannelInterface) { return; } $oldLocales = $this->repository->getDeletedLocalesForChannel($channel); $newLocales = $channel->getLocales(); $updatedLocales = []; foreach ($oldLocales as $locale) { $locale->removeChannel($channel); $updatedLocales[] = $locale; if (null !== $this->completeness) { $this->completeness->scheduleForChannelAndLocale($channel, $locale); } } foreach ($newLocales as $locale) { if (!$locale->hasChannel($channel)) { $locale->addChannel($channel); $updatedLocales[] = $locale; } } if (!empty($updatedLocales)) { $this->saver->saveAll($updatedLocales); } }
public function login(GenericEvent $event) { $user = $event->getSubject(); if ($user instanceof UserInterface) { $this->userCartMerger->merge($user); } }
/** * Starts a new phantomjs process in background * * @throws \Symfony\Component\Process\Exception\RuntimeException */ public function up() { $this->killAllRunning(); $this->process = new Process('phantomjs --webdriver=' . $this->port . ' ' . $this->options); $process = $this->process; $output = new GenericEvent(); $process->setTimeout(null); $process->start(function () use($process, $output) { $output->setArgument('output', $process->getIncrementalOutput()); }); $phantomjsOnline = false; $portScan = false; while (!$phantomjsOnline) { if ($output->hasArgument('output')) { $portScan = strpos($output->getArgument('output'), 'running on port ' . $this->port); } if ($portScan) { echo $output->getArgument('output'); } $phantomjsOnline = $process->isStarted() && $process->isRunning() && $portScan; if ($process->isTerminated()) { throw new RuntimeException('Phantomjs could not been started with webdriver on port ' . $this->port); } } }
public function onContent(Event $event) { $page = $event->getSubject(); foreach ($page->getDocument()->getElementsByTagName('img') as $image) { $url = parse_url($image->getAttribute('src')); if (isset($url['host'])) { continue; } if (isset($url['query'])) { parse_str($url['query'], $query); } $src = $this->urlGenerator->generate('image', ['path' => $url['path']]); if ('a' !== $image->parentNode->nodeName && (!isset($query['link']) || 'no' !== $query['link'])) { $a = $image->parentNode->insertBefore($page->getDocument()->createElement('a'), $image); $a->appendChild($image); $a->setAttribute('href', $src . (isset($query['link']) && 'direct' === $query['link'] ? '' : '?details')); } if (isset($query['link'])) { unset($query['link']); } if (!empty($query)) { $src .= '?' . http_build_query($query); } $image->setAttribute('src', $src); unset($query); } }
function it_does_not_update_password_if_customer_does_not_have_user(PasswordUpdaterInterface $passwordUpdater, GenericEvent $event, CustomerInterface $customer) { $event->getSubject()->willReturn($customer); $customer->getUser()->willReturn(null); $passwordUpdater->updatePassword(null)->shouldNotBeCalled(); $this->customerUpdateEvent($event); }
function it_does_not_set_locale_on_post_update_when_event_subject_is_different_from_current_user($translator, GenericEvent $event, UserInterface $user, RequestStack $requestStack, Request $request, LocaleInterface $locale) { $event->getSubject()->willReturn($user); $event->getArgument('current_user')->willReturn(null); $translator->setLocale('fr_FR')->shouldNotBeCalled(); $this->onPostUpdate($event); }
/** * Check if channels are linked to this tree * * @param GenericEvent $event * * @throws ConflictHttpException */ public function checkChannels(GenericEvent $event) { $tree = $event->getSubject(); if (count($tree->getChannels()) > 0) { throw new ConflictHttpException($this->translator->trans('flash.tree.not removable')); } }
/** * @param GenericEvent $event */ public function onApiCall(GenericEvent $event) { if (!$this->calls) { $this->calls = []; } $this->calls[] = $event->getSubject(); }
/** * Mark document's related job as 'started'. * * @param GenericEvent $event */ public function onTextmasterDocumentIncomplete(GenericEvent $event) { /** @var DocumentInterface $document */ $document = $event->getSubject(); $job = $this->jobManager->getFromDocument($document); $this->jobManager->start($job); }
public function initializeRequest(GenericEvent $event) { if (null === $this->request) { return; } $this->request->attributes->set('easyadmin', array('entity' => $entity = $event->getArgument('entity'), 'view' => $this->request->query->get('action', 'list'), 'item' => ($id = $this->request->query->get('id')) ? $this->findCurrentItem($entity, $id) : null)); }
function it_sets_customer_on_a_resource($customerContext, GenericEvent $event, CustomerAwareInterface $resource, CustomerInterface $customer) { $event->getSubject()->willReturn($resource); $customerContext->getCustomer()->willReturn($customer); $resource->setCustomer($customer)->shouldBeCalled(); $this->setCustomer($event); }
public function onSave(GenericEvent $event) { if (get_class($event->getSubject()) == $this->workflowClass) { //if it is a 'save' of the workflow entity check the workflow-status of the belonging types and save the formNodes to the real nodes $workflow = $event->getSubject(); //get the repository for the changed workflow $repositories = $this->getEntityRepository($workflow); if ($repositories != null) { //get all ressources without workflow-status $resources = array(); foreach ($repositories as $repository) { $currentResourcesEmpty = $repository->getEmptyWorkflowStatus(); //replace old workflowstatus with current workflowstatus $this->removeOldWorkflowStatus($repository, $workflow); $resources = array_merge($currentResourcesEmpty, $resources); } //check if there are some entries with workflow-status null if ($resources != null) { //set a workflow-status if the current workflow is active if ($workflow->getActive()) { $this->setWorkflowStatus($workflow, $resources); } } } $this->writeNodes($workflow, $repositories); $this->em->flush(); } }
/** * Update community ticker * * @param GenericEvent $event * @return void */ public function update(GenericEvent $event) { $params = $event->getArguments(); $user = array_key_exists('user', $params) ? $params['user'] : null; unset($params['user']); $this->getRepository()->save(new CommunityTickerEvent(), array('event' => $event->getName(), 'user' => $user, 'params' => $params)); }
public function onMetaParse(Event $event) { $page = $event->getSubject(); if (is_string($page->getMetas())) { $page->setMetas(Yaml::parse($page->getMetas())); } }
function it_does_nothing_if_review_already_has_author($customerContext, ReviewerInterface $existingAuthor, GenericEvent $event, ReviewInterface $review) { $event->getSubject()->willReturn($review); $review->getAuthor()->willReturn($existingAuthor); $customerContext->getCustomer()->shouldNotBeCalled(); $this->ensureReviewHasAuthor($event); }
function it_calls_taxation_processor_on_order(TaxationProcessorInterface $taxationProcessor, GenericEvent $event, OrderInterface $order) { $event->getSubject()->willReturn($order); $taxationProcessor->applyTaxes($order)->shouldBeCalled(); $order->calculateTotal()->shouldBeCalled(); $this->applyTaxes($event); }
public function preSave(GenericEvent $event) { $subject = $event->getSubject(); if ($subject instanceof Slugable) { $slug = $subject->getSlug(); if (is_array($slug)) { foreach ($slug as $locale => $value) { if (empty($value)) { $slug[$locale] = $this->slugify($this->getContext($subject, $locale)); } } $subject->setSlug($slug); } } if ($subject instanceof Routeable) { /** @var Route $route */ $route = $subject->getRoute(); if ($route instanceof Route) { $staticPrefixes = $route->getStaticPrefix(); if (is_array($staticPrefixes)) { foreach ($staticPrefixes as $locale => $value) { if (empty($value)) { $staticPrefixes[$locale] = sprintf('/%s/%s', $locale, $this->slugify($this->getContext($subject, $locale))); } } $route->setStaticPrefix($staticPrefixes); } } } }
function it_generates_order_number(NumberListener $listener, GenericEvent $event, OrderInterface $order) { $event->getSubject()->willReturn($order); $order->getNumber()->willReturn(null); $listener->enableEntity($order)->shouldBeCalled(); $this->generateOrderNumber($event); }
function it_adds_error_message_to_flashbag_when_coupon_is_not_eligible(GenericEvent $event, FlashBagInterface $flashBag, $session, $translator) { $event->getName()->willReturn(SyliusPromotionEvents::COUPON_NOT_ELIGIBLE); $translator->trans(Argument::any(), Argument::any(), 'flashes')->shouldBeCalled(); $flashBag->add('error', Argument::any())->shouldBeCalled(); $session->getBag('flashes')->shouldBeCalled()->willReturn($flashBag); $this->handleCouponPromotion($event); }
/** * Use generator to add a proper number to order. * * @param GenericEvent $event */ public function generateOrderNumber(GenericEvent $event) { $order = $event->getSubject(); if (null !== $order->getNumber()) { return; } $this->listener->enableEntity($order); }
/** * @param GenericEvent $event * * @return OrderInterface * * @throws UnexpectedTypeException */ protected function getOrder(GenericEvent $event) { $order = $event->getSubject(); if (!$order instanceof OrderInterface) { throw new UnexpectedTypeException($order, OrderInterface::class); } return $order; }
/** * @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 GenericEvent $event */ public function uploadTaxonImage(GenericEvent $event) { $subject = $event->getSubject(); Assert::isInstanceOf($subject, TaxonInterface::class); if ($subject->hasFile()) { $this->uploader->upload($subject); } }