Skip to content

Commit df24965

Browse files
authored
Merge pull request #166 from bugsnag/SUP-3062/create-symfony-62-example
Create Symfony 6.4 example app
2 parents 772e66b + 134eede commit df24965

34 files changed

+998
-0
lines changed

example/symfony64/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
symfony.lock
3+
vendor

example/symfony64/.env

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the latter taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
# https://symfony.com/doc/current/configuration/secrets.html
13+
#
14+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
15+
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
16+
17+
###> symfony/framework-bundle ###
18+
APP_ENV=dev
19+
APP_SECRET=8e5e1fbd5c4599ab6850c2f857c97c25
20+
###< symfony/framework-bundle ###
21+
###> bugsnag/bugsnag-symfony ###
22+
BUGSNAG_API_KEY=
23+
###< bugsnag/bugsnag-symfony ###
24+
###> symfony/mailer ###
25+
# MAILER_DSN=null://null
26+
###< symfony/mailer ###
27+
28+
###> symfony/messenger ###
29+
# Choose one of the transports below
30+
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
31+
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
32+
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
33+
###< symfony/messenger ###

example/symfony64/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
/composer.lock
3+
4+
###> symfony/framework-bundle ###
5+
/.env.local
6+
/.env.local.php
7+
/.env.*.local
8+
/config/secrets/prod/prod.decrypt.private.php
9+
/public/bundles/
10+
/var/
11+
/vendor/
12+
###< symfony/framework-bundle ###
13+
14+
###> phpunit/phpunit ###
15+
/phpunit.xml
16+
.phpunit.result.cache
17+
###< phpunit/phpunit ###
18+
19+
###> symfony/phpunit-bridge ###
20+
.phpunit.result.cache
21+
/phpunit.xml
22+
###< symfony/phpunit-bridge ###

example/symfony64/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM php:8.3-fpm
2+
3+
WORKDIR /app
4+
5+
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
6+
ENV COMPOSER_ALLOW_SUPERUSER=1
7+
8+
RUN apt-get update && \
9+
apt-get install -y --no-install-recommends \
10+
git \
11+
zip \
12+
unzip
13+
14+
COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer
15+
16+
COPY composer.json /app/composer.json
17+
COPY bin /app/bin
18+
19+
RUN composer install
20+
21+
COPY . /app/
22+
23+
CMD ["php", "-S", "0.0.0.0:8000", "-t", "public"]

example/symfony64/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Running BugSnag with Symfony 6
2+
3+
This example shows how to integrate BugSnag with Symfony 6. 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+
Symfony 6.4 requires PHP 8.1.0 or higher. Alternatively, you can run this using Docker.
5+
6+
## Using Docker
7+
8+
This example comes with a `Dockerfile` you can use to run the project.
9+
Please first build the image:
10+
11+
```shell
12+
docker build -t bugsnag-symfony6 .
13+
```
14+
15+
Then run the container:
16+
17+
```shell
18+
docker run -it --rm -p 8000:8000 bugsnag-symfony6
19+
```
20+
21+
You can then access the application at [http://localhost:8000](http://localhost:8000).
22+
23+
## Manual installation
24+
25+
1. Install composer, following the instructions provided in the [composer documentation](http://getcomposer.org/doc/01-basic-usage.md)
26+
27+
2. Install dependencies using composer
28+
29+
```shell
30+
composer install
31+
```
32+
33+
### Running the example
34+
35+
To run the example:
36+
37+
```shell
38+
symfony server:start
39+
```
40+
41+
Or for the command example:
42+
43+
```shell
44+
php bin/console app:crash
45+
```
46+
47+
## Configuring BugSnag
48+
49+
There are two ways of configuring your BugSnag client.
50+
51+
1. Set the configuration options in `config/packages/bugsnag.yaml`. These values will automatically be loaded in when the application starts.
52+
53+
```yaml
54+
bugsnag:
55+
api_key: 'YOUR_API_KEY'
56+
auto_notify: true
57+
```
58+
59+
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:
60+
61+
```env
62+
BUGSNAG_API_KEY=YOUR_API_KEY_HERE
63+
```
64+
65+
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/).
66+
67+
In Symfony 6 the BugSnag bundle should be automatically registered in the `config/bundles.php` file:
68+
69+
```php
70+
return [
71+
// ...
72+
Bugsnag\BugsnagBundle\BugsnagBundle::class => ['all' => true],
73+
];
74+
```
75+
76+
BugSnag will now be set up and ready to notify of any exceptions.
77+
78+
## Manually Acquiring the BugSnag Bundle
79+
80+
In order to use BugSnag in any of your classes you will need to require it via dependency injection.
81+
82+
In your services.yaml file, bind the Bugsnag\Client class to the @bugsnag service:
83+
84+
```yaml
85+
services:
86+
# resolve "Bugsnag\Client" to the BugSnag service
87+
Bugsnag\Client: '@bugsnag'
88+
```
89+
90+
Any of your classes requiring BugSnag can use the type Bugsnag\Client to access it:
91+
92+
```php
93+
private $bugsnag;
94+
95+
public function __construct(\Bugsnag\Client $bugsnag)
96+
{
97+
$this->bugsnag = $bugsnag;
98+
}
99+
```
100+
101+
Which allows BugSnag to be used within the class as you would any other property.

example/symfony64/bin/console

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
7+
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
8+
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
9+
}
10+
11+
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
12+
13+
return function (array $context) {
14+
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
15+
16+
return new Application($kernel);
17+
};

example/symfony64/bin/phpunit

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (!ini_get('date.timezone')) {
5+
ini_set('date.timezone', 'UTC');
6+
}
7+
8+
if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
9+
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
10+
require PHPUNIT_COMPOSER_INSTALL;
11+
PHPUnit\TextUI\Command::main();
12+
} else {
13+
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
14+
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
15+
exit(1);
16+
}
17+
18+
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
19+
}

