📜 ⬆️ ⬇️

Future release of symfony 4.0 and a project using symfony flex

November 30, 2017 release of symfony 4.0 will take place



image

The fourth version has a number of global changes, the main of which can be called the transition to symfony Flex.
')

What is symfony flex?


This is a new approach to organizing applications on a symphony, based on "recipes" .
According to the developers, this should make it easier to work with dependencies \ bundles \ packages and introduce more automation.

There are 2 repositories with recipes:


The recipe is configured via manifest.json which contains a set of configurators and options.

Options


aliases
Used to specify an alternative recipe name. For example, without using this option, the recipe is set as follows:

composer req acme-inc/acme-log-monolog-handler 

Adding to manifest.json

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

can be used

 composer req acme-log 

Configurators


A set of tasks to be performed when installing a recipe.
bundles

Connecting one or more bundles with the ability to specify the environment.

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

container
Adding container parameters to services.yaml, for example, locale:

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

copy-from-package
Copies folders or files from the package to the project:

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

Available constants:
% BIN_DIR%,% CONF_DIR%,% CONFIG_DIR%,% SRC_DIR%% VAR_DIR%,% PUBLIC_DIR%

copy-from-recipe
Copying files and directories from the recipe itself:

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

env
Adding parameters to .env and .env.dist:

 { "env": { "APP_ENV": "dev", "APP_DEBUG": "1" } } 

You can generate a random 16-bit string using % generate (secret)%

gitignore
Adds patterns to .gitignore:

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

post-install-output
Defines the content that will be shown after the installation of the recipe, must be defined in the post-install.txt file , each line is closed by PHP_EOL.
Console colors / styles are supported.

A complete example of manifest.json for symfony / framework-bundle :

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


We collect the first project on symfony Flex


We will use the latest version available at the time of this writing - "v4.0.0-RC1"

First we need composer .

Let's create a project:

 composer create-project symfony/skeleton flex-test-project "v4.0.0-RC1" 

Initially, only official recipes are available to us. To use third-party recipes, you must do the following:

 composer config extra.symfony.allow-contrib true 

or add yourself

 "extra": { "symfony": { "allow-contrib": "true" } 

in composer.json

To start, you can use the PHP-integrated web server or install the web-server-bundle through its recipe:

 composer req web-server bin/console server:start 

Also, we need a profiler and a generator, which is now called maker-bundle .
Profiler requires twig.

 composer req twig composer req web-profiler-bundle 

And for the annotation generator it may also be necessary to lower the minimum-stability requirements in * composer.json *.

  "minimum-stability": "dev" 

 composer req maker composer req annotations bin/console make:controller 

Is done.



You can use https://symfony.sh/ to search for recipes.
Major changes in the upcoming version .
Github repository
Upgrade from 3. * to 4. *

Source: https://habr.com/ru/post/343030/


All Articles