update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -0,0 +1,13 @@
CHANGELOG
=========
2.4.0
-----
* added ConsoleHandler and ConsoleFormatter which can be used to show log messages
in the console output depending on the verbosity settings
2.1.0
-----
* added ChromePhpHandler

View file

@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Formatter;
use Monolog\Formatter\LineFormatter;
use Monolog\Logger;
/**
* Formats incoming records for console output by coloring them depending on log level.
*
* @author Tobias Schultze <http://tobion.de>
*/
class ConsoleFormatter extends LineFormatter
{
const SIMPLE_FORMAT = "%start_tag%[%datetime%] %channel%.%level_name%:%end_tag% %message% %context% %extra%\n";
/**
* {@inheritdoc}
*/
public function __construct($format = null, $dateFormat = null, $allowInlineLineBreaks = false, $ignoreEmptyContextAndExtra = true)
{
parent::__construct($format, $dateFormat, $allowInlineLineBreaks, $ignoreEmptyContextAndExtra);
}
/**
* {@inheritdoc}
*/
public function format(array $record)
{
if ($record['level'] >= Logger::ERROR) {
$record['start_tag'] = '<error>';
$record['end_tag'] = '</error>';
} elseif ($record['level'] >= Logger::NOTICE) {
$record['start_tag'] = '<comment>';
$record['end_tag'] = '</comment>';
} elseif ($record['level'] >= Logger::INFO) {
$record['start_tag'] = '<info>';
$record['end_tag'] = '</info>';
} else {
$record['start_tag'] = '';
$record['end_tag'] = '';
}
return parent::format($record);
}
}

View file

@ -0,0 +1,81 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Handler\ChromePHPHandler as BaseChromePhpHandler;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
/**
* ChromePhpHandler.
*
* @author Christophe Coevoet <stof@notk.org>
*/
class ChromePhpHandler extends BaseChromePhpHandler
{
/**
* @var array
*/
private $headers = array();
/**
* @var Response
*/
private $response;
/**
* Adds the headers to the response once it's created.
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if (!preg_match('{\bChrome/\d+[\.\d+]*\b}', $event->getRequest()->headers->get('User-Agent'))) {
$this->sendHeaders = false;
$this->headers = array();
return;
}
$this->response = $event->getResponse();
foreach ($this->headers as $header => $content) {
$this->response->headers->set($header, $content);
}
$this->headers = array();
}
/**
* {@inheritdoc}
*/
protected function sendHeader($header, $content)
{
if (!$this->sendHeaders) {
return;
}
if ($this->response) {
$this->response->headers->set($header, $content);
} else {
$this->headers[$header] = $content;
}
}
/**
* Override default behavior since we check it in onKernelResponse.
*/
protected function headersAccepted()
{
return true;
}
}

View file

@ -0,0 +1,186 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Writes logs to the console output depending on its verbosity setting.
*
* It is disabled by default and gets activated as soon as a command is executed.
* Instead of listening to the console events, the output can also be set manually.
*
* The minimum logging level at which this handler will be triggered depends on the
* verbosity setting of the console output. The default mapping is:
* - OutputInterface::VERBOSITY_NORMAL will show all WARNING and higher logs
* - OutputInterface::VERBOSITY_VERBOSE (-v) will show all NOTICE and higher logs
* - OutputInterface::VERBOSITY_VERY_VERBOSE (-vv) will show all INFO and higher logs
* - OutputInterface::VERBOSITY_DEBUG (-vvv) will show all DEBUG and higher logs, i.e. all logs
*
* This mapping can be customized with the $verbosityLevelMap constructor parameter.
*
* @author Tobias Schultze <http://tobion.de>
*/
class ConsoleHandler extends AbstractProcessingHandler implements EventSubscriberInterface
{
/**
* @var OutputInterface|null
*/
private $output;
/**
* @var array
*/
private $verbosityLevelMap = array(
OutputInterface::VERBOSITY_NORMAL => Logger::WARNING,
OutputInterface::VERBOSITY_VERBOSE => Logger::NOTICE,
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
);
/**
* Constructor.
*
* @param OutputInterface|null $output The console output to use (the handler remains disabled when passing null
* until the output is set, e.g. by using console events)
* @param bool $bubble Whether the messages that are handled can bubble up the stack
* @param array $verbosityLevelMap Array that maps the OutputInterface verbosity to a minimum logging
* level (leave empty to use the default mapping)
*/
public function __construct(OutputInterface $output = null, $bubble = true, array $verbosityLevelMap = array())
{
parent::__construct(Logger::DEBUG, $bubble);
$this->output = $output;
if ($verbosityLevelMap) {
$this->verbosityLevelMap = $verbosityLevelMap;
}
}
/**
* {@inheritdoc}
*/
public function isHandling(array $record)
{
return $this->updateLevel() && parent::isHandling($record);
}
/**
* {@inheritdoc}
*/
public function handle(array $record)
{
// we have to update the logging level each time because the verbosity of the
// console output might have changed in the meantime (it is not immutable)
return $this->updateLevel() && parent::handle($record);
}
/**
* Sets the console output to use for printing logs.
*
* @param OutputInterface $output The console output to use
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
}
/**
* Disables the output.
*/
public function close()
{
$this->output = null;
parent::close();
}
/**
* Before a command is executed, the handler gets activated and the console output
* is set in order to know where to write the logs.
*
* @param ConsoleCommandEvent $event
*/
public function onCommand(ConsoleCommandEvent $event)
{
$this->setOutput($event->getOutput());
}
/**
* After a command has been executed, it disables the output.
*
* @param ConsoleTerminateEvent $event
*/
public function onTerminate(ConsoleTerminateEvent $event)
{
$this->close();
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(
ConsoleEvents::COMMAND => array('onCommand', 255),
ConsoleEvents::TERMINATE => array('onTerminate', -255),
);
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
if ($record['level'] >= Logger::ERROR && $this->output instanceof ConsoleOutputInterface) {
$this->output->getErrorOutput()->write((string) $record['formatted']);
} else {
$this->output->write((string) $record['formatted']);
}
}
/**
* {@inheritdoc}
*/
protected function getDefaultFormatter()
{
return new ConsoleFormatter();
}
/**
* Updates the logging level based on the verbosity setting of the console output.
*
* @return bool Whether the handler is enabled and verbosity is not set to quiet.
*/
private function updateLevel()
{
if (null === $this->output || OutputInterface::VERBOSITY_QUIET === $verbosity = $this->output->getVerbosity()) {
return false;
}
if (isset($this->verbosityLevelMap[$verbosity])) {
$this->setLevel($this->verbosityLevelMap[$verbosity]);
} else {
$this->setLevel(Logger::DEBUG);
}
return true;
}
}

