Skip to content

Commit

Permalink
fix for dsn parameter required issue (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
wimvds committed Oct 29, 2013
1 parent d4ce12f commit d874166
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
8 changes: 4 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function getConfigTreeBuilder()
$rootNode
->children()
->booleanNode('enabled')
->defaultValue(false)
->end()
->defaultFalse()
->end()
->scalarNode('dsn')
->cannotBeEmpty()
->end()
->defaultNull()
->end()
->end();

// Here you should define the parameters that are allowed to
Expand Down
12 changes: 9 additions & 3 deletions DependencyInjection/KunstmaanSentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

Expand All @@ -21,11 +22,16 @@ public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$container->setParameter($this->getAlias(). '.enabled', $config['enabled']);
$container->setParameter($this->getAlias(). '.dsn', $config['dsn']);

if ($this->isConfigEnabled($container, $config)) {
if (!array_key_exists('dsn', $config) || empty($config['dsn'])) {
throw new InvalidArgumentException("The kunstmaan_sentry config array 'dsn' key is required.");
}
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
}

}
}
17 changes: 4 additions & 13 deletions EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ class ExceptionListener
*/
protected $client;

/**
* @var boolean $enabled
*/
protected $enabled;

/**
* @param Raven $client
*/
public function __construct(Raven $client, $enabled)
public function __construct(Raven $client)
{
$this->client = $client;
$this->enabled = $enabled;
}

/**
Expand All @@ -44,11 +38,8 @@ public function onKernelException(GetResponseForExceptionEvent $event)
if ($event->getRequest()->attributes->has("_controller")) {
$culprit = $event->getRequest()->attributes->get("_controller");
}
if (!$this->enabled) {
return array($exception, $culprit, $this->client->getEnvironment());
} else {
$event_id = $this->client->getIdent($this->client->captureException($exception, $culprit, $this->client->getEnvironment()));
return error_log("[$event_id] " . $exception->getMessage() . ' in: ' . $exception->getFile() . ':' . $exception->getLine());
}
$event_id = $this->client->getIdent($this->client->captureException($exception, $culprit, $this->client->getEnvironment()));

return error_log("[$event_id] " . $exception->getMessage() . ' in: ' . $exception->getFile() . ':' . $exception->getLine());
}
}
1 change: 0 additions & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<service id="sentry.exception_listener" class="%sentry.exception_listener.class%">
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" />
<argument type="service" id="sentry.client" />
<argument>%kunstmaan_sentry.enabled%</argument>
</service>
</services>
</container>

0 comments on commit d874166

Please sign in to comment.