example/symfony64/composer.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"type": "project",
3+
"license": "proprietary",
4+
"minimum-stability": "dev",
5+
"prefer-stable": true,
6+
"require": {
7+
"php": ">=8.1",
8+
"ext-ctype": "*",
9+
"ext-iconv": "*",
10+
"bugsnag/bugsnag-symfony": "^1.6",
11+
"doctrine/annotations": "^2.0",
12+
"phpdocumentor/reflection-docblock": "^5.3",
13+
"phpstan/phpdoc-parser": "^1.21",
14+
"symfony/asset": "6.4.*",
15+
"symfony/console": "6.4.*",
16+
"symfony/dotenv": "6.4.*",
17+
"symfony/expression-language": "6.4.*",
18+
"symfony/flex": "^2",
19+
"symfony/form": "6.4.*",
20+
"symfony/framework-bundle": "6.4.*",
21+
"symfony/http-client": "6.4.*",
22+
"symfony/intl": "6.4.*",
23+
"symfony/mailer": "6.4.*",
24+
"symfony/messenger": "6.4.*",
25+
"symfony/mime": "6.4.*",
26+
"symfony/monolog-bundle": "^3.0",
27+
"symfony/notifier": "6.4.*",
28+
"symfony/process": "6.4.*",
29+
"symfony/property-access": "6.4.*",
30+
"symfony/property-info": "6.4.*",
31+
"symfony/runtime": "6.4.*",
32+
"symfony/security-bundle": "6.4.*",
33+
"symfony/serializer": "6.4.*",
34+
"symfony/string": "6.4.*",
35+
"symfony/translation": "6.4.*",
36+
"symfony/twig-bundle": "6.4.*",
37+
"symfony/validator": "6.4.*",
38+
"symfony/web-link": "6.4.*",
39+
"symfony/yaml": "6.4.*"
40+
},
41+
"config": {
42+
"allow-plugins": {
43+
"php-http/discovery": true,
44+
"symfony/flex": true,
45+
"symfony/runtime": true
46+
},
47+
"sort-packages": true
48+
},
49+
"autoload": {
50+
"psr-4": {
51+
"App\\": "src/"
52+
}
53+
},
54+
"autoload-dev": {
55+
"psr-4": {
56+
"App\\Tests\\": "tests/"
57+
}
58+
},
59+
"replace": {
60+
"symfony/polyfill-ctype": "*",
61+
"symfony/polyfill-iconv": "*",
62+
"symfony/polyfill-php72": "*",
63+
"symfony/polyfill-php73": "*",
64+
"symfony/polyfill-php74": "*",
65+
"symfony/polyfill-php80": "*",
66+
"symfony/polyfill-php81": "*"
67+
},
68+
"scripts": {
69+
"auto-scripts": {
70+
"cache:clear": "symfony-cmd",
71+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
72+
},
73+
"post-install-cmd": [
74+
"@auto-scripts"
75+
],
76+
"post-update-cmd": [
77+
"@auto-scripts"
78+
]
79+
},
80+
"conflict": {
81+
"symfony/symfony": "*"
82+
},
83+
"extra": {
84+
"symfony": {
85+
"allow-contrib": false,
86+
"require": "6.4.*"
87+
}
88+
},
89+
"require-dev": {
90+
"phpunit/phpunit": "^9.5",
91+
"symfony/browser-kit": "6.4.*",
92+
"symfony/css-selector": "6.4.*",
93+
"symfony/debug-bundle": "6.4.*",
94+
"symfony/maker-bundle": "^1.0",
95+
"symfony/phpunit-bridge": "^6.2",
96+
"symfony/stopwatch": "6.4.*",
97+
"symfony/web-profiler-bundle": "6.4.*"
98+
}
99+
}

example/symfony64/config/bundles.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
return [
4+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
5+
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
6+
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
7+
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
8+
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
9+
Bugsnag\BugsnagBundle\BugsnagBundle::class => ['all' => true],
10+
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
11+
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
12+
];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bugsnag:
2+
api_key: "YOUR_API_KEY"
3+
auto_notify: true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
framework:
2+
cache:
3+
# Unique name of your app: used to compute stable namespaces for cache keys.
4+
#prefix_seed: your_vendor_name/app_name
5+
6+
# The "app" cache stores to the filesystem by default.
7+
# The data in this cache should persist between deploys.
8+
# Other options include:
9+
10+
# Redis
11+
#app: cache.adapter.redis
12+
#default_redis_provider: redis://localhost
13+
14+
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
15+
#app: cache.adapter.apcu
16+
17+
# Namespaced pools use the above "app" backend by default
18+
#pools:
19+
#my.dedicated.cache: null
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
when@dev:
2+
debug:
3+
# Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser.
4+
# See the "server:dump" command to start a new server.
5+
dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# see https://symfony.com/doc/current/reference/configuration/framework.html
2+
framework:
3+
secret: '%env(APP_SECRET)%'
4+
#csrf_protection: true
5+
http_method_override: false
6+
handle_all_throwables: true
7+
8+
# Enables session support. Note that the session will ONLY be started if you read or write from it.
9+
# Remove or comment this section to explicitly disable session support.
10+
session:
11+
handler_id: null
12+
cookie_secure: auto
13+
cookie_samesite: lax
14+
storage_factory_id: session.storage.factory.native
15+
16+
#esi: true
17+
#fragments: true
18+
php_errors:
19+
log: true
20+
21+
when@test:
22+
framework:
23+
test: true
24+
session:
25+
storage_factory_id: session.storage.factory.mock_file
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
mailer:
3+
dsn: '%env(MAILER_DSN)%'

0 commit comments

Comments
 (0)