Skip to content

Commit 39e0d99

Browse files
committed
Initial commit
0 parents  commit 39e0d99

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Matyx
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# sentry-nette
2+
Integrates Sentry error handlers to nette (alse registers [Raven_client](https://github.com/getsentry/sentry-php) as a service)
3+
4+
## Install
5+
```bash
6+
composer require matyx/sentry-nette
7+
```
8+
9+
## Configure
10+
Add following to your **config.local.neon**
11+
```yaml
12+
#register extension
13+
extensions:
14+
sentry: Matyx\Sentry\SentryExtension
15+
16+
17+
sentry:
18+
dsn: https://__REPLACE_WITH_TOKEN__
19+
```

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "matyx/sentry-nette",
3+
"type": "library",
4+
"require": {
5+
"sentry/sentry": "^1.5",
6+
"nette/di": "^2.4"
7+
},
8+
"license": "MIT",
9+
"authors": [
10+
{
11+
"name": "Martin Macho",
12+
"email": "matyxcz@gmail.com"
13+
}
14+
],
15+
"minimum-stability": "stable",
16+
"autoload": {
17+
"classmap": ["src/"]
18+
}
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Matyx\Sentry;
4+
5+
use Nette;
6+
use Nette\DI\CompilerExtension;
7+
8+
class SentryExtension extends CompilerExtension {
9+
/** @var boolean Enable this extension? */
10+
private $enable = true;
11+
12+
public function beforeCompile() {
13+
$config = $this->getConfig();
14+
15+
if(!isset($config['dsn'])) {
16+
$this->enable = false;
17+
return;
18+
}
19+
20+
$builder = $this->getContainerBuilder();
21+
22+
$builder->addDefinition($this->prefix('ravenClient'))->setClass(\Raven_Client::class, [$config['dsn']]);
23+
}
24+
25+
public function afterCompile(Nette\PhpGenerator\ClassType $class) {
26+
if(!$this->enable) return;
27+
28+
$initialize = $class->methods['initialize'];
29+
30+
$initialize->addBody('$ravenErrorHandler = new \Raven_ErrorHandler($this->getByType(\Raven_Client::class));');
31+
$initialize->addBody('$ravenErrorHandler->registerExceptionHandler();');
32+
$initialize->addBody('$ravenErrorHandler->registerErrorHandler();');
33+
$initialize->addBody('$ravenErrorHandler->registerShutdownFunction();');
34+
}
35+
36+
}

0 commit comments

Comments
 (0)