コード例 #1
0
ファイル: IssueCacheListener.php プロジェクト: av4tar/sheti
 public function onIssueGetPost(EventInterface $e)
 {
     $this->log->debug('ISSUES_GET.post - store in cache');
     $config = $e->getParams();
     $key = 'issues-' . $config['account-name'] . '-' . $config['repo'] . '-' . implode('-', $config['issue-filters']);
     $this->cache->setItem($key, $config['issues']);
 }
コード例 #2
0
ファイル: Module.php プロジェクト: socialog/socialog
 /**
  * {@inheritDoc}
  */
 public function onBootstrap(EventInterface $e)
 {
     $app = $e->getApplication();
     $sm = $app->getServiceManager();
     $config = $app->getConfig();
     // Set configuration options
     if ($phpSettings = $config['php_ini']) {
         foreach ($phpSettings as $key => $value) {
             ini_set($key, $value);
         }
     }
     $sharedEventManager = $sm->get('SharedEventManager');
     // Hook into comments
     $sharedEventManager->attach('theme', 'post.post', function ($e) use($sm) {
         $viewRenderer = $sm->get('ViewRenderer');
         return $viewRenderer->partial('socialog/comment/post', $e->getParams());
     });
     // Hook into comments
     $sharedEventManager->attach('view', 'navigation.render', function ($e) use($sm) {
         /* @var $pageMapper \Socialog\Mapper\PageMapper */
         $pageMapper = $sm->get('socialog_page_mapper');
         $result = "";
         foreach ($pageMapper->findAllPages() as $page) {
             $result .= new Theme\Menuitem($page->getTitle(), $e->getTarget()->url('socialog-page', array('id' => $page->getId())));
         }
         return $result;
     });
 }
コード例 #3
0
 /**
  * Actually do the logging.
  *
  * @param EventInterface $event
  */
 public function log(EventInterface $event)
 {
     $params = $event->getParams();
     $method = '?';
     $exception = isset($params['exception']) ? $params['exception'] : '';
     $sql = isset($params['sql']) ? $params['sql'] : array();
     $this->logger->critical(get_class($event->getTarget()) . "::{$method} - {$exception}", $sql);
 }
コード例 #4
0
ファイル: ListenerAggregate.php プロジェクト: im286er/ent
 private function setKey(EventInterface $e)
 {
     $params = $e->getParams();
     if (is_array($params) && array_key_exists('__RESULT__', $params)) {
         $this->_cache_result = $params['__RESULT__'];
         unset($params['__RESULT__']);
     }
     $this->_key = crc32(get_class($e->getTarget()) . '-' . json_encode($params));
 }
コード例 #5
0
 /**
  * Remove the object from the Identity Map if it's there
  *
  * @param  EventInterface $e
  * @return void
  */
 public function removeFromCache(EventInterface $e)
 {
     $mapper = $e->getTarget();
     $params = $e->getParams();
     $query = $params['query'];
     $cacheKey = $query->getCacheKey();
     if (!$cacheKey) {
         return;
     }
     $this->identityMap->remove($mapper->getClassName(), $cacheKey);
 }
コード例 #6
0
 /**
  * Send a message to Queue about indexing entry.
  *
  * @param EventInterface $event
  */
 public function index(EventInterface $event)
 {
     try {
         $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
         $channel = $connection->channel();
         $channel->queue_declare('search-index', false, false, false, false);
         $params = $event->getParams();
         $msg = new AMQPMessage(json_encode($params));
         $channel->basic_publish($msg, '', 'search-index');
         $channel->close();
         $connection->close();
     } catch (\Exception $e) {
         $this->logger->warn("Queue Service when indexing entries: " . $e->getMessage());
     }
 }
コード例 #7
0
 /**
  * Callback on receive webhook
  * @param  EventInterface $event
  * @return void
  */
 public function onWebhookReceive(EventInterface $event)
 {
     /**
      * Retrieve the API from the target controller and inject into ourself
      */
     $controller = $event->getTarget();
     $context = $controller->getContext();
     $this->setPrismicApi($context->getPrismicApi());
     /**
      * Respond to the event
      */
     $type = $event->getParam('type');
     $this->lastPayload = $event->getParams();
     if ('api-update' === $type) {
         $this->clearCache();
     }
 }
コード例 #8
0
 /**
  * Send email notification of contact request
  *
  * @param EventInterface $event
  */
 public function notify(EventInterface $event)
 {
     $contact = $event->getParams();
     if (!$contact instanceof ContactEntity) {
         return;
     }
     $config = $this->getConfig();
     $message = new Message();
     $message->setFrom($config['contact']['from']);
     $message->setTo($config['contact']['email']);
     $message->setSubject("Contact Request from {$contact->getName()}");
     $message->setBody("Contact request ID {$contact->getId()}\n" . "Name: {$contact->getName()}\n" . "Email: {$contact->getEmail()}\n" . "\n---------------------------------\n" . $contact->getMessage());
     //        try {
     $this->getEmailService()->send($message);
     //        } catch (\Exception $e) {
     //            // TODO log failure
     //        }
 }
