Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
respect our convention
Browse files Browse the repository at this point in the history
  • Loading branch information
benji07 committed Dec 1, 2015
1 parent ef5b5be commit 568aded
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 45 deletions.
30 changes: 30 additions & 0 deletions .php_cs
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__))
;
9 changes: 8 additions & 1 deletion DependencyInjection/Configuration.php
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;
Expand All @@ -10,7 +18,6 @@
*/
class Configuration implements ConfigurationInterface
{

/**
* Get config tree
*
Expand Down
14 changes: 11 additions & 3 deletions DependencyInjection/ElaoErrorNotifierExtension.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?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\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
Expand All @@ -28,7 +36,7 @@ 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') {
Expand Down
8 changes: 8 additions & 0 deletions ElaoErrorNotifierBundle.php
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;
Expand Down
9 changes: 9 additions & 0 deletions Exception/InvokerException.php
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
Expand Down
46 changes: 28 additions & 18 deletions Listener/Notifier.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<?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 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
Expand Down Expand Up @@ -104,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;
}
}
Expand Down Expand Up @@ -171,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) {
Expand Down Expand Up @@ -264,7 +272,8 @@ public function handlePhpFatalErrorAndWarnings()
/**
* Convert the error code to a readable format
*
* @param integer $errorNo
* @param int $errorNo
*
* @return string
*/
public function getErrorString($errorNo)
Expand Down Expand Up @@ -313,15 +322,15 @@ 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) {
$subject = '['.$request->headers->get('host').'] Error '.$exception->getStatusCode().': '.$exception->getMessage();
$subject = '[' . $request->headers->get('host') . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
} elseif ($this->command) {
$subject = '['.$this->command->getName().'] Error '.$exception->getStatusCode().': '.$exception->getMessage();
$subject = '[' . $this->command->getName() . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
} else {
$subject = 'Error '.$exception->getStatusCode().': '.$exception->getMessage();
$subject = 'Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
}

if (function_exists('mb_substr')) {
Expand All @@ -343,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);
Expand Down
53 changes: 30 additions & 23 deletions Twig/DumpyTwigFilter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* This file is part of the Elao ErrorNotifier Bundle
*
* Copyright (C) Elao
*
* @author Elao <[email protected]>
*/
namespace Elao\ErrorNotifierBundle\Twig;

use Elao\ErrorNotifierBundle\Exception\InvokerException;
use Symfony\Component\Yaml\Dumper as YamlDumper;

/**
* Extends Twig with
* {{ "my string, whatever" | pre }} --> wraps with <pre>
Expand All @@ -21,14 +33,9 @@
* Default value is 1. (MAX_DEPTH const)
*
* @see https://gist.github.com/1747036
*
* @author Goutte
*/

namespace Elao\ErrorNotifierBundle\Twig;

use Symfony\Component\Yaml\Dumper as YamlDumper;
use Elao\ErrorNotifierBundle\Exception\InvokerException;

class DumpyTwigFilter extends \Twig_Extension
{
/** @const INLINE : default value for the inline parameter of the YAML dumper aka the expanding-level */
Expand All @@ -52,7 +59,7 @@ public function getFilters()

public function pre($stringable)
{
return "<pre>" . (string) $stringable . "</pre>";
return '<pre>' . (string) $stringable . '</pre>';
}

public function preDump($values)
Expand All @@ -69,7 +76,8 @@ public function preYamlDump($values, $depth = self::MAX_DEPTH)
* Encodes as YAML the passed $input
*
* @param $input
* @param int $inline
* @param int $inline
*
* @return mixed
*/
public function encode($input, $inline = self::INLINE)
Expand All @@ -86,8 +94,9 @@ public function encode($input, $inline = self::INLINE)
/**
* Returns a templating-helper dump of depth-sanitized var as yaml string
*
* @param mixed $value What to dump
* @param int $depth Recursion max depth
* @param mixed $value What to dump
* @param int $depth Recursion max depth
*
* @return string
*/
public function yamlDump($value, $depth = self::MAX_DEPTH)
Expand All @@ -101,8 +110,9 @@ public function yamlDump($value, $depth = self::MAX_DEPTH)
* A bit dirty as this should be in another Class, but hey
*
* @param $value
* @param int $maxRecursionDepth The maximum depth of recursion
* @param int $recursionDepth The depth of recursion (used internally)
* @param int $maxRecursionDepth The maximum depth of recursion
* @param int $recursionDepth The depth of recursion (used internally)
*
* @return array|string
*/
public function sanitize($value, $maxRecursionDepth = self::MAX_DEPTH, $recursionDepth = 0)
Expand Down Expand Up @@ -143,10 +153,9 @@ public function sanitize($value, $maxRecursionDepth = self::MAX_DEPTH, $recursio
}

return $classInfo;

} else { // Get all accessors and their values
$data = array();
$data['class'] = '<span title="' . $class->getName(). '">' . $class->getShortName() . '</span>';
$data = array();
$data['class'] = '<span title="' . $class->getName() . '">' . $class->getShortName() . '</span>';
if ($class->isIterateable()) {
$data['iterateable'] = $this->sanitizeIterateable($value, $maxRecursionDepth, $recursionDepth);
} else {
Expand All @@ -160,34 +169,32 @@ public function sanitize($value, $maxRecursionDepth = self::MAX_DEPTH, $recursio
$methodInfo = ($method->getNumberOfParameters() ? substr($methodInfo, 0, -2) : $methodInfo) . ')';
if (!$method->getNumberOfRequiredParameters()) { // Get the value, we don't need params
try {
$methodValue = $method->invoke($value);
$methodValue = $method->invoke($value);
$data['accessors'][$methodInfo] = $this->sanitize($methodValue, $maxRecursionDepth, $recursionDepth + 1);
} catch (\Exception $e) {
$data['accessors'][$methodInfo] = $this->sanitize(new InvokerException('Couldn\'t invoke method: Exception "' . get_class($e) . '" with message "' . $e->getMessage() . '"'), $maxRecursionDepth, $recursionDepth + 1);
}

} else { // Get only method name and its params
$data['accessors'][] = $methodInfo;
}
}
}

}

return $data;
}
}

if (is_string($value)) {
$value = '(string) '.$value;
$value = '(string) ' . $value;
}

if (is_int($value)) {
$value = '(int) '.$value;
$value = '(int) ' . $value;
}

if (is_float($value)) {
$value = '(float) '.$value;
$value = '(float) ' . $value;
}

if (is_null($value)) {
Expand All @@ -208,9 +215,9 @@ public function sanitize($value, $maxRecursionDepth = self::MAX_DEPTH, $recursio
public function sanitizeIterateable($value, $maxRecursionDepth = self::MAX_DEPTH, $recursionDepth = 0)
{
if ($recursionDepth < $maxRecursionDepth) {
$r = array ();
$r = array();
$arrayCount = count($value);
$count = 0;
$count = 0;

foreach ($value as $k => $v) {
$r[$k] = $this->sanitize($v, $maxRecursionDepth, $recursionDepth + 1);
Expand Down

0 comments on commit 568aded

Please sign in to comment.