示例#1
0
 /**
  * @param string $message
  */
 public function logDebug($message)
 {
     if (!is_null($this->getLogger())) {
         $this->logger->debug($message);
     }
     if (!is_null($this->getConsoleOutput())) {
         $this->consoleOutput->writeln("<info>>>> " . $message . "</info>");
     }
 }
 /**
  * @param string $command
  * @param [] $args
  * @return mixed
  */
 protected function commit($command, array $args)
 {
     if ($this->logger) {
         $this->logger->debug(__CLASS__ . ' >> ' . $command, $args);
     }
     return $this->client->{$command}($args);
 }
示例#3
0
 /**
  * Connect to AMI and start emitting events.
  *
  * @param string $address Example uaername:password@localhost:5038
  * @return \React\Promise\Promise
  */
 public function connect($address)
 {
     $factory = new Factory($this->eventLoop);
     return $factory->createClient($address)->then(function (Client $client) {
         $this->amiClient = $client;
         $this->actionSender = new ActionSender($client);
         $this->actionSender->events(true);
         $client->on('close', function () {
             $this->logger->debug('AMI connection closed');
         });
         $client->on('event', function (Event $event) {
             $this->wsClient->emit($event->getName(), (array) $event);
         });
     }, function (\Exception $e) {
         $this->logger->err('Connection error: ' . $e->getMessage());
     });
 }
示例#4
0
文件: Zend2.php 项目: tillk/vufind
 /**
  * Print a message if debug is enabled.
  *
  * @param string $msg Message to print
  *
  * @return void
  */
 protected function debugPrint($msg)
 {
     if ($this->logger) {
         $this->logger->debug("{$msg}\n");
     } else {
         parent::debugPrint($msg);
     }
 }
 /**
  * Generates the request url for querying the Google Geocoder API.
  *
  * @param string $address
  * @param string $format
  * @return string
  */
 protected function generateRequestUrl($address, $format)
 {
     $url = self::GEOCODER_API_URI;
     $url .= $format;
     $queryParams = ['address' => $address];
     $key = $this->getKey();
     if (null != $key) {
         $queryParams['key'] = $key;
     }
     $queryString = http_build_query($queryParams);
     $url .= '?' . $queryString;
     if (true === isset($queryParams['key'])) {
         $queryParams['key'] = mb_substr($key, 0, 2) . str_repeat('x', strlen($key) - 4) . mb_substr($key, -2);
         $queryString = http_build_query($queryParams);
     }
     $this->logger->debug(sprintf('Generated url: %s.', self::GEOCODER_API_URI . '?' . $queryString));
     return $url;
 }
示例#6
0
 /**
  * Show a debug message.
  *
  * @param string $msg Debug message.
  *
  * @return void
  */
 protected function debug($msg)
 {
     if ($this->logger) {
         $this->logger->debug($msg);
     }
 }
示例#7
0
 /**
  * Log information about a database query
  * @param \Application\Service\EventInterface $e
  */
 public function logQuery(EventInterface $e)
 {
     $text = $e->getParam('query');
     $this->logger->debug($text);
 }
示例#8
0
 /**
  * Login via an external Application. This will get obsolet as soon we'll have a full featured Rest API.
  *
  * Passed in params:
  * - appKey: Application identifier key
  * - user: Name of the user to log in
  * - pass: Password of the user to log in
  *
  * Returns an json response with the session-id.
  * Non existent users will be created!
  *
  */
 public function loginExternAction()
 {
     $services = $this->serviceLocator;
     $adapter = $services->get('ExternalApplicationAdapter');
     $appKey = $this->params()->fromPost('appKey');
     $adapter->setIdentity($this->params()->fromPost('user'))->setCredential($this->params()->fromPost('pass'))->setApplicationKey($appKey);
     $auth = $this->auth;
     $result = $auth->authenticate($adapter);
     if ($result->isValid()) {
         $this->logger->info('User ' . $this->params()->fromPost('user') . ' logged via ' . $appKey);
         // the external login may include some parameters for an update
         $updateParams = $this->params()->fromPost();
         unset($updateParams['user'], $updateParams['pass'], $updateParams['appKey']);
         $resultMessage = $result->getMessages();
         $password = null;
         if (array_key_exists('firstLogin', $resultMessage) && $resultMessage['firstLogin'] === true) {
             $password = substr(md5(uniqid()), 0, 6);
             $updateParams['password'] = $password;
         }
         if (!empty($updateParams)) {
             $user = $auth->getUser();
             try {
                 foreach ($updateParams as $updateKey => $updateValue) {
                     if ('email' == $updateKey) {
                         $user->info->email = $updateValue;
                     }
                     $user->{$updateKey} = $updateValue;
                 }
             } catch (\Exception $e) {
             }
             $services->get('repositories')->store($user);
         }
         $resultMessage = $result->getMessages();
         // TODO: send a mail also when required (maybe first mail failed or email has changed)
         if (array_key_exists('firstLogin', $resultMessage) && $resultMessage['firstLogin'] === true) {
             // first external Login
             $userName = $this->params()->fromPost('user');
             $this->logger->debug('first login for User: '******'/^(.*)@\\w+$/', $userName, $realUserName)) {
                 $userName = $realUserName[1];
             }
             $mail = $this->mailer('htmltemplate');
             /* @var $mail \Core\Mail\HTMLTemplateMessage */
             $apps = $this->config('external_applications');
             $apps = array_flip($apps);
             $application = isset($apps[$appKey]) ? $apps[$appKey] : null;
             $mail->setVariables(array('application' => $application, 'login' => $userName, 'password' => $password));
             $mail->setSubject($this->options->getMailSubjectRegistration());
             $mail->setTemplate('mail/first-external-login');
             $mail->addTo($user->getInfo()->getEmail());
             try {
                 $this->mailer($mail);
                 $this->logger->info('Mail first-login sent to ' . $userName);
             } catch (\Zend\Mail\Transport\Exception\ExceptionInterface $e) {
                 $this->logger->warn('No Mail was sent');
                 $this->logger->debug($e);
             }
         }
         return new JsonModel(array('status' => 'success', 'token' => session_id()));
     } else {
         $this->logger->info('Failed to authenticate User ' . $this->params()->fromPost('user') . ' via ' . $this->params()->fromPost('appKey'));
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_401);
         return new JsonModel(array('status' => 'failure', 'user' => $this->params()->fromPost('user'), 'appKey' => $this->params()->fromPost('appKey'), 'code' => $result->getCode(), 'messages' => $result->getMessages()));
     }
 }
示例#9
0
 /**
  * Logs a message using the logger.
  *
  * @param string $message
  */
 public function debug($message)
 {
     if (isset($this->logger)) {
         $this->logger->debug($message);
     }
 }