コード例 #9
0
ファイル: LogListener.php プロジェクト: kalelc/inventory
 public function save(EventInterface $e)
 {
     $log = new Log();
     $logTable = $this->serviceManager->get("Security\\Model\\LogTable");
     $params = $e->getParams();
     $authenticationService = new AuthenticationService();
     $user = $authenticationService->getIdentity()->id;
     if (isset($params['id']) && !empty($params['id'])) {
         $log->setTableId($params['id']);
     }
     $log->setTable($params['table']);
     $log->setOperation($params['operation']);
     if (isset($params['data'])) {
         $log->setData($params['data']);
     }
     $log->setUser($user);
     $logTable->save($log);
 }
コード例 #10
0
ファイル: Good.php プロジェクト: rostmefpoter/bh
 public function afterCreate(EventInterface $msg)
 {
     $data = $msg->getParams();
     /*
     if ($data['operation'] == 'отдал') {
         $id = $this->boot()->get('good')->insert([
             'source_subject_id' => $data['target_subject_id'],
             'target_subject_id' => $data['source_subject_id'],
             'product_id' => $data['product_id'],
             'count' => $data['count'],
             'notes' => $data['notes'],
             'add_date' => $data['add_date'],
             'operation' => 'получил',
             'contr_entity_id' => $data['id'],
             'owner' => $data['owner'],
             'confirm' => 0
         ]);
         $this->boot()->get('good')->update($data['id'], [
             'contr_entity_id' => $id,
         ]);
     }
     
     if ($data['operation'] == 'получил') {
         $id = $this->boot()->get('good')->insert([
             'source_subject_id' => $data['target_subject_id'],
             'target_subject_id' => $data['source_subject_id'],
             'product_id' => $data['product_id'],
             'count' => $data['count'],
             'notes' => $data['notes'],
             'add_date' => $data['add_date'],
             'operation' => 'отдал',
             'contr_entity_id' => $data['id'],
             'owner' => $data['owner'],
             'confirm' => 0
         ]);
         $this->boot()->get('good')->update($data['id'], [
             'contr_entity_id' => $id,
         ]);
     }
     */
 }
コード例 #11
0
 /**
  * Put Object to S3
  *
  * @param EventInterface $event
  */
 public function putObject(EventInterface $event)
 {
     $params = $event->getParams();
     $config = $this->getServiceLocator()->get('Config');
     $imageFileName = basename(basename($params->getPath()));
     $thumbFileName = basename(basename($params->getThumbPath()));
     $awsSdk = $this->getServiceLocator()->get(AwsSdk::class);
     $s3Client = $awsSdk->createS3();
     // uploading image to S3
     try {
         $s3Client->putObject(array('Bucket' => $config['s3']['bucket']['name'], 'Key' => $config['s3']['fields']['path']['key_prefix'] . '/' . $imageFileName, 'Body' => fopen($params->getPath(), 'r'), 'ACL' => $config['s3']['bucket']['acl']));
     } catch (S3Exception $e) {
         //             var_dump($e->getMessage());
     }
     // uploading thumbnail to S3
     try {
         $s3Client->putObject(array('Bucket' => $config['s3']['bucket']['name'], 'Key' => $config['s3']['fields']['thumbPath']['key_prefix'] . '/' . $imageFileName, 'Body' => fopen($params->getThumbPath(), 'r'), 'ACL' => $config['s3']['bucket']['acl']));
     } catch (S3Exception $e) {
         //             var_dump($e->getMessage());
     }
 }
コード例 #12
0
ファイル: FirewallListener.php プロジェクト: dollyaswin/pyro
 /**
  * Listen to the "user" event
  *
  * @param EventInterface $event
  * @return mixed
  */
 public function doFirewall(EventInterface $event)
 {
     $serviceManager = $this->getServiceLocator();
     $application = $serviceManager->get('Application');
     $request = $application->getRequest();
     if ($request instanceof ConsoleRequest) {
         return;
     }
     if ($serviceManager->get('config')['zoop']['pyro']['enable']) {
         $firewall = $event->getParams();
         if ($firewall instanceof Firewall) {
             $ipAddress = $this->getIpAddress();
             $this->triggerEvent(FirewallEvent::EVENT_FIREWALL_PRE_PROCESS, $firewall);
             try {
                 $firewall->process($ipAddress);
                 $this->triggerEvent(FirewallEvent::EVENT_FIREWALL_POST_PROCESS, $firewall);
             } catch (IpAddressDeniedException $e) {
                 $application->getResponse()->setStatusCode(403);
             }
         }
     }
 }
