This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Elao/symfony3
allow this bundle to work with symfony3
- Loading branch information
Showing
8 changed files
with
147 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
$header = <<<EOF | ||
This file is part of the Elao ErrorNotifier Bundle | ||
Copyright (C) Elao | ||
@author Elao <[email protected]> | ||
EOF; | ||
|
||
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header); | ||
|
||
return Symfony\CS\Config\Config::create() | ||
// use default SYMFONY_LEVEL and extra fixers: | ||
->fixers([ | ||
'-concat_without_spaces', | ||
'-phpdoc_short_description', | ||
'-pre_increment', | ||
'-unalign_double_arrow', | ||
'-unalign_equals', | ||
'align_double_arrow', | ||
'align_equals', | ||
'concat_with_spaces', | ||
'header_comment', | ||
'ordered_use', | ||
'phpdoc_order', | ||
]) | ||
->setUsingCache(true) | ||
->finder(Symfony\CS\Finder\DefaultFinder::create()->in(__DIR__)) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Elao ErrorNotifier Bundle | ||
* | ||
* Copyright (C) Elao | ||
* | ||
* @author Elao <[email protected]> | ||
*/ | ||
|
||
namespace Elao\ErrorNotifierBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
|
@@ -10,7 +18,6 @@ | |
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
|
||
/** | ||
* Get config tree | ||
* | ||
|
@@ -27,7 +34,9 @@ public function getConfigTreeBuilder() | |
->arrayNode('to') | ||
->beforeNormalization() | ||
->ifString() | ||
->then(function($value) { return array($value); }) | ||
->then(function ($value) { | ||
return array($value); | ||
}) | ||
->end() | ||
->isRequired() | ||
->cannotBeEmpty() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Elao ErrorNotifier Bundle | ||
* | ||
* Copyright (C) Elao | ||
* | ||
* @author Elao <[email protected]> | ||
*/ | ||
|
||
namespace Elao\ErrorNotifierBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
/** | ||
* ElaoErrorNotifier Extension | ||
*/ | ||
class ElaoErrorNotifierExtension extends Extension | ||
{ | ||
|
||
/** | ||
* load configuration | ||
* | ||
* @param array $configs configs | ||
* @param ContainerBuilder $container container | ||
* | ||
* @return void | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
|
@@ -32,11 +36,12 @@ public function load(array $configs, ContainerBuilder $container) | |
|
||
$container->setParameter('elao.error_notifier.config', $config); | ||
|
||
$loader = new XmlFileLoader($container, new FileLocator(array(__DIR__.'/../Resources/config/'))); | ||
$loader = new XmlFileLoader($container, new FileLocator(array(__DIR__ . '/../Resources/config/'))); | ||
$loader->load('services.xml'); | ||
|
||
if ($config['mailer'] != 'mailer') { | ||
$container->getDefinition('elao.error_notifier.listener')->replaceArgument(0, new Reference($config['mailer'])); | ||
$definition = $container->getDefinition('elao.error_notifier.listener'); | ||
$definition->replaceArgument(0, new Reference($config['mailer'])); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Elao ErrorNotifier Bundle | ||
* | ||
* Copyright (C) Elao | ||
* | ||
* @author Elao <[email protected]> | ||
*/ | ||
|
||
namespace Elao\ErrorNotifierBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Elao ErrorNotifier Bundle | ||
* | ||
* Copyright (C) Elao | ||
* | ||
* @author Elao <[email protected]> | ||
*/ | ||
|
||
namespace Elao\ErrorNotifierBundle\Exception; | ||
|
||
/** | ||
* Exception which is thrown when a method cannot be invoked | ||
* | ||
* @see Elao\ErrornotifierBundle\Twig\Dumpy | ||
*/ | ||
class InvokerException extends \Exception | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Elao ErrorNotifier Bundle | ||
* | ||
* Copyright (C) Elao | ||
* | ||
* @author Elao <[email protected]> | ||
*/ | ||
|
||
namespace Elao\ErrorNotifierBundle\Listener; | ||
|
||
use \Swift_Mailer; | ||
use Swift_Mailer; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
use Symfony\Component\Console\Event\ConsoleExceptionEvent; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Debug\Exception\FlattenException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Templating\EngineInterface; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\Console\Event\ConsoleExceptionEvent; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
use Symfony\Component\Debug\Exception\FlattenException; | ||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\Templating\EngineInterface; | ||
|
||
/** | ||
* Notifier | ||
*/ | ||
class Notifier | ||
{ | ||
|
||
/** | ||
* @var Swift_Mailer $mailer | ||
* @var Swift_Mailer | ||
*/ | ||
private $mailer; | ||
|
||
/** | ||
* @var EngineInterface $templating | ||
* @var EngineInterface | ||
*/ | ||
private $templating; | ||
|
||
|
@@ -105,13 +112,13 @@ public function onKernelException(GetResponseForExceptionEvent $event) | |
} | ||
|
||
if (strlen($this->ignoredAgentsPattern)) { | ||
if (preg_match('#'.$this->ignoredAgentsPattern.'#', $event->getRequest()->headers->get('User-Agent'))) { | ||
if (preg_match('#' . $this->ignoredAgentsPattern . '#', $event->getRequest()->headers->get('User-Agent'))) { | ||
return; | ||
} | ||
} | ||
|
||
if (strlen($this->ignoredUrlsPattern)) { | ||
if (preg_match('#'.$this->ignoredUrlsPattern.'#', $event->getRequest()->getUri())) { | ||
if (preg_match('#' . $this->ignoredUrlsPattern . '#', $event->getRequest()->getUri())) { | ||
return; | ||
} | ||
} | ||
|
@@ -172,7 +179,7 @@ public function onConsoleCommand(ConsoleCommandEvent $event) | |
{ | ||
$this->request = null; | ||
|
||
$this->command = $event->getCommand(); | ||
$this->command = $event->getCommand(); | ||
$this->commandInput = $event->getInput(); | ||
|
||
if ($this->reportErrors || $this->reportWarnings) { | ||
|
@@ -198,10 +205,10 @@ protected function setErrorHandlers() | |
/** | ||
* @see http://php.net/set_error_handler | ||
* | ||
* @param integer $level | ||
* @param string $message | ||
* @param string $file | ||
* @param integer $line | ||
* @param int $level | ||
* @param string $message | ||
* @param string $file | ||
* @param int $line | ||
* | ||
* @throws ErrorException | ||
*/ | ||
|
@@ -220,7 +227,7 @@ public function handlePhpError($level, $message, $file, $line, $errcontext) | |
return false; | ||
} | ||
|
||
if(in_array($message, $this->ignoredPhpErrors)) { | ||
if (in_array($message, $this->ignoredPhpErrors)) { | ||
return false; | ||
} | ||
|
||
|
@@ -257,15 +264,16 @@ public function handlePhpFatalErrorAndWarnings() | |
} | ||
|
||
if (in_array($lastError['type'], $errors) && !in_array(@$lastError['message'], $this->ignoredPhpErrors)) { | ||
$exception = new \ErrorException(sprintf('%s: %s in %s line %d', @$this->getErrorString(@$lastError['type']), @$lastError['message'], @$lastError['file'], @$lastError['line']), @$lastError['type'], @$lastError['type'], @$lastError['file'], @$lastError['line']); | ||
$exception = new \ErrorException(sprintf('%s: %s in %s line %d', @$this->getErrorString(@$lastError['type']), @$lastError['message'], @$lastError['file'], @$lastError['line']), @$lastError['type'], @$lastError['type'], @$lastError['file'], @$lastError['line']); | ||
$this->createMailAndSend($exception, $this->request, null, $this->command, $this->commandInput); | ||
} | ||
} | ||
|
||
/** | ||
* Convert the error code to a readable format | ||
* | ||
* @param integer $errorNo | ||
* @param int $errorNo | ||
* | ||
* @return string | ||
*/ | ||
public function getErrorString($errorNo) | ||
|
@@ -314,12 +322,12 @@ public function createMailAndSend($exception, Request $request = null, $context | |
'status_code' => $exception->getCode(), | ||
'context' => $context, | ||
'command' => $command, | ||
'command_input' => $commandInput | ||
'command_input' => $commandInput, | ||
)); | ||
|
||
if($this->request) { | ||
if ($this->request) { | ||
$subject = '[' . $request->headers->get('host') . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage(); | ||
} elseif($this->command) { | ||
} elseif ($this->command) { | ||
$subject = '[' . $this->command->getName() . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage(); | ||
} else { | ||
$subject = 'Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage(); | ||
|
@@ -344,13 +352,14 @@ public function createMailAndSend($exception, Request $request = null, $context | |
/** | ||
* Check last send time | ||
* | ||
* @param FlattenException $exception | ||
* @param FlattenException $exception | ||
* | ||
* @return bool | ||
*/ | ||
private function checkRepeat(FlattenException $exception) | ||
{ | ||
$key = md5($exception->getMessage().':'.$exception->getLine().':'.$exception->getFile()); | ||
$file = $this->errorsDir.'/'.$key; | ||
$key = md5($exception->getMessage() . ':' . $exception->getLine() . ':' . $exception->getFile()); | ||
$file = $this->errorsDir . '/' . $key; | ||
$time = is_file($file) ? file_get_contents($file) : 0; | ||
if ($time < time()) { | ||
file_put_contents($file, time() + $this->repeatTimeout); | ||
|
@@ -373,5 +382,4 @@ protected static function _freeMemory() | |
{ | ||
self::$tmpBuffer = ''; | ||
} | ||
|
||
} |
Oops, something went wrong.