/** * 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 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 * * @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 \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 { // 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()); } }
public function serialize(EventInterface $event) { if (!$event instanceof \JsonSerializable) { throw new \InvalidArgumentException(sprintf('Cannot serialize %s event.', $event->getName())); } return json_encode($event); }
/** * 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 { $this->getApplicationServer()->getSystemLogger()->info($event->getName()); } catch (\Exception $e) { $this->getApplicationServer()->getSystemLogger()->error($e->__toString()); } }
/** * 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); }
/** * 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 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()); } }
/** * 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 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()); } }
/** * 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()); // print a message with the old UID/EUID $applicationServer->getSystemLogger()->info("Running as " . posix_getuid() . "/" . posix_geteuid()); // extract the variables $uid = 0; extract(posix_getpwnam('root')); // switcht 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 " . posix_getuid() . "/" . posix_geteuid()); // @TODO Switch group also!!!! } catch (\Exception $e) { $applicationServer->getSystemLogger()->error($e->__toString()); } }