Skip to content

Commit 2105c29

Browse files
committed
README, services.yaml and DefaultController updated to reflect current BugSnag Symfony integration docs. Routes tested and exceptions reported successfully.
1 parent dce795d commit 2105c29

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

example/symfony54/README.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
# Running Bugsnag with Symfony 5
1+
# Running BugSnag with Symfony 6
22

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/).
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/).
44

55

66
## Installing dependencies
77

88
1. Install composer, following the instructions provided in the [composer documentation](http://getcomposer.org/doc/01-basic-usage.md)
99

10-
2. Install bugsnag using composer
10+
2. Install BugSnag using composer
1111

1212
```shell
1313
composer install
1414
```
1515

16-
## Configuring Bugsnag
16+
## Configuring BugSnag
1717

18-
There are two ways of configuring your Bugsnag client.
18+
There are two ways of configuring your BugSnag client.
1919

2020
1. Set the configuration options in `config/packages/bugsnag.yaml`. These values will automatically be loaded in when the application starts.
2121

2222
```yaml
2323
bugsnag:
24-
api_key: YOUR_API_KEY_HERE
24+
api_key: 'YOUR_API_KEY'
2525
auto_notify: true
2626
```
2727

@@ -31,43 +31,40 @@ bugsnag:
3131
BUGSNAG_API_KEY=YOUR_API_KEY_HERE
3232
```
3333
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/).
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/).
3535
36-
In Symfony 5 the Bugsnag bundle should be automatically registered in the `config/bundles.php` file:
36+
In Symfony 6 the BugSnag bundle should be automatically registered in the `config/bundles.php` file:
3737
```php
3838
return [
3939
// ...
4040
Bugsnag\BugsnagBundle\BugsnagBundle::class => ['all' => true],
4141
];
4242
```
4343

44-
Bugsnag will now be set up and ready to notify of any exceptions.
44+
BugSnag will now be set up and ready to notify of any exceptions.
4545

46-
## Manually Acquiring the Bugsnag Bundle
46+
## Manually Acquiring the BugSnag Bundle
4747

48-
In order to manually use Bugsnag in any of your controllers you will need to require it via dependency injection.
48+
In order to use BugSnag in any of your classes you will need to require it via dependency injection.
4949

50-
In your `services.yml` file, you should bind the Bugsnag instance to your service parameters by:
50+
In your services.yaml file, bind the Bugsnag\Client class to the @bugsnag service:
5151
```yaml
5252
services:
53-
# default configuration for services in *this* file
54-
_defaults:
55-
# ...
56-
bind:
57-
$bugsnag: '@bugsnag'
53+
# resolve "Bugsnag\Client" to the BugSnag service
54+
Bugsnag\Client: '@bugsnag'
5855
```
5956
60-
This will make any methods with a `$bugsnag` argument be passed the Bugsnag bundle:
61-
57+
Any of your classes requiring BugSnag can use the type Bugsnag\Client to access it:
6258
```php
63-
protected $bugsnag;
59+
private $bugsnag;
6460

65-
public function __construct($bugsnag) {
61+
public function __construct(\Bugsnag\Client $bugsnag)
62+
{
6663
$this->bugsnag = $bugsnag;
6764
}
6865
```
6966

70-
Which allows Bugsnag to be used within the class as you would any other property.
67+
Which allows BugSnag to be used within the class as you would any other property.
7168

7269
## Running the example
7370

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/DefaultController.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
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
}
19+
1920

2021
/**
2122
* @Route("/", name="homepage")
2223
*/
2324
public function index()
2425
{
25-
return new Response('Welcome to the Bugsnag Symfony 5 example. Visit the
26+
return new Response('Welcome to the BugSnag Symfony 5 example. Visit the
2627
file "src/Controller/DefaultController" to see how certain functions
2728
are implemented, and routes they can be tested on.');
2829
}
@@ -32,7 +33,7 @@ public function index()
3233
*/
3334
public function crash()
3435
{
35-
throw new RuntimeException('It crashed! Go to your Bugsnag dashboard to view the exception');
36+
throw new RuntimeException('It crashed! Go to your BugSnag dashboard to view the exception');
3637
}
3738

3839
/**
@@ -49,7 +50,7 @@ public function callback()
4950
]);
5051
});
5152

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

5556
/**
@@ -59,7 +60,7 @@ public function notify()
5960
{
6061
$this->bugsnag->notifyException(new RuntimeException("It didn't crash!"));
6162

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

6566
/**
@@ -76,7 +77,7 @@ public function metadata()
7677
]);
7778
});
7879

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

8283
/**
@@ -88,6 +89,6 @@ public function severity()
8889
$report->setSeverity('info');
8990
});
9091

91-
return new Response("It didn't crash, but check your Bugsnag dashboard for the manual notification, and check the severity of the report");
92+
return new Response("It didn't crash, but check your BugSnag dashboard for the manual notification, and check the severity of the report");
9293
}
9394
}

0 commit comments

Comments
 (0)