コード例 #13
0
 /**
  * Thumbnail Image
  *
  * @param EventInterface $event
  */
 public function thumbnailImage(EventInterface $event)
 {
     $params = $event->getParams();
     $config = $this->getServiceLocator()->get('Config');
     $thumbFilePath = $config['images']['thumb_path'] . DIRECTORY_SEPARATOR . basename($params->getPath());
     Resize::save($params->getPath(), $thumbFilePath, 200, 200);
     $params->setThumbPath($thumbFilePath);
 }
コード例 #14
0
 public function onEvent(EventInterface $event)
 {
     if ($event instanceof LogEvent) {
         $this->logger->log($event->getPriority(), $event->getMessage(), $event->getParams());
     }
 }
コード例 #15
0
 /**
  * emailMissingTranslation
  *
  * @param EventInterface $event
  *
  * @return void
  */
 public function emailMissingTranslation($event)
 {
     $params = $event->getParams();
     $defaultLocale = $this->getDefaultLocale();
     if ($params['locale'] !== $defaultLocale) {
         // @todo write and implement this
     }
 }
コード例 #16
0
ファイル: ActivityListener.php プロジェクト: bix0r/Stjornvisi
 /**
  * Actually do the logging.
  *
  * @param EventInterface $event
  * @todo this requires a major rewrite
  */
 public function log(EventInterface $event)
 {
     $target = $event->getTarget();
     $recipient = [(object) ['name' => 'Stjónvísi', 'address' => '*****@*****.**'], (object) ['name' => 'Einar Valur', 'address' => '*****@*****.**']];
     $params = $event->getParams();
     $method = isset($params[0]) ? $params[0] : '';
     if ($target instanceof Event && isset($params['data'])) {
         $data = $params['data'];
         switch ($method) {
             case 'create':
                 $this->send($recipient, '[Activity]:Viðburður stofnaður', "<p>Viðburður <strong>{$data['subject']}</strong> stofnaður <a href=\"http://stjornvisi.is/vidburdir/{$data['id']}\">http://stjornvisi.is/vidburdir/{$data['id']}</a></p>");
                 break;
             case 'update':
                 $this->send($recipient, '[Activity]:Viðburður uppfærður', "<p>Viðburður <strong>{$data['subject']}</strong> uppfærður <a href=\"http://stjornvisi.is/vidburdir/{$data['id']}\">http://stjornvisi.is/vidburdir/{$data['id']}</p>");
                 break;
             case 'delete':
                 $this->send($recipient, '[Activity]:Viðburði eytt', "<p>Viðburði <strong>{$data['subject']}</strong> eytt</p>");
                 break;
             default:
                 break;
         }
     } else {
         if ($target instanceof News && isset($params['data'])) {
             $data = $params['data'];
             switch ($method) {
                 case 'create':
                     $this->send($recipient, '[Activity]:Frétt stofnuð', "<p>Frétt <strong>{$data['title']}</strong> stofnuð <a href=\"http://stjornvisi.is/frettir/{$data['id']}\">http://stjornvisi.is/frettir/{$data['id']}</a></p>");
                     break;
                 case 'update':
                     $this->send($recipient, '[Activity]:Frétt uppfærð', "<p>Frétt <strong>{$data['title']}</strong> uppfærður <a href=\"http://stjornvisi.is/frettir/{$data['id']}\">http://stjornvisi.is/frettir/{$data['id']}</p>");
                     break;
                 case 'delete':
                     $this->send($recipient, '[Activity]:Frétt eytt', "<p>Frétt <strong>{$data['title']}</strong> eytt</p>");
                     break;
                 default:
                     break;
             }
         } else {
             if ($target instanceof Company && isset($params['data'])) {
                 $data = $params['data'];
                 switch ($method) {
                     case 'create':
                         $this->send($recipient, '[Activity]:Fyrirtæki stofnuð', "<p>Fyrirtæki <strong>{$data['name']}</strong> stofnuð <a href=\"http://stjornvisi.is/fyrirtaeki/{$data['id']}\">http://stjornvisi.is/fyrirtaeki/{$data['id']}</a></p>");
                         break;
                     case 'update':
                         $this->send($recipient, '[Activity]:Fyrirtæki uppfært', "<p>Fyrirtæki <strong>{$data['name']}</strong> uppfært <a href=\"http://stjornvisi.is/fyrirtaeki/{$data['id']}\">http://stjornvisi.is/fyrirtaeki/{$data['id']}</p>");
                         break;
                     case 'delete':
                         $this->send($recipient, '[Activity]:Fyrirtæki eytt', "<p>Fyrirtæki <strong>{$data['name']}</strong> eytt</p>");
                         break;
                     default:
                         break;
                 }
             } elseif ($target instanceof User && isset($params['data'])) {
                 $data = $params['data'];
                 switch ($method) {
                     case 'create':
                         $this->send($recipient, '[Activity]:Notandi stofnaður', "<p>Notandi <strong>{$data['name']}</strong> stofnaður <a href=\"http://stjornvisi.is/notandi/{$data['id']}\">http://stjornvisi.is/notandi/{$data['id']}</a></p>");
                         break;
                     default:
                         break;
                 }
             }
         }
     }
 }