View file

@ -0,0 +1,59 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Logger;
use Monolog\Handler\TestHandler;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
/**
* DebugLogger.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class DebugHandler extends TestHandler implements DebugLoggerInterface
{
/**
* {@inheritdoc}
*/
public function getLogs()
{
$records = array();
foreach ($this->records as $record) {
$records[] = array(
'timestamp' => $record['datetime']->getTimestamp(),
'message' => $record['message'],
'priority' => $record['level'],
'priorityName' => $record['level_name'],
'context' => $record['context'],
);
}
return $records;
}
/**
* {@inheritdoc}
*/
public function countErrors()
{
$cnt = 0;
$levels = array(Logger::ERROR, Logger::CRITICAL, Logger::ALERT, Logger::EMERGENCY);
foreach ($levels as $level) {
if (isset($this->recordsByLevel[$level])) {
$cnt += count($this->recordsByLevel[$level]);
}
}
return $cnt;
}
}

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Handler\FingersCrossed;
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Activation strategy that ignores 404s for certain URLs.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Fabien Potencier <fabien@symfony.com>
*/
class NotFoundActivationStrategy extends ErrorLevelActivationStrategy
{
private $blacklist;
private $requestStack;
public function __construct(RequestStack $requestStack, array $excludedUrls, $actionLevel)
{
parent::__construct($actionLevel);
$this->requestStack = $requestStack;
$this->blacklist = '{('.implode('|', $excludedUrls).')}i';
}
public function isHandlerActivated(array $record)
{
$isActivated = parent::isHandlerActivated($record);
if (
$isActivated
&& isset($record['context']['exception'])
&& $record['context']['exception'] instanceof HttpException
&& $record['context']['exception']->getStatusCode() == 404
&& ($request = $this->requestStack->getMasterRequest())
) {
return !preg_match($this->blacklist, $request->getPathInfo());
}
return $isActivated;
}
}

View file

@ -0,0 +1,82 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Handler\FirePHPHandler as BaseFirePHPHandler;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response;
/**
* FirePHPHandler.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class FirePHPHandler extends BaseFirePHPHandler
{
/**
* @var array
*/
private $headers = array();
/**
* @var Response
*/
private $response;
/**
* Adds the headers to the response once it's created.
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if (!preg_match('{\bFirePHP/\d+\.\d+\b}', $event->getRequest()->headers->get('User-Agent'))
&& !$event->getRequest()->headers->has('X-FirePHP-Version')) {
$this->sendHeaders = false;
$this->headers = array();
return;
}
$this->response = $event->getResponse();
foreach ($this->headers as $header => $content) {
$this->response->headers->set($header, $content);
}
$this->headers = array();
}
/**
* {@inheritdoc}
*/
protected function sendHeader($header, $content)
{
if (!$this->sendHeaders) {
return;
}
if ($this->response) {
$this->response->headers->set($header, $content);
} else {
$this->headers[$header] = $content;
}
}
/**
* Override default behavior since we check the user agent in onKernelResponse.
*/
protected function headersAccepted()
{
return true;
}
}

View file

