/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server and the naming directory instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); /** @var \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */ $namingDirectory = $applicationServer->getNamingDirectory(); // load the configuration filename $configurationFilename = $applicationServer->getConfigurationFilename(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // load the setup mode from the naming directory $setupMode = $namingDirectory->search('php:env/args/s'); $currentUser = $namingDirectory->search('php:env/currentUser'); // load the service instance and switch to the new setup mode /** @var \AppserverIo\Appserver\Core\Api\ContainerService $service */ $service = $applicationServer->newService('AppserverIo\\Appserver\\Core\\Api\\ContainerService'); $service->switchSetupMode($setupMode, $configurationFilename, $currentUser); } catch (NamingException $ne) { $applicationServer->getSystemLogger()->error('Please specify a setup mode, e. g. \'./server.php -s prod\''); } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param EventInterface $event * * @return void */ public function handle(EventInterface $event) { if (!$event instanceof SerializableEvent) { throw new \InvalidArgumentException(sprintf('Cannot serialize %s event.', $event->getName())); } $this->publisher->publish(json_encode($event->toArray()), $event->getName()); }
public function serialize(EventInterface $event) { if (!$event instanceof \JsonSerializable) { throw new \InvalidArgumentException(sprintf('Cannot serialize %s event.', $event->getName())); } return json_encode($event); }
/** * @param ElementInterface $element * * @return string */ public function handleTagImg(EventInterface $event, ElementInterface $element) { // Should mutate all images and stop propagation if (function_exists('cloudinary_url')) { $src = $element->getAttribute('src'); $width = $element->getAttribute('width'); $height = $element->getAttribute('height'); $sizes = $this->generateSizes(); $srcset = $this->generateSrcset($src); $urlConfig = ['width' => 400, 'height' => 225, 'crop' => 'limit', 'sign_url' => true, 'type' => 'fetch', 'effect' => 'sharpen']; if ($width < 100 || $height < 100) { $width = $urlConfig['width']; $height = $urlConfig['height']; } else { $urlConfig['width'] = $width; $urlConfig['height'] = $height; } // Create the responsive <amp-img /> tag $ampImg = $element->createWritableElement('amp-img'); $ampImg->setAttribute('src', cloudinary_url($src, $urlConfig)); $ampImg->setAttribute('width', $width); $ampImg->setAttribute('height', $height); $ampImg->setAttribute('sizes', $sizes); $ampImg->setAttribute('srcset', $srcset); $ampImg->setAttribute('layout', 'responsive'); $ampImg->setAttribute('alt', $element->getAttribute('alt')); $ampImg->setAttribute('attribution', $element->getAttribute('attribution')); $ampImg->setAttribute('class', 'amp-img'); $element->replaceWith($ampImg); $event->stopPropagation(); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // add the configured extractors to the internal array /** @var \AppserverIo\Appserver\Core\Api\Node\ExtractorNodeInterface $extractorNode */ foreach ($applicationServer->getSystemConfiguration()->getExtractors() as $extractorNode) { /** @var \AppserverIo\Appserver\Core\Extractors\ExtractorFactoryInterface $extractorFactory */ $extractorFactory = $extractorNode->getFactory(); // use the factory if available /** @var \AppserverIo\Appserver\Core\Interfaces\ConsoleInterface $console */ $extractor = $extractorFactory::factory($applicationServer, $extractorNode); // deploy the found application archives $extractor->deployWebapps(); // log that the extractor has successfully been initialized and executed $applicationServer->getSystemLogger()->debug(sprintf('Extractor %s successfully initialized and executed', $extractorNode->getName())); } } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // initialize the service to load the container configurations $deploymentService = $applicationServer->newService('AppserverIo\\Appserver\\Core\\Api\\DeploymentService'); $applicationServer->setSystemConfiguration($deploymentService->loadContainerInstances()); // and initialize a container thread for each container /** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode */ foreach ($applicationServer->getSystemConfiguration()->getContainers() as $containerNode) { /** @var \AppserverIo\Appserver\Core\Interfaces\ContainerFactoryInterface $containerFactory */ $containerFactory = $containerNode->getFactory(); // use the factory if available /** @var \AppserverIo\Appserver\Core\Interfaces\ContainerInterface $container */ $container = $containerFactory::factory($applicationServer, $containerNode); $container->start(); // wait until all servers has been bound to their ports and addresses while ($container->hasServersStarted() === false) { // sleep to avoid cpu load usleep(10000); } // register the container as service $applicationServer->bindService(ApplicationServerInterface::NETWORK, $container); } } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server and the naming directory instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); /** @var \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */ $namingDirectory = $applicationServer->getNamingDirectory(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // deploy the applications for all containers /** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode */ foreach ($applicationServer->getSystemConfiguration()->getContainers() as $containerNode) { // load the container instance to deploy the applications for /** @var \AppserverIo\Appserver\Core\Interfaces\ContainerInterface $container */ $container = $namingDirectory->search(sprintf('php:services/%s/%s', $applicationServer->runlevelToString(ApplicationServerInterface::NETWORK), $containerNode->getName())); // iterate over all applications and shut them down /** @var \AppserverIo\Psr\Application\ApplicationInterface $application */ foreach ($container->getApplications() as $application) { $application->stop(); } } } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { $this->getApplicationServer()->getSystemLogger()->info($event->getName()); } catch (\Exception $e) { $this->getApplicationServer()->getSystemLogger()->error($e->__toString()); } }
function it_skips_converting_non_youtube_object_tags(EventInterface $event, ElementInterface $element, ElementInterface $childElement) { $element->getChildren()->shouldBeCalled()->willReturn([$childElement]); $childElement->getAttribute('value')->shouldBeCalled()->willReturn('http://metube.com/embed/XGSy3_Czz8k'); $event->stopPropagation()->shouldNotBeCalled(); $element->createWritableElement('div', ['class' => 'youtube-container'])->shouldNotBeCalled(); $this->handleObject($event, $element); }
/** * Handle an event. * * @param EventInterface $event * * @return void */ public function handle(EventInterface $event) { if (!$event instanceof PlayerCreatedEvent) { return; } $applicationUser = $this->finder->find($event->getExternalReference()); $applicationUser->linkToPlayer($event->getGameId(), $event->getPlayerId()); $this->finder->save($applicationUser); }
/** * Handle an event. * * @param EventInterface $event * @param Context $context * * @return void */ public function handle(EventInterface $event, Context $context = null) { if (!$event instanceof GameResult) { return; } $this->logger->info(sprintf('Send message after "%s"', $event->getName())); $messageContext = $this->getMessageContext($context); $users = $this->getUsersList($event, $messageContext); $this->sendMessage($event, $users, $messageContext); }
/** * Check if slack is enabled, if so send the snapshot to the relevant * channel. * * @param EventInterface $event * @throws EndPointNotSetException */ public function handle(EventInterface $event) { if ($this->config['slack']['enabled']) { if (empty($this->config['slack']['endpoint'])) { throw new EndPointNotSetException("You must set the endpoint for your slack channel."); } $client = new Client($this->config['slack']['endpoint'], $this->config['slack']['settings']); $client->send($this->getMessage($event->getSnapshot())); } }
/** * @inheritDoc */ public function handle(EventInterface $event) { if ($event instanceof SecurityFailureEvent) { $fff = self::fff(); //! log self::dispatchEvent(new LogEvent(LoggerLevelEnum::ERROR(), LoggerTemplate::LOGGER_MESSAGE_SECURITY_FAILURE, ['security' => get_class($event->getRule()), 'pattern' => $fff->get('PATTERN')])); //! error self::dispatchEvent($event->getRule()->getErrorEvent()); } }
/** * @inheritDoc */ public function handle(EventInterface $event) { if ($event instanceof LogEvent) { //! get the default logger $logger = Utility::instance()->getLogger(); if (!is_null($logger)) { call_user_func_array([$logger, $event->getLevel()], [$event->getMessage(), $event->getContext()]); } } }
/** * @param EventInterface $event * @param ElementInterface $element * @param $tag */ public function handleBlockquote(EventInterface $event, ElementInterface $element, $tag) { $classAttr = explode(' ', $element->getAttribute('class')); if (in_array('twitter-tweet', $classAttr) && false !== ($twitterStatusId = $this->getStatusId($element))) { $container = $element->createWritableElement('div', ['class' => 'amp-twitter-container']); $container->appendChild($this->createAmpTwitterTag($element, $twitterStatusId)); $element->replaceWith($container); $event->stopPropagation(); } }
protected function handleCheckout(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)? checkout$/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: Not yet implemented. Sorry!', [$payload['user']]), $channel); log_message('info', 'Presence', sprintf('%s checked out.', $payload['user'])); }); }
protected function sendUptimeReport(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)? uptime$/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: My current uptime is %s.', [$payload['user'], $this->uptime->diffForHumans(new Carbon(), true)]), $channel); log_message('info', 'Uptime', sprintf('Uptime report posted to %s.', $channel->getId())); }); }
protected function handleMention(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)?/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: Noot! Noot!', [$payload['user']]), $channel); log_message('info', 'Interaction', sprintf('Replied to mention in %s.', $channel->getId())); }); }
protected function sendPingReport(EventInterface $event, Payload $payload) { if ($this->slack->shouldTrigger('/^<@{:pingu:}>(:)? ping$/', $payload) === false) { return; } $event->stopPropagation(); $this->slack->typing($payload['channel']); $this->slack->getChannelGroupOrDMByID($payload['channel'])->then(function (Channel $channel) use($payload) { $this->slack->send(vsprintf('<@%s>: My current ping towards Slack is %ums.', [$payload['user'], $this->ping]), $channel); log_message('info', 'Ping', sprintf('Ping report posted to %s.', $channel->getId())); }); }
public function handleInstagram(EventInterface $event, ElementInterface $element) { if ($this->convertToAmp($element) == false) { return; } $shortcode = $this->getEmbedShortcode($element); if ($shortcode == null) { return; } $attrs = ['layout' => "responsive", 'width' => 600, 'height' => 384, 'data-shortcode' => $shortcode]; $element->replaceWith($element->createWritableElement('amp-instagram', $attrs)); $event->stopPropagation(); }
public function handle(EventInterface $event) { $events = $this->implementedEvents(); if (empty($events)) { return; } if (!isset($events[$event->getName()])) { return; } $handler = $events[$event->getName()]; if (!method_exists($this, $handler)) { return; } return $this->{$handler}($event); }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * @param integer $runlevel The actual runlevel * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event, $runlevel = ApplicationServerInterface::NETWORK) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // initialize the service to load the container configurations /** @var \AppserverIo\Appserver\Core\Api\DeploymentService $deploymentService */ $deploymentService = $this->getDeploymentService(); $applicationServer->setSystemConfiguration($systemConfiguration = $deploymentService->loadContainerInstances()); // we also have to re-attach the system configuration to the initial context, because it's not a \Stackable /** @var \AppserverIo\Appserver\Application\Interfaces\ContextInterface */ $initialContext = $applicationServer->getInitialContext(); $initialContext->setSystemConfiguration($systemConfiguration); $applicationServer->setInitialContext($initialContext); // load the naming directory /** @var \AppserverIo\Appserver\Naming\NamingDirectory $namingDirectory */ $namingDirectory = $applicationServer->getNamingDirectory(); // initialize the environment variables $namingDirectory->bind('php:env/tmpDirectory', $deploymentService->getBaseDirectory(DirectoryKeys::TMP)); $namingDirectory->bind('php:env/baseDirectory', $deploymentService->getBaseDirectory()); $namingDirectory->bind('php:env/umask', $applicationServer->getSystemConfiguration()->getUmask()); $namingDirectory->bind('php:env/user', $applicationServer->getSystemConfiguration()->getUser()); $namingDirectory->bind('php:env/group', $applicationServer->getSystemConfiguration()->getGroup()); // and initialize a container thread for each container /** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode */ foreach ($applicationServer->getSystemConfiguration()->getContainers() as $containerNode) { // load the factory class name /** @var \AppserverIo\Appserver\Core\Interfaces\ContainerFactoryInterface $containerFactory */ $containerFactory = $containerNode->getFactory(); // use the factory to create a new container instance /** @var \AppserverIo\Appserver\Core\Interfaces\ContainerInterface $container */ $container = $containerFactory::factory($applicationServer, $containerNode, $runlevel); $container->start(); // wait until all servers has been bound to their ports and addresses while ($container->hasServersStarted() === false) { // sleep to avoid cpu load usleep(10000); } // register the container as service $applicationServer->bindService($runlevel, $container); } } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // load the service instance and switch the umask /** @var \AppserverIo\Appserver\Core\Api\DeploymentService $service */ $service = $applicationServer->newService('AppserverIo\\Appserver\\Core\\Api\\DeploymentService'); $service->initUmask($applicationServer->getSystemConfiguration()->getUmask()); } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // load the service instance and prepare the filesystem /** @var \AppserverIo\Appserver\Core\Api\ContainerService $service */ $service = $applicationServer->newService('AppserverIo\\Appserver\\Core\\Api\\ContainerService'); $service->prepareFileSystem(); } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // load the service instance and create the SSL file if not available /** @var \AppserverIo\Appserver\Core\Api\ContainerService $service */ $service = $applicationServer->newService('AppserverIo\\Appserver\\Core\\Api\\ContainerService'); $service->createSslCertificate(new \SplFileInfo($service->getConfDir(CreateSslCertificateListener::DEFAULT_CERTIFICATE_NAME))); } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
public function handleObject(EventInterface $event, ElementInterface $element) { $embedCode = false; /** @var ElementInterface $child */ foreach ($element->getChildren() as $child) { if (1 === preg_match('/youtube\\.com\\/(?:v|embed)\\/([a-zA-z0-9_-]+)/i', $child->getAttribute('value'), $match)) { $embedCode = $match[1]; } } if ($embedCode !== false) { $container = $element->createWritableElement('div', ['class' => 'youtube-container']); $container->appendChild($this->createAmpTag($element, $embedCode)); $element->replaceWith($container); $event->stopPropagation(); } }
/** * Handle an event. * * @param EventInterface $event * @param Context $context * * @return void */ public function handle(EventInterface $event, Context $context = null) { if (!$event instanceof UnableToCreateUserEvent) { return; } $this->logger->info('Send message', ['user' => $event->getUser()->getName(), 'type' => $event->getName()]); $messageContext = null; if ($context) { $messageContext = $this->messageFinder->findByReference($context->getValue()); } $message = $this->messageFactory->buildMessage([$event->getUser()], $event); if (!$message) { $this->logger->warning('Message could not be generated'); return; } $this->messageSender->send($message, $messageContext ? $messageContext->getSource() : null); }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // don't do anything under Windows if (FileSystem::getOsIdentifier() === 'WIN') { $applicationServer->getSystemLogger()->info('Don\'t switch UID to \'%s\' because OS is Windows'); return; } // initialize the variable for user/group $uid = 0; $gid = 0; // throw an exception if the POSIX extension is not available if (extension_loaded('posix') === false) { throw new \Exception('Can\'t switch user, because POSIX extension is not available'); } // print a message with the old UID/EUID $applicationServer->getSystemLogger()->info("Running as " . posix_getuid() . "/" . posix_geteuid()); // extract the user and group name as variables extract(posix_getgrnam($applicationServer->getSystemConfiguration()->getGroup())); extract(posix_getpwnam($applicationServer->getSystemConfiguration()->getUser())); // switch the effective GID to the passed group if (posix_setegid($gid) === false) { $applicationServer->getSystemLogger()->error(sprintf('Can\'t switch GID to \'%s\'', $gid)); } // print a message with the new GID/EGID $applicationServer->getSystemLogger()->info("Running as group" . posix_getgid() . "/" . posix_getegid()); // switch the effective UID to the passed user if (posix_seteuid($uid) === false) { $applicationServer->getSystemLogger()->error(sprintf('Can\'t switch UID to \'%s\'', $uid)); } // print a message with the new UID/EUID $applicationServer->getSystemLogger()->info("Running as user " . posix_getuid() . "/" . posix_geteuid()); } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server and the naming directory instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // add the configured extractors to the internal array /** @var \AppserverIo\Appserver\Core\Api\Node\ScannerNodeInterface $scannerNode */ foreach ($applicationServer->getSystemConfiguration()->getScanners() as $scannerNode) { // load the factory class name $factoryClass = $scannerNode->getFactory(); // invoke the visit method of the factory class /** @var \AppserverIo\Appserver\Core\Scanner\ScannerFactoryInterface $factory */ $factoryClass::visit($applicationServer, $scannerNode); } } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }
/** * Handle an event. * * @param \League\Event\EventInterface $event The triggering event * * @return void * @see \League\Event\ListenerInterface::handle() */ public function handle(EventInterface $event) { try { // load the application server instance /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */ $applicationServer = $this->getApplicationServer(); // write a log message that the event has been invoked $applicationServer->getSystemLogger()->info($event->getName()); // and initialize a console for each node found in the configuration /** @var \AppserverIo\Appserver\Core\Api\Node\ConsoleNodeInterface $consoleNode */ foreach ($applicationServer->getSystemConfiguration()->getConsoles() as $consoleNode) { /** @var \AppserverIo\Appserver\Core\Interfaces\ConsoleFactoryInterface $consoleFactory */ $consoleFactory = $consoleNode->getFactory(); // use the factory if available /** @var \AppserverIo\Appserver\Core\Interfaces\ConsoleInterface $console */ $console = $consoleFactory::factory($applicationServer, $consoleNode); // register the console as service $applicationServer->bindService(ApplicationServerInterface::ADMINISTRATION, $console); } } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }