Skip to content
Snippets Groups Projects
Christoph Reiter's avatar
Reiter, Christoph authored
Since we inherit from all the required interfaces anyway, autoconfigure should
just work. No need to confuse users with all the special service tags.
ca651d0f
History

Relay Template Bundle

This Symfony bundle can be used as a template for creating new bundles for the DBP Relay project.

When including this bundle into your API server it will gain the following features:

  • A custom ./bin/console command
  • An example entity
  • Various HTTP methods implemented for that entity

TL;DR

The quickest way to make use of this template bundle is to feed your desired names to one command and generate a ready-to-use bundle with the correct naming.

See Generate DBP Symfony bundle for more information.

Using the Bundle as a Template

  • Copy the repo contents
  • Adjust the package name in composer.json
  • Invent a new PHP namespace and adjust it in all PHP files
  • Rename src/DbpRelayTemplateBundle and DependencyInjection/DbpRelayTemplateExtension to match the new project name

Integration into the API Server

  • Add the repository to your composer.json:
    "repositories": [
        {
            "type": "vcs",
            "url": "git@gitlab.tugraz.at:dbp/relay/dbp-relay-template-bundle.git"
        }
    ],
  • Add the bundle package as a dependency:
composer require dbp/relay-template-bundle=dev-main
  • Add the bundle to your config/bundles.php:
...
Dbp\Relay\TemplateBundle\DbpRelayTemplateBundle::class => ['all' => true],
DBP\API\CoreBundle\DbpCoreBundle::class => ['all' => true],
];
  • Run composer install to clear caches

Configuration

The bundle has a secret_token configuration value that you can specify in your app, either by hardcoding it, or by referencing an environment variable.

For this create config/packages/dbp_relay_template.yaml in the app with the following content:

dbp_relay_template:
  secret_token: 42
  # secret_token: '%env(SECRET_TOKEN)%'

The value gets read in DbpRelayTemplateExtension and passed when creating the MyCustomService service.

For more info on bundle configuration see https://symfony.com/doc/current/bundles/configuration.html

Development & Testing

  • Install dependencies: composer install
  • Run tests: composer test
  • Run linters: composer run lint
  • Run cs-fixer: composer run cs-fix

Bundle dependencies

Don't forget you need to pull down your dependencies in your main application if you are installing packages in a bundle.

# updates and installs dependencies from dbp/relay-template-bundle
composer update dbp/relay-template-bundle