Skip to content

Create Symfony 6.4 example app #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions example/symfony64/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
symfony.lock
vendor
33 changes: 33 additions & 0 deletions example/symfony64/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=8e5e1fbd5c4599ab6850c2f857c97c25
###< symfony/framework-bundle ###
###> bugsnag/bugsnag-symfony ###
BUGSNAG_API_KEY=
###< bugsnag/bugsnag-symfony ###
###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###

###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###< symfony/messenger ###
21 changes: 21 additions & 0 deletions example/symfony64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.DS_Store

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
23 changes: 23 additions & 0 deletions example/symfony64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM php:8.3-fpm

WORKDIR /app

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1

RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
zip \
unzip

COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer

COPY composer.json /app/composer.json
COPY bin /app/bin

RUN composer install

COPY . /app/

CMD ["php", "-S", "0.0.0.0:8000", "-t", "public"]
100 changes: 100 additions & 0 deletions example/symfony64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Running BugSnag with Symfony 6

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

## Using Docker

This example comes with a `Dockerfile` you can use to run the project.
Please first build the image:

```shell
docker build -t bugsnag-symfony6 .
```

Then run the container:

```shell
docker run -it --rm -p 8000:8000 bugsnag-symfony6
```

You can then access the application at [http://localhost:8000](http://localhost:8000).

## Manual installation

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

2. Install dependencies using composer

```shell
composer install
```

### Running the example

To run the example:

```shell
symfony server:start
```

Or for the command example:

```shell
php bin/console app:crash
```

## Configuring BugSnag

There are two ways of configuring your BugSnag client.

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

```yaml
bugsnag:
api_key: 'YOUR_API_KEY'
auto_notify: true
```

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:

```env
BUGSNAG_API_KEY=YOUR_API_KEY_HERE
```

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

In Symfony 6 the BugSnag bundle should be automatically registered in the `config/bundles.php` file:

```php
return [
// ...
Bugsnag\BugsnagBundle\BugsnagBundle::class => ['all' => true],
];
```

BugSnag will now be set up and ready to notify of any exceptions.

## Manually Acquiring the BugSnag Bundle

In order to use BugSnag in any of your classes you will need to require it via dependency injection.

In your services.yaml file, bind the Bugsnag\Client class to the @bugsnag service:

```yaml
services:
# resolve "Bugsnag\Client" to the BugSnag service
Bugsnag\Client: '@bugsnag'
```

Any of your classes requiring BugSnag can use the type Bugsnag\Client to access it:

```php
private $bugsnag;

public function __construct(\Bugsnag\Client $bugsnag)
{
$this->bugsnag = $bugsnag;
}
```

Which allows BugSnag to be used within the class as you would any other property.
17 changes: 17 additions & 0 deletions example/symfony64/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
19 changes: 19 additions & 0 deletions example/symfony64/bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
} else {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
99 changes: 99 additions & 0 deletions example/symfony64/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"bugsnag/bugsnag-symfony": "^1.6",
"doctrine/annotations": "^2.0",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.21",
"symfony/asset": "6.4.*",
"symfony/console": "6.4.*",
"symfony/dotenv": "6.4.*",
"symfony/expression-language": "6.4.*",
"symfony/flex": "^2",
"symfony/form": "6.4.*",
"symfony/framework-bundle": "6.4.*",
"symfony/http-client": "6.4.*",
"symfony/intl": "6.4.*",
"symfony/mailer": "6.4.*",
"symfony/messenger": "6.4.*",
"symfony/mime": "6.4.*",
"symfony/monolog-bundle": "^3.0",
"symfony/notifier": "6.4.*",
"symfony/process": "6.4.*",
"symfony/property-access": "6.4.*",
"symfony/property-info": "6.4.*",
"symfony/runtime": "6.4.*",
"symfony/security-bundle": "6.4.*",
"symfony/serializer": "6.4.*",
"symfony/string": "6.4.*",
"symfony/translation": "6.4.*",
"symfony/twig-bundle": "6.4.*",
"symfony/validator": "6.4.*",
"symfony/web-link": "6.4.*",
"symfony/yaml": "6.4.*"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.4.*"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.4.*",
"symfony/css-selector": "6.4.*",
"symfony/debug-bundle": "6.4.*",
"symfony/maker-bundle": "^1.0",
"symfony/phpunit-bridge": "^6.2",
"symfony/stopwatch": "6.4.*",
"symfony/web-profiler-bundle": "6.4.*"
}
}
Loading