コード例 #17
0
 /**
  * addMissingDefaultTranslation
  *
  * @param EventInterface $event
  *
  * @return void
  */
 public function addMissingDefaultTranslation($event)
 {
     $params = $event->getParams();
     $defaultLocale = $this->getDefaultLocale();
     // Ignore if not translate
     if ($params['text_domain'] === self::DO_NOT_TRANSLATE) {
         return;
     }
     // Only adding if we are the default locale
     if ($params['locale'] !== $defaultLocale) {
         return;
     }
     $em = $this->getEntityManager();
     try {
         $defaultMessage = $em->getRepository('RcmI18n\\Entity\\Message')->findOneBy(['locale' => $defaultLocale, 'defaultText' => $params['message']]);
     } catch (\Exception $e) {
         $defaultMessage = null;
     }
     if (empty($defaultMessage)) {
         $newMessage = new Message();
         $newMessage->setLocale($defaultLocale);
         $newMessage->setDefaultText($params['message']);
         $newMessage->setText($params['message']);
         $em->persist($newMessage);
         $em->flush($newMessage);
     }
 }
コード例 #18
0
ファイル: AbstractController.php プロジェクト: nuklehed/zf2
 /**
  * Set an event to use during dispatch
  *
  * By default, will re-cast to MvcEvent if another event type is provided.
  *
  * @param  Event $e
  * @return void
  */
 public function setEvent(Event $e)
 {
     if ($e instanceof Event && !$e instanceof MvcEvent) {
         $eventParams = $e->getParams();
         $e = new MvcEvent();
         $e->setParams($eventParams);
         unset($eventParams);
     }
     $this->event = $e;
 }
コード例 #19
0
ファイル: Module.php プロジェクト: dotuancd/secretary
 /**
  * @param  \Zend\EventManager\EventInterface $e
  * @return void
  */
 protected function initMail(EventInterface $e)
 {
     $config = $e->getApplication()->getConfig();
     if ($config['mail']['activate'] === false) {
         return;
     }
     /* @var \Secretary\Service\Mail $mailService */
     $mailService = $e->getApplication()->getServiceManager()->get('mail-service');
     /* @var \Zend\EventManager\SharedEventManager $sharedEvents */
     $sharedEvents = $e->getApplication()->getEventManager()->getSharedManager();
     $identifier = array('Zend\\Mvc\\Controller\\AbstractActionController', 'Secretary\\Service\\Base');
     $sharedEvents->attach($identifier, 'sendMail', function ($e) use($mailService) {
         $target = $e->getTarget();
         $mailOptions = $e->getParams();
         $mailService->send($mailOptions, $target);
     });
     $sharedEvents->attach('Zend\\Mvc\\Application', 'dispatch.error', function ($e) use($mailService) {
         $exception = $e->getParam('exception');
         if (empty($exception)) {
             return;
         }
         $mailService->send(array('exception' => $exception), 'error');
     });
 }
コード例 #20
0
 /**
  * Removes an object from the cache
  *
  * @param  EventInterface $e
  * @return void
  */
 public function removeFromCache(EventInterface $e)
 {
     $mapper = $e->getTarget();
     $params = $e->getParams();
     $object = $params['object'];
     // build a query object for this id
     $primaryKey = $mapper->getAdapterOption('primaryKey');
     if ($primaryKey && is_scalar($primaryKey)) {
         $query = $mapper->getAdapter()->buildQuery();
         $query->setId($object->{$primaryKey});
     } else {
         return;
     }
     $cacheKey = $query->getCacheKey();
     if (!$cacheKey) {
         return;
     }
     if ($cacheKey) {
         $this->cache->removeItem($cacheKey);
     }
 }
コード例 #21
0
 /**
  * @param EventInterface $event
  */
 public function setEvent(EventInterface $event)
 {
     if (!$event instanceof MvcEvent) {
         $this->event = new MvcEvent(null, null, $event->getParams());
         return;
     }
     $this->event = $event;
 }
コード例 #22
0
 /**
  * Actually do the logging.
  *
  * @param EventInterface $event
  */
 public function log(EventInterface $event)
 {
     $params = $event->getParams();
     $method = isset($params[0]) ? $params[0] : '';
     $this->logger->debug(get_class($event->getTarget()) . "::{$method} - {$event->getName()}");
 }