Skip to content

Commit 772e66b

Browse files
authored
Merge pull request #167 from bugsnag/SUP-3042/upgrade-symfony50-example-to-54
Symfony dependencies in composer.json updated to 5.4
2 parents 128a0a3 + 5baaf91 commit 772e66b

File tree

26 files changed

+110
-102
lines changed

26 files changed

+110
-102
lines changed

example/symfony50/README.md

Lines changed: 0 additions & 84 deletions
This file was deleted.

example/symfony54/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Running BugSnag with Symfony 5
2+
3+
This example shows how to integrate BugSnag with Symfony 5. Full instructions on how to set BugSnag up with Symfony can be found in [the official BugSnag documentation](https://docs.bugsnag.com/platforms/php/symfony/).
4+
5+
6+
## Installing dependencies
7+
8+
1. Install composer, following the instructions provided in the [composer documentation](http://getcomposer.org/doc/01-basic-usage.md)
9+
10+
2. Install BugSnag using composer
11+
12+
```shell
13+
composer install
14+
```
15+
16+
## Configuring BugSnag
17+
18+
There are two ways of configuring your BugSnag client.
19+
20+
1. Set the configuration options in `config/packages/bugsnag.yaml`. These values will automatically be loaded in when the application starts.
21+
22+
```yaml
23+
bugsnag:
24+
api_key: 'YOUR_API_KEY'
25+
auto_notify: true
26+
```
27+
28+
2. Use environment variables. In this example you can set the `BUGSNAG_API_KEY` environment variable to your api key. This can also be set in the applications `.env` file:
29+
30+
```
31+
BUGSNAG_API_KEY=YOUR_API_KEY_HERE
32+
```
33+
34+
More information about configuring BugSnag can be found in [the configuration section of the BugSnag documentation](https://docs.bugsnag.com/platforms/php/symfony/configuration-options/).
35+
36+
In Symfony 5 the BugSnag bundle should be automatically registered in the `config/bundles.php` file:
37+
```php
38+
return [
39+
// ...
40+
Bugsnag\BugsnagBundle\BugsnagBundle::class => ['all' => true],
41+
];
42+
```
43+
44+
BugSnag will now be set up and ready to notify of any exceptions.
45+
46+
## Manually Acquiring the BugSnag Bundle
47+
48+
In order to use BugSnag in any of your classes you will need to require it via dependency injection.
49+
50+
In your services.yaml file, bind the Bugsnag\Client class to the @bugsnag service:
51+
```yaml
52+
services:
53+
# resolve "Bugsnag\Client" to the BugSnag service
54+
Bugsnag\Client: '@bugsnag'
55+
```
56+
57+
Any of your classes requiring BugSnag can use the type Bugsnag\Client to access it:
58+
```php
59+
private $bugsnag;
60+
61+
public function __construct(\Bugsnag\Client $bugsnag)
62+
{
63+
$this->bugsnag = $bugsnag;
64+
}
65+
```
66+
67+
Which allows BugSnag to be used within the class as you would any other property.
68+
69+
## Running the example
70+
71+
To run the example:
72+
73+
```shell
74+
symfony server:start
75+
```
76+
77+
Or for the command example:
78+
79+
```shell
80+
php bin/console app:crash
81+
```
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@
88
"ext-iconv": "*",
99
"bugsnag/bugsnag-symfony": "^1.5.0",
1010
"sensio/framework-extra-bundle": "^5.5@dev",
11-
"symfony/console": "5.0.*",
12-
"symfony/dotenv": "5.0.*",
11+
"symfony/console": "5.4.*",
12+
"symfony/dotenv": "5.4.*",
1313
"symfony/flex": "^1.3.1",
14-
"symfony/framework-bundle": "5.0.*",
15-
"symfony/yaml": "5.0.*"
14+
"symfony/framework-bundle": "5.4.*",
15+
"symfony/routing": "^5.4",
16+
"symfony/yaml": "5.4.*"
1617
},
1718
"repositories": [
1819
{
1920
"type": "vcs",
2021
"url": "git@github.com:bugsnag/bugsnag-symfony.git"
2122
}
2223
],
23-
"require-dev": {
24-
},
2524
"config": {
2625
"preferred-install": {
2726
"*": "dist"
2827
},
29-
"sort-packages": true
28+
"sort-packages": true,
29+
"allow-plugins": {
30+
"symfony/flex": false
31+
}
3032
},
3133
"autoload": {
3234
"psr-4": {
@@ -65,7 +67,7 @@
6567
"extra": {
6668
"symfony": {
6769
"allow-contrib": false,
68-
"require": "5.0.*"
70+
"require": "5.4.*"
6971
}
7072
}
7173
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)