@ -0,0 +1,90 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Handler\SwiftMailerHandler as BaseSwiftMailerHandler;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
/**
* Extended SwiftMailerHandler that flushes mail queue if necessary.
*
* @author Philipp Kräutli <pkraeutli@astina.ch>
*/
class SwiftMailerHandler extends BaseSwiftMailerHandler
{
protected $transport;
protected $instantFlush = false;
/**
* @param \Swift_Transport $transport
*/
public function setTransport(\Swift_Transport $transport)
{
$this->transport = $transport;
}
/**
* After the kernel has been terminated we will always flush messages.
*
* @param PostResponseEvent $event
*/
public function onKernelTerminate(PostResponseEvent $event)
{
$this->instantFlush = true;
}
/**
* After the CLI application has been terminated we will always flush messages
*
* @param ConsoleTerminateEvent $event
*/
public function onCliTerminate(ConsoleTerminateEvent $event)
{
$this->instantFlush = true;
}
/**
* {@inheritdoc}
*/
protected function send($content, array $records)
{
parent::send($content, $records);
if ($this->instantFlush) {
$this->flushMemorySpool();
}
}
/**
* Flushes the mail queue if a memory spool is used.
*/
private function flushMemorySpool()
{
$mailerTransport = $this->mailer->getTransport();
if (!$mailerTransport instanceof \Swift_Transport_SpoolTransport) {
return;
}
$spool = $mailerTransport->getSpool();
if (!$spool instanceof \Swift_MemorySpool) {
return;
}
if (null === $this->transport) {
throw new \Exception('No transport available to flush mail queue');
}
$spool->flushQueue($this->transport);
}
}

View file

@ -0,0 +1,19 @@
Copyright (c) 2004-2015 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,94 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog;
use Monolog\Logger as BaseLogger;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
/**
* Logger.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Logger extends BaseLogger implements LoggerInterface, DebugLoggerInterface
{
/**
* @deprecated since 2.2, to be removed in 3.0. Use emergency() which is PSR-3 compatible.
*/
public function emerg($message, array $context = array())
{
return parent::addRecord(BaseLogger::EMERGENCY, $message, $context);
}
/**
* @deprecated since 2.2, to be removed in 3.0. Use critical() which is PSR-3 compatible.
*/
public function crit($message, array $context = array())
{
return parent::addRecord(BaseLogger::CRITICAL, $message, $context);
}
/**
* @deprecated since 2.2, to be removed in 3.0. Use error() which is PSR-3 compatible.
*/
public function err($message, array $context = array())
{
return parent::addRecord(BaseLogger::ERROR, $message, $context);
}
/**
* @deprecated since 2.2, to be removed in 3.0. Use warning() which is PSR-3 compatible.
*/
public function warn($message, array $context = array())
{
return parent::addRecord(BaseLogger::WARNING, $message, $context);
}
/**
* {@inheritdoc}
*/
public function getLogs()
{
if ($logger = $this->getDebugLogger()) {
return $logger->getLogs();
}
return array();
}
/**
* {@inheritdoc}
*/
public function countErrors()
{
if ($logger = $this->getDebugLogger()) {
return $logger->countErrors();
}
return 0;
}
/**
* Returns a DebugLoggerInterface instance if one is registered with this logger.
*
* @return DebugLoggerInterface|null A DebugLoggerInterface instance or null if none is registered
*/
private function getDebugLogger()
{
foreach ($this->handlers as $handler) {
if ($handler instanceof DebugLoggerInterface) {
return $handler;
}
}
}
}

View file

@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Monolog\Processor;
use Monolog\Processor\WebProcessor as BaseWebProcessor;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
/**
* WebProcessor override to read from the HttpFoundation's Request.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class WebProcessor extends BaseWebProcessor
{
public function __construct(array $extraFields = null)
{
// Pass an empty array as the default null value would access $_SERVER
parent::__construct(array(), $extraFields);
}
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->isMasterRequest()) {
$this->serverData = $event->getRequest()->server->all();
}
}
}

View file

@ -0,0 +1,13 @@
Monolog Bridge
==============
Provides integration for Monolog with various Symfony components.
Resources
---------
You can run the unit tests with the following command:
$ cd path/to/Symfony/Bridge/Monolog/
$ composer install
$ phpunit

View file

@ -0,0 +1,43 @@
{
"name": "symfony/monolog-bridge",
"type": "symfony-bridge",
"description": "Symfony Monolog Bridge",
"keywords": [],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=5.3.3",
"monolog/monolog": "~1.11"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7",
"symfony/http-kernel": "~2.4",
"symfony/console": "~2.4",
"symfony/event-dispatcher": "~2.2"
},
"suggest": {
"symfony/http-kernel": "For using the debugging handlers together with the response life cycle of the HTTP kernel.",
"symfony/console": "For the possibility to show log messages in console commands depending on verbosity settings. You need version ~2.3 of the console for it.",
"symfony/event-dispatcher": "Needed when using log messages in console commands"
},
"autoload": {
"psr-0": { "Symfony\\Bridge\\Monolog\\": "" }
},
"target-dir": "Symfony/Bridge/Monolog",
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "2.6-dev"
}
}
}

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Symfony Monolog Bridge Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>