err() public method

public err ( $message, array $context = [] )
$context array
 /**
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return null
  * @throws PsrInvalidArgumentException
  */
 public function log($level, $message, array $context = array())
 {
     switch ($level) {
         case PsrLogLevel::ALERT:
             $this->symfonyLogger->alert($message, $context);
             break;
         case PsrLogLevel::CRITICAL:
             $this->symfonyLogger->crit($message, $context);
             break;
         case PsrLogLevel::DEBUG:
             $this->symfonyLogger->debug($message, $context);
             break;
         case PsrLogLevel::EMERGENCY:
             $this->symfonyLogger->emerg($message, $context);
             break;
         case PsrLogLevel::ERROR:
             $this->symfonyLogger->err($message, $context);
             break;
         case PsrLogLevel::INFO:
             $this->symfonyLogger->info($message, $context);
             break;
         case PsrLogLevel::NOTICE:
             $this->symfonyLogger->notice($message, $context);
             break;
         case PsrLogLevel::WARNING:
             $this->symfonyLogger->warn($message, $context);
             break;
         default:
             throw new PsrInvalidArgumentException(sprintf('Loglevel "%s" not valid, use constants from "%s"', $level, "Psr\\Log\\LogLevel"));
             break;
     }
     return null;
 }
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $wsseRegex = '/UsernameToken Username="******"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
     if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
         // Deny authentication with a '403 Forbidden' HTTP response
         $response = new Response();
         $response->setStatusCode(403);
         $event->setResponse($response);
         return;
     }
     $token = new WsseUserToken();
     $token->setUser($matches[1]);
     $token->digest = $matches[2];
     $token->nonce = $matches[3];
     $token->created = $matches[4];
     try {
         $authToken = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($authToken);
         return;
     } catch (AuthenticationException $failed) {
         // ... you might log something here
         $failedMessage = 'WSSE Login failed for ' . $token->getUsername() . '. Why ? ' . $failed->getMessage();
         $this->logger->err($failedMessage);
         //To deny the authentication clear the token. This will redirect to the login page.
         //Make sure to only clear your token, not those of other authentication listeners.
         $this->securityContext->setToken(null);
         // Deny authentication with a '403 Forbidden' HTTP response
         $response = new Response();
         $response->setStatusCode(403);
         $response->setContent($failedMessage);
         $event->setResponse($response);
         return;
     }
 }
 /**
  * Callback called from RabbitMQ to update a bundle
  *
  * @param AMQPMessage $msg serialized Message
  */
 public function execute(AMQPMessage $msg)
 {
     // Retrieve informations from the message
     $message = json_decode($msg->body, true);
     if (!isset($message['bundle_id'])) {
         if ($this->logger) {
             $this->logger->err('Bundle id is missing : skip message');
         }
         return;
     }
     $bundles = $this->em->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle');
     // Retrieve Bundle from database
     /* @var $bundle Bundle */
     if (!($bundle = $bundles->find($message['bundle_id']))) {
         if ($this->logger) {
             $this->logger->warn(sprintf('Unable to retrieve bundle #%d', $message['bundle_id']));
         }
         return;
     }
     if (isset($message['action']) && 'remove' == $message['action']) {
         if ($this->logger) {
             $this->logger->warn(sprintf('Bundle "%s" will be removed', $bundle->getName()));
         }
         $this->removeBundle($bundle);
         return;
     }
     if ($this->logger) {
         $this->logger->info(sprintf('Retrieved bundle %s', $bundle->getName()));
     }
     $keywordRepo = $this->em->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Keyword');
     $scoreRepo = $this->em->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Score');
     for ($i = 0; $i < self::MAX_GITHUB_TRIALS; $i++) {
         try {
             if (!$this->githubRepoApi->update($bundle)) {
                 if ($this->logger) {
                     $this->logger->warn(sprintf('Update of "%s" failed', $bundle->getName()));
                 }
                 return;
             }
             $this->indexer->indexBundle($bundle);
             $this->updateContributors($bundle);
             $this->updateKeywords($bundle, $keywordRepo);
             $this->updateScore($bundle, $scoreRepo);
             if ($bundle->getUsesTravisCi()) {
                 $this->travis->update($bundle);
             }
         } catch (ApiLimitExceedException $e) {
             if ($this->logger) {
                 $this->logger->err(sprintf('Bundle %s got a %s for trial %s', $bundle->getName(), $e->getMessage(), $i + 1));
             }
             sleep(60 * ($i + 1));
             continue;
         } catch (\Exception $e) {
             if ($this->logger) {
                 $this->logger->err('[' . get_class($e) . ' / ' . $e->getFile() . ':' . $e->getLine() . '] ' . $e->getMessage());
             }
         }
         break;
     }
 }
