• Stars
    star
    908
  • Rank 48,296 (Top 1.0 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Symfony Recipes Repository

Symfony Recipes

Symfony recipes allow the automation of Composer packages configuration via the Symfony Flex Composer plugin.

This repository contains "official" recipes for Composer packages endorsed by the Symfony Core Team. For contributed recipes, see the contrib repository.

See RECIPES.md for a full list of recipes that live in this repository.

Creating Recipes

Symfony recipes consist of a manifest.json config file and, optionally, any number of files and directories. Recipes must be stored on their own repositories, outside of your Composer package repository. They must follow the vendor/package/version/ directory structure, where version is the minimum version supported by the recipe.

The following example shows the real directory structure of some Symfony recipes:

symfony/
    console/
        3.3/
            bin/
            manifest.json
    framework-bundle/
        3.3/
            config/
            public/
            src/
            manifest.json
    requirements-checker/
        1.0/
            manifest.json

All the manifest.json file contents are optional and they are divided into options and configurators.

Note

Don't create a recipe for Symfony bundles if the only configuration in the manifest is the registration of the bundle for all environments, as this is done automatically.

Note

When creating a recipe, don't create bundle config files under config/packages/ when no options are set.

Updating Recipes

When a recipe needs to be updated, we try to minimize the impact for the current versions. Creating a new project with a set of dependencies should always use the same recipes to avoid differences between the generated code and the existing documentation, blog posts, videos for these versions.

As a rule of thumb, consider the same principles as semantic versioning:

  • Only change an existing recipe for a version in case of a bug (typos, mis-configuration, ...);
  • If the change is about a new best practice or a different way of doing something, do it for the next version of the dependency.

Options

aliases option

This option (not available in the recipes-contrib repository) defines one or more alternative names that can be used to install the dependency. Its value is an array of strings. For example, if a dependency is published as acme-inc/acme-log-monolog-handler, it can define one or more aliases to make it easier to install:

{
    "aliases": ["acme-log", "acmelog"]
}

Developers can now install this dependency with composer require acme-log.

Configurators

Recipes define the different tasks executed when installing a dependency, such as running commands, copying files or adding new environment variables. Recipes only contain the tasks needed to install and configure the dependency because Symfony is smart enough to reverse those tasks when uninstalling and unconfiguring the dependencies.

There are several types of tasks, which are called configurators: copy-from-recipe, copy-from-package, bundles, env, container composer-scripts, gitignore, and post-install-output.

bundles Configurator

Enables one or more bundles in the Symfony application by appending them to the bundles.php file. Its value is an associative array where the key is the bundle class name and the value is an array of environments where it must be enabled. The supported environments are dev, prod, test and all (which enables the bundle in all environments):

{
    "bundles": {
        "Symfony\\Bundle\\DebugBundle\\DebugBundle": ["dev", "test"],
        "Symfony\\Bundle\\MonologBundle\\MonologBundle": ["all"]
    }
}

The previous recipe is transformed into the following PHP code:

// config/bundles.php
return [
    'Symfony\Bundle\DebugBundle\DebugBundle' => ['dev' => true, 'test' => true],
    'Symfony\Bundle\MonologBundle\MonologBundle' => ['all' => true],
];

container Configurator

Adds new container parameters in the services.yaml file by adding your parameters in the container option.

This example creates a new locale container parameter with a default value in your container:

{
    "container": {
        "locale": "en"
    }
}

copy-from-package Configurator

Copies files or directories from the Composer package contents to the Symfony application. It's defined as an associative array where the key is the original file/directory and the value is the target file/directory.

Caution

Copying files from the package should be avoided, except for some very specific use cases. Copying PHP files under the project's src/ directory is almost always a bad idea; consider adding a command in your bundle that is able to generate such PHP files instead.

This example copies the bin/check.php script of the package into the binary directory of the application:

{
    "copy-from-package": {
        "bin/check.php": "%BIN_DIR%/check.php"
    }
}

The %BIN_DIR% string is a placeholder that, when installing the recipe, is turned into the absolute path of the binaries directory of the Symfony app. These are the available placeholders: %BIN_DIR%, %CONF_DIR%, %CONFIG_DIR%, %SRC_DIR% %VAR_DIR% and %PUBLIC_DIR%.

Recipes must use these placeholders instead of hardcoding the paths to be truly reusable. The placeholder values can be overridden in the extra section of your composer.json file (where you can define your own placeholders too):

// composer.json
{
    "...": "...",

    "extra": {
        // overriding the value of the default placeholders
        "bin-dir": "bin/",
        "config-dir": "config/",
        "src-dir": "src/",
        "var-dir": "var/",
        "public-dir": "public/",

        // defining a custom placeholder (can be accessed using
        // %MY_SPECIAL_DIR% in the recipe)
        "my-special-dir": "..."
    }
}

copy-from-recipe Configurator

It's identical to copy-from-package but contents are copied from the recipe itself instead of from the Composer package contents. It's useful to copy the initial configuration of the dependency and even a simple initial structure of files and directories:

"copy-from-recipe": {
    "config/": "%CONFIG_DIR%/",
}

Avoid storing PHP files that should land under the src/ directory; consider adding a command in your bundle that is able to generate such PHP files instead.

env Configurator

Adds the given list of environment variables to the .env and .env.dist files stored in the root of the Symfony project:

{
    "env": {
        "APP_ENV": "dev"
    }
}

This recipe is converted into the following content appended to the .env and .env.dist files:

###> your-recipe-name-here ###
APP_ENV=dev
###< your-recipe-name-here ###

The ###> your-recipe-name-here ### section separators are needed by Symfony to detect the contents added by this dependency in case you uninstall it later. Don't remove or modify these separators.

Tip

Use %generate(secret)% as the value of any environment variable to replace it with a cryptographically secure random value of 16 bytes.

composer-scripts Configurator

Registers scripts in the auto-scripts section of the composer.json file to execute them automatically when running composer install and composer update. The value is an associative array where the key is the script to execute (including all its arguments and options) and the value is the type of script (php-script for PHP scripts, script for any shell script and symfony-cmd for Symfony commands):

{
    "composer-scripts": {
        "vendor/bin/security-checker security:check": "php-script",
        "make cache-warmup": "script",
        "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
    }
}

gitignore Configurator

Adds patterns to the .gitignore file of the Symfony project. Define those patterns as a simple array of strings (a PHP_EOL character is added after each line):

{
    "gitignore": [
        ".env",
        "/public/bundles/",
        "/var/",
        "/vendor/"
    ]
}

Similar to other configurators, the contents are copied into the .gitignore file and wrapped with section separators (###> your-recipe-name-here ###) that must not be removed or modified.

post-install-output Configurator

Displays contents in the command console after the package has been installed. Avoid outputting meaningless information and use it only when you need to show help messages or the next step actions.

The contents must be defined in a file named post-install.txt (a PHP_EOL character is added after each line). Symfony Console styles and colors are supported too:

<bg=blue;fg=white>              </>
<bg=blue;fg=white> What's next? </>
<bg=blue;fg=white>              </>

  * <fg=blue>Run</> your application:
    1. Change to the project directory
    2. Execute the <comment>make serve</> command;
    3. Browse to the <comment>http://localhost:8000/</> URL.

  * <fg=blue>Read</> the documentation at <comment>https://symfony.com/doc</>

add-lines Configurator

If no other configurators can meet your needs, the add-lines configurator can add entire lines to files, either at the top, bottom or after a target:

"add-lines": [
    {
        "file": "webpack.config.js",
        "content": "\nenables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)\n    .enableStimulusBridge('./assets/controllers.json')",
        "position": "after_target",
        "target": ".splitEntryChunks()"
    },
    {
        "file": "assets/app.js",
        "content": "import './bootstrap.js';",
        "position": "top",
        "warn_if_missing": true
    },
    {
        "file": "assets/translator.js",
        "content": "export * from '../var/translations';",
        "position": "bottom",
        "requires": "symfony/webpack-encore-bundle"
    }
]

Each item needs file, content and position, which can be top, bottom or after_target. If after_target is used, a target must also be specified, which is a string that will be searched for in the file.

If warn_if_missing is set to true, a warning will be shown to the user if the file or target isn't found. If requires is set, the rule will only be applied if the given package is installed.

Validation

When submitting a recipe, several checks are automatically executed to validate the recipe:

  • YAML files suffix must be .yaml, not .yml;
  • YAML files must be valid;
  • YAML files must use 4 space indentations;
  • YAML files use null instead of ~;
  • YAML files under config/packages must not define a "parameters" section;
  • JSON files must be valid;
  • JSON files must use 4 space indentations;
  • Aliases are only supported in the main repository, not the contrib one;
  • Aliases must not be already defined by another package;
  • Aliases are not in the list of special Composer commands (nothing, lock, and mirrors);
  • The manifest file only contains supported keys;
  • The package must exist on Packagist;
  • The package must have at least one version on Packagist;
  • The package must have an MIT or BSD license;
  • The package must be of type "symfony-bundle" if a bundle is registered in the manifest;
  • The package must have a registered bundle in the manifest if type is "symfony-bundle";
  • The package does not only register a bundle for all environments;
  • The package does not depend on symfony/symfony or symfony/security;
  • All text files should end with a newline;
  • All configuration file names under config should use the underscore notation;
  • No "semantically" empty configuration files are created under config/packages;
  • All files are stored under a directory referenced by the "copy-from-recipe" section of "manifest.json";
  • The pull request does not contain merge commits;
  • The Symfony website must be referenced using HTTPs.

Full Example

Combining all the above configurators you can define powerful recipes, like the one used by symfony/framework-bundle:

{
    "bundles": {
        "Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle": ["all"]
    },
    "copy-from-recipe": {
        "config/": "%CONFIG_DIR%/",
        "public/": "%PUBLIC_DIR%/",
        "src/": "%SRC_DIR%/"
    },
    "composer-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
    },
    "env": {
        "APP_ENV": "dev",
        "APP_SECRET": "%generate(secret)%"
    },
    "gitignore": [
        ".env",
        "/public/bundles/",
        "/var/",
        "/vendor/"
    ]
}

More Repositories

1

symfony

The Symfony PHP framework
PHP
28,665
star
2

console

Eases the creation of beautiful and testable command line interfaces
PHP
9,560
star
3

http-foundation

Defines an object-oriented layer for the HTTP specification
PHP
8,513
star
4

event-dispatcher

Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
PHP
8,393
star
5

finder

Finds files and directories via an intuitive fluent interface
PHP
8,290
star
6

http-kernel

Provides a structured process for converting a Request into a Response
PHP
7,980
star
7

thanks

Give thanks (in the form of a GitHub โ˜…) to your fellow PHP package maintainers (not limited to Symfony components)!
PHP
7,912
star
8

polyfill-mbstring

This component provides a partial, native PHP implementation for the Mbstring extension.
PHP
7,746
star
9

routing

Maps an HTTP request to a set of configuration variables
PHP
7,477
star
10

debug

Provides tools to ease debugging PHP code
PHP
7,312
star
11

css-selector

Converts CSS selectors to XPath expressions
PHP
7,309
star
12

process

Executes commands in sub-processes
PHP
7,302
star
13

var-dumper

Provides mechanisms for walking through any arbitrary PHP variable
PHP
7,278
star
14

translation

Provides tools to internationalize your application
PHP
6,529
star
15

polyfill-php72

This component provides functions added to PHP 7.2 core.
PHP
4,756
star
16

filesystem

Provides basic utilities for the filesystem
PHP
4,500
star
17

config

Helps you find, load, combine, autofill and validate configuration values of any kind
PHP
4,138
star
18

flex

Composer plugin for Symfony
PHP
4,043
star
19

dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application
PHP
4,011
star
20

cache

Provides extended PSR-6, PSR-16 (and tags) implementations
PHP
3,977
star
21

polyfill-ctype

This component provides a partial, native PHP implementation for the Ctype extension.
PHP
3,966
star
22

dom-crawler

Eases DOM navigation for HTML and XML documents
PHP
3,834
star
23

yaml

Loads and dumps YAML files
PHP
3,693
star
24

contracts

A set of abstractions extracted out of the Symfony components
PHP
3,607
star
25

dotenv

Registers environment variables from a .env file
PHP
3,604
star
26

framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework
PHP
3,402
star
27

maker-bundle

Symfony Maker Bundle
PHP
3,293
star
28

polyfill-php70

This component provides features unavailable in releases prior to PHP 7.0.
3,243
star
29

polyfill-intl-idn

This component provides a partial, native PHP implementation for the Intl extension (IDN features).
PHP
3,163
star
30

event-dispatcher-contracts

A set of event dispatcher abstractions extracted out of the Symfony components
PHP
3,146
star
31

doctrine-bridge

Provides integration for Doctrine with various Symfony components
PHP
3,086
star
32

options-resolver

Provides an improved replacement for the array_replace PHP function
PHP
3,074
star
33

asset

Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
PHP
3,046
star
34

browser-kit

Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically
PHP
2,849
star
35

monolog-bundle

Symfony Monolog Bundle
PHP
2,817
star
36

panther

A browser testing and web crawling library for PHP and Symfony
PHP
2,742
star
37

expression-language

Provides an engine that can compile and evaluate expressions
PHP
2,709
star
38

stopwatch

Provides a way to profile code
PHP
2,692
star
39

property-access

Provides functions to read and write from/to an object or array using a simple string notation
PHP
2,677
star
40

form

Allows to easily create, process and reuse HTML forms
PHP
2,663
star
41

mime

Allows manipulating MIME messages
PHP
2,576
star
42

intl

Provides access to the localization data of the ICU library
PHP
2,560
star
43

polyfill-intl-icu

This component provides a collection of functions/classes using the symfony/intl package when the Intl extension is not installed.
PHP
2,537
star
44

validator

Provides tools to validate values
PHP
2,515
star
45

monolog-bridge

Provides integration for Monolog with various Symfony components
PHP
2,512
star
46

error-handler

Provides tools to manage errors and ease debugging PHP code
PHP
2,506
star
47

polyfill

PHP polyfills
PHP
2,468
star
48

twig-bridge

Provides integration for Twig with various Symfony components
PHP
2,416
star
49

twig-bundle

Provides a tight integration of Twig into the Symfony full-stack framework
PHP
2,412
star
50

phpunit-bridge

Provides utilities for PHPUnit, especially user deprecation notices management
PHP
2,398
star
51

security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework
PHP
2,374
star
52

service-contracts

A set of service abstractions extracted out of the Symfony components
PHP
2,369
star
53

polyfill-php73

This component provides functions unavailable in releases prior to PHP 7.3.
PHP
2,367
star
54

translation-contracts

A set of translation abstractions extracted out of the Symfony components
PHP
2,362
star
55

serializer

Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.
PHP
2,358
star
56

demo

Symfony Demo Application
PHP
2,345
star
57

debug-bundle

Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge into the Symfony full-stack framework
PHP
2,277
star
58

inflector

Converts words between their singular and plural forms (English only)
PHP
2,227
star
59

webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
JavaScript
2,209
star
60

cache-contracts

A set of cache abstractions extracted out of the Symfony components
PHP
2,149
star
61

web-profiler-bundle

Provides a development tool that gives detailed information about the execution of any request
Twig
2,147
star
62

property-info

Extracts information about PHP class' properties using metadata of popular sources
PHP
2,079
star
63

symfony-docs

The Symfony documentation
HTML
2,077
star
64

var-exporter

Allows exporting any serializable PHP data structure to plain PHP code
PHP
1,916
star
65

polyfill-intl-normalizer

This component provides a fallback implementation for the Normalizer class provided by the Intl extension.
PHP
1,840
star
66

orm-pack

A Symfony Pack for Doctrine ORM
1,839
star
67

http-client-contracts

A set of HTTP client abstractions extracted out of the Symfony components
PHP
1,770
star
68

http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously
PHP
1,763
star
69

polyfill-iconv

This component provides a native PHP implementation of the php.net/iconv functions.
PHP
1,757
star
70

deprecation-contracts

A generic function and convention to trigger deprecation notices
PHP
1,751
star
71

security-core

Symfony Security Component - Core Library
PHP
1,734
star
72

profiler-pack

A Symfony Pack for Symfony profiler
1,716
star
73

security-csrf

Symfony Security Component - CSRF Library
PHP
1,652
star
74

security-http

Symfony Security Component - HTTP Integration
PHP
1,580
star
75

polyfill-php80

This component provides functions unavailable in releases prior to PHP 8.0.
PHP
1,576
star
76

swiftmailer-bundle

Symfony Swiftmailer Bundle
PHP
1,571
star
77

polyfill-php56

This component provides functions unavailable in releases prior to PHP 5.6.
1,557
star
78

polyfill-intl-grapheme

This component provides a partial, native PHP implementation of the Grapheme functions from the Intl extension.
PHP
1,512
star
79

symfony-standard

The "Symfony Standard Edition" distribution
PHP
1,501
star
80

debug-pack

A Symfony Pack for Symfony debug
1,498
star
81

string

Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
PHP
1,447
star
82

security-guard

Symfony Security Component - Guard
PHP
1,434
star
83

polyfill-util

This component provides binary-safe string functions, using the mbstring extension when available.
PHP
1,338
star
84

web-link

Manages links between resources
PHP
1,333
star
85

web-server-bundle

Provides commands for running applications using the PHP built-in web server
PHP
1,280
star
86

mailer

Helps sending emails
PHP
1,263
star
87

psr-http-message-bridge

PSR HTTP message bridge
PHP
1,209
star
88

security

Provides a complete security system for your web application
PHP
1,203
star
89

class-loader

[DEPRECATED] The ClassLoader component provides tools to autoload your classes and cache their locations for performance.
PHP
1,109
star
90

serializer-pack

A Symfony Pack for Symfony Serializer
1,075
star
91

templating

Provides all the tools needed to build any kind of template system
PHP
1,021
star
92

webpack-encore-bundle

Symfony integration with Webpack Encore!
PHP
926
star
93

lts

Enforces Long Term Supported versions of Symfony components
924
star
94

messenger

Helps applications send and receive messages to/from other applications or via message queues
PHP
923
star
95

apache-pack

A Symfony Pack for Symfony Apache
913
star
96

test-pack

A Symfony Pack for functional testing
866
star
97

polyfill-php81

This component provides functions unavailable in releases prior to PHP 8.1.
PHP
764
star
98

proxy-manager-bridge

Provides integration for ProxyManager with various Symfony components
PHP
724
star
99

notifier

Sends notifications via one or more channels (email, SMS, ...)
PHP
673
star
100

polyfill-apcu

This component provides apcu_* functions and the APCUIterator class to users of the legacy APC extension.
PHP
635
star