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

Commit

Permalink
allow this bundle to work with symfony3
Browse files Browse the repository at this point in the history
  • Loading branch information
benji07 committed Dec 1, 2015
1 parent a312af0 commit ef5b5be
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
4 changes: 3 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function getConfigTreeBuilder()
->arrayNode('to')
->beforeNormalization()
->ifString()
->then(function($value) { return array($value); })
->then(function ($value) {
return array($value);
})
->end()
->isRequired()
->cannotBeEmpty()
Expand Down
7 changes: 2 additions & 5 deletions DependencyInjection/ElaoErrorNotifierExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand All @@ -14,14 +13,11 @@
*/
class ElaoErrorNotifierExtension extends Extension
{

/**
* load configuration
*
* @param array $configs configs
* @param ContainerBuilder $container container
*
* @return void
*/
public function load(array $configs, ContainerBuilder $container)
{
Expand All @@ -36,7 +32,8 @@ public function load(array $configs, ContainerBuilder $container)
$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']));
}
}
}
Expand Down
30 changes: 14 additions & 16 deletions Listener/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Elao\ErrorNotifierBundle\Listener;

use \Swift_Mailer;
use Swift_Mailer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -20,14 +20,13 @@
*/
class Notifier
{

/**
* @var Swift_Mailer $mailer
* @var Swift_Mailer
*/
private $mailer;

/**
* @var EngineInterface $templating
* @var EngineInterface
*/
private $templating;

Expand Down Expand Up @@ -198,10 +197,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
*/
Expand All @@ -220,7 +219,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;
}

Expand Down Expand Up @@ -257,7 +256,7 @@ 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);
}
}
Expand Down Expand Up @@ -317,12 +316,12 @@ public function createMailAndSend($exception, Request $request = null, $context
'command_input' => $commandInput
));

if($this->request) {
$subject = '[' . $request->headers->get('host') . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
} elseif($this->command) {
$subject = '[' . $this->command->getName() . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
if ($this->request) {
$subject = '['.$request->headers->get('host').'] Error '.$exception->getStatusCode().': '.$exception->getMessage();
} elseif ($this->command) {
$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 Down Expand Up @@ -373,5 +372,4 @@ protected static function _freeMemory()
{
self::$tmpBuffer = '';
}

}
15 changes: 8 additions & 7 deletions Twig/DumpyTwigFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ public function yamlDump($value, $depth = self::MAX_DEPTH)
* @param int $recursionDepth The depth of recursion (used internally)
* @return array|string
*/
public function sanitize ($value, $maxRecursionDepth = self::MAX_DEPTH, $recursionDepth = 0)
public function sanitize($value, $maxRecursionDepth = self::MAX_DEPTH, $recursionDepth = 0)
{
if (is_resource($value)) {
return 'Resource';
}

if (is_array($value)) {
return $this->sanitizeIterateable ($value, $maxRecursionDepth, $recursionDepth);
return $this->sanitizeIterateable($value, $maxRecursionDepth, $recursionDepth);
}

if ($value instanceof InvokerException) {
Expand Down Expand Up @@ -148,7 +148,7 @@ public function sanitize ($value, $maxRecursionDepth = self::MAX_DEPTH, $recursi
$data = array();
$data['class'] = '<span title="' . $class->getName(). '">' . $class->getShortName() . '</span>';
if ($class->isIterateable()) {
$data['iterateable'] = $this->sanitizeIterateable ($value, $maxRecursionDepth, $recursionDepth);
$data['iterateable'] = $this->sanitizeIterateable($value, $maxRecursionDepth, $recursionDepth);
} else {
$data['accessors'] = array();
foreach ($class->getMethods() as $method) {
Expand Down Expand Up @@ -205,7 +205,7 @@ public function sanitize ($value, $maxRecursionDepth = self::MAX_DEPTH, $recursi
return $value;
}

public function sanitizeIterateable ($value, $maxRecursionDepth = self::MAX_DEPTH, $recursionDepth = 0)
public function sanitizeIterateable($value, $maxRecursionDepth = self::MAX_DEPTH, $recursionDepth = 0)
{
if ($recursionDepth < $maxRecursionDepth) {
$r = array ();
Expand All @@ -215,15 +215,16 @@ public function sanitizeIterateable ($value, $maxRecursionDepth = self::MAX_DEPT
foreach ($value as $k => $v) {
$r[$k] = $this->sanitize($v, $maxRecursionDepth, $recursionDepth + 1);
$count++;
if($count >= 20) {
if ($count >= 20) {
$r[] = sprintf('... and %s more ...', ($arrayCount - $count));
break;
}
}

return $r;
} else {
$c = count($value); $t = gettype($value);
$c = count($value);
$t = gettype($value);

return $c ? "$t of $c" : "empty $t";
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": "~2.3",
"symfony/console": "~2.3",
"symfony/framework-bundle": "~2.3|~3.0",
"symfony/console": "~2.3|~3.0",
"swiftmailer/swiftmailer": "~5.0"
},

Expand Down

0 comments on commit ef5b5be

Please sign in to comment.