Example #4
0
 /**
  * Treat a Zend Ldap Exception.
  *
  * @param ZendLdapException $exception
  */
 protected function zendExceptionHandler(ZendLdapException $exception)
 {
     switch ($exception->getCode()) {
         // Error level codes
         case ZendLdapException::LDAP_SERVER_DOWN:
             if ($this->logger) {
                 $this->logger->err($exception->getMessage());
             }
             break;
             // Other level codes
         // Other level codes
         default:
             $this->logDebug($exception->getMessage());
             break;
     }
 }
 /**
  * {@inheritDoc}
  */
 public function execute(AMQPMessage $msg)
 {
     if ($this->logger) {
         $this->logger->info('[GithubHookConsumer] Received a github post push hook');
     }
     if (null === ($message = json_decode($msg->body))) {
         if ($this->logger) {
             $this->logger->err('[GithubHookConsumer] Unable to decode payload');
         }
         return;
     }
     $payload = $message->payload;
     $bundle = $this->manager->getRepository('KnpBundlesBundle:Bundle')->findOneBy(array('name' => $payload->repository->name, 'ownerName' => $payload->repository->owner->name));
     if (!$bundle) {
         if ($this->logger) {
             $this->logger->warn(sprintf('[GithubHookConsumer] unknown bundle %s/%s', $payload->repository->name, $payload->repository->owner->name));
         }
         return;
     }
     $this->producer->publish(serialize(array('bundle_id' => $bundle->getId())));
 }
 /**
  * Logs exceptions
  *
  * @param \Exception  $originalException  Original exception that called the listener
  * @param \Exception  $generatedException Generated exception
  * @param string|null $message            Message to log
  */
 private function logException(\Exception $originalException, \Exception $generatedException, $message = null)
 {
     if (!$message) {
         $message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($generatedException), $generatedException->getMessage());
     }
     if (null !== $this->logger) {
         if (!$originalException instanceof HttpExceptionInterface || $originalException->getStatusCode() >= 500) {
             $this->logger->crit($message);
         } else {
             $this->logger->err($message);
         }
     } else {
         error_log($message);
     }
 }
 /**
  * Handle a server-initiated message by passing it to our handlers.
  * @param \XMPPHP_XMLObj $message The message.
  */
 public function handleMessage(\XMPPHP_XMLObj $message)
 {
     try {
         $parsed = simplexml_load_string($message->toString());
         $payload = $parsed->event->asXml();
     } catch (\Exception $exception) {
         if ($this->logger !== null) {
             $this->logger->err("Problem parsing XML: " . $message->toString());
         }
         throw $exception;
     }
     try {
         foreach ($this->handlers as $handler) {
             $handler->handleNotification($payload);
         }
     } catch (\Exception $exception) {
         // Log exceptions, but don't stop them from propagating
         if ($this->logger !== null) {
             $this->logger->err("Caught " . \get_class($exception) . " while handling notification: " . $exception->getMessage());
         }
         throw $exception;
     }
 }
Example #8
0
 /**
  * A convenience function for logging an error event.
  *
  * @param mixed $message the message to log.
  */
 public function err($message)
 {
     if (null !== $this->logger) {
         $this->logger->err($message);
     }
 }
Example #9
0
 /**
  * A convenience function for logging an error event.
  *
  * @param mixed $message the message to log.
  */
 public function err($message)
 {
     $this->logger->err($message);
 }
Example #10
0
 public function enterNode(\PHPParser_Node $node)
 {
     /**
      * determine domain from namespace of files.
      * Finder appears to start with root level files so Namespace is correct for remaining files
      */
     if ($node instanceof \PHPParser_Node_Stmt_Namespace) {
         if (isset($node->name)) {
             if (array_key_exists($node->name->toString(), $this->bundles)) {
                 $this->domain = strtolower($this->bundles[$node->name->toString()]);
             }
             return;
         } else {
             foreach ($node->stmts as $node) {
                 $this->enterNode($node);
             }
             return;
         }
     }
     if (!$node instanceof \PHPParser_Node_Expr_MethodCall || !is_string($node->name) || !in_array(strtolower($node->name), $this->methodNames)) {
         $this->previousNode = $node;
         return;
     }
     $ignore = false;
     $desc = $meaning = null;
     if (null !== ($docComment = $this->getDocCommentForNode($node))) {
         foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
             if ($annot instanceof Ignore) {
                 $ignore = true;
             } else {
                 if ($annot instanceof Desc) {
                     $desc = $annot->text;
                 } else {
                     if ($annot instanceof Meaning) {
                         $meaning = $annot->text;
                     }
                 }
             }
         }
     }
     if (!$node->args[0]->value instanceof \PHPParser_Node_Scalar_String) {
         if ($ignore) {
             return;
         }
         $message = sprintf('Can only extract the translation id from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine());
         if ($this->logger) {
             $this->logger->err($message);
             return;
         }
         throw new RuntimeException($message);
     }
     $id = $node->args[0]->value->value;
     if (in_array(strtolower($node->name), array('_n', '_fn'), true)) {
         // concatenate pluralized strings from zikula functions
         $id = $node->args[0]->value->value . '|' . $node->args[1]->value->value;
     }
     // determine location of domain
     $domainIndex = array_search(strtolower($node->name), $this->methodNames);
     if (isset($node->args[$domainIndex])) {
         if (!$node->args[$domainIndex]->value instanceof \PHPParser_Node_Scalar_String) {
             if ($ignore) {
                 return;
             }
             $message = sprintf('Can only extract the translation domain from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine());
             if ($this->logger) {
                 $this->logger->err($message);
                 return;
             }
             throw new RuntimeException($message);
         }
         $domain = $node->args[$domainIndex]->value->value;
     } else {
         $domain = !empty($this->domain) ? $this->domain : 'messages';
     }
     $message = new Message($id, $domain);
     $message->setDesc($desc);
     $message->setMeaning($meaning);
     $message->addSource(new FileSource((string) $this->file, $node->getLine()));
     $this->catalogue->add($message);
 }
Example #11
0
 /**
  * @throws MissingMandatoryParametersException When route has some missing mandatory parameters
  * @throws InvalidParameterException When a parameter value is not correct
  */
 protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute, $hostnameTokens)
 {
     $variables = array_flip($variables);
     $mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
     // all params must be given
     if ($diff = array_diff_key($variables, $mergedParams)) {
         throw new MissingMandatoryParametersException(sprintf('The "%s" route has some missing mandatory parameters ("%s").', $name, implode('", "', array_keys($diff))));
     }
     $url = '';
     $optional = true;
     foreach ($tokens as $token) {
         if ('variable' === $token[0]) {
             if (!$optional || !array_key_exists($token[3], $defaults) || (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
                 // check requirement
                 if (null !== $this->strictRequirements && !preg_match('#^' . $token[2] . '$#', $mergedParams[$token[3]])) {
                     $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $token[2], $mergedParams[$token[3]]);
                     if ($this->strictRequirements) {
                         throw new InvalidParameterException($message);
                     }
                     if ($this->logger) {
                         $this->logger->err($message);
                     }
                     return null;
                 }
                 $url = $token[1] . $mergedParams[$token[3]] . $url;
                 $optional = false;
             }
         } else {
             // static text
             $url = $token[1] . $url;
             $optional = false;
         }
     }
     if ('' === $url) {
         $url = '/';
     }
     // do not encode the contexts base url as it is already encoded (see Symfony\Component\HttpFoundation\Request)
     $url = $this->context->getBaseUrl() . strtr(rawurlencode($url), $this->decodedChars);
     // the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
     // so we need to encode them as they are not used for this purpose here
     // otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
     $url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
     if ('/..' === substr($url, -3)) {
         $url = substr($url, 0, -2) . '%2E%2E';
     } elseif ('/.' === substr($url, -2)) {
         $url = substr($url, 0, -1) . '%2E';
     }
     // add a query string if needed
     $extra = array_diff_key($parameters, $variables);
     if ($extra && ($query = http_build_query($extra, '', '&'))) {
         $url .= '?' . $query;
     }
     if ($host = $this->context->getHost()) {
         $scheme = $this->context->getScheme();
         if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme != $req) {
             $absolute = true;
             $scheme = $req;
         }
         if ($hostnameTokens) {
             $routeHost = '';
             foreach ($hostnameTokens as $token) {
                 if ('variable' === $token[0]) {
                     if (null !== $this->strictRequirements && !preg_match('#^' . $token[2] . '$#', $mergedParams[$token[3]])) {
                         $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $token[2], $mergedParams[$token[3]]);
                         if ($this->strictRequirements) {
                             throw new InvalidParameterException($message);
                         }
                         if ($this->logger) {
                             $this->logger->err($message);
                         }
                         return null;
                     }
                     $routeHost = $token[1] . $mergedParams[$token[3]] . $routeHost;
                 } elseif ('text' === $token[0]) {
                     $routeHost = $token[1] . $routeHost;
                 }
             }
             if ($routeHost != $host) {
                 $host = $routeHost;
                 $absolute = true;
             }
         }
         if ($absolute) {
             $port = '';
             if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
                 $port = ':' . $this->context->getHttpPort();
             } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
                 $port = ':' . $this->context->getHttpsPort();
             }
             $url = $scheme . '://' . $host . $port . $url;
         }
     }
     return $url;
 }
 public function onSalesforceClientError(Event\ErrorEvent $event)
 {
     $error = $event->getError();
     $this->logger->err('[Salesforce] error: ' . $error->statusCode . ' - ' . $error->message, get_object_vars($error));
 }