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

26 files changed

+110
-102
lines changed

example/symfony50/README.md

Lines changed: 0 additions & 84 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

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+
```
File renamed without changes.

example/symfony50/composer.json renamed to example/symfony54/composer.json

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": "[email protected]: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
}

example/symfony54/config/preload.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
if (file_exists(dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php')) {
4+
require dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php';
5+
}
6+
7+
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
8+
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
9+
}

example/symfony50/config/services.yaml renamed to example/symfony54/config/services.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
parameters:
77

88
services:
9+
# resolve "Bugsnag\Client" to the BugSnag service
10+
Bugsnag\Client: '@bugsnag'
911
# default configuration for services in *this* file
1012
_defaults:
1113
autowire: true # Automatically injects dependencies in your services.
1214
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
13-
bind:
14-
$bugsnag: '@bugsnag'
1515

1616
# makes classes in src/ available to be used as services
1717
# this creates a service per class whose id is the fully-qualified class name

example/symfony54/src/Controller/.gitignore

Whitespace-only changes.

example/symfony50/src/Controller/DefaultController.php renamed to example/symfony54/src/Controller/DefaultController.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
class DefaultController extends AbstractController
1212
{
13-
protected $bugsnag;
13+
private $bugsnag;
1414

15-
public function __construct($bugsnag)
15+
public function __construct(\Bugsnag\Client $bugsnag)
1616
{
1717
$this->bugsnag = $bugsnag;
1818
}
@@ -22,7 +22,7 @@ public function __construct($bugsnag)
2222
*/
2323
public function index()
2424
{
25-
return new Response('Welcome to the Bugsnag Symfony 5 example. Visit the
25+
return new Response('Welcome to the BugSnag Symfony 5 example. Visit the
2626
file "src/Controller/DefaultController" to see how certain functions
2727
are implemented, and routes they can be tested on.');
2828
}
@@ -32,7 +32,7 @@ public function index()
3232
*/
3333
public function crash()
3434
{
35-
throw new RuntimeException('It crashed! Go to your Bugsnag dashboard to view the exception');
35+
throw new RuntimeException('It crashed! Go to your BugSnag dashboard to view the exception');
3636
}
3737

3838
/**
@@ -49,7 +49,7 @@ public function callback()
4949
]);
5050
});
5151

52-
throw new RuntimeException('It crashed! Go to your Bugsnag dashboard to view the exception and metadata');
52+
throw new RuntimeException('It crashed! Go to your BugSnag dashboard to view the exception and metadata');
5353
}
5454

5555
/**
@@ -59,7 +59,7 @@ public function notify()
5959
{
6060
$this->bugsnag->notifyException(new RuntimeException("It didn't crash!"));
6161

62-
return new Response("It didn't crash, but check your Bugsnag dashboard for the manual notification");
62+
return new Response("It didn't crash, but check your BugSnag dashboard for the manual notification");
6363
}
6464

6565
/**
@@ -76,7 +76,7 @@ public function metadata()
7676
]);
7777
});
7878

79-
return new Response("It didn't crash, but check your Bugsnag dashboard for the manual notification with additional metadata");
79+
return new Response("It didn't crash, but check your BugSnag dashboard for the manual notification with additional metadata");
8080
}
8181

8282
/**
@@ -88,6 +88,6 @@ public function severity()
8888
$report->setSeverity('info');
8989
});
9090

91-
return new Response("It didn't crash, but check your Bugsnag dashboard for the manual notification, and check the severity of the report");
91+
return new Response("It didn't crash, but check your BugSnag dashboard for the manual notification, and check the severity of the report");
9292
}
9393
}
File renamed without changes.

0 commit comments

Comments
 (0)