@@ -67,9 +67,9 @@ there's not even any performance difference between them.
67
67
YAML is used by default when installing packages because it's concise and very
68
68
readable. These are the main advantages and disadvantages of each format:
69
69
70
- * **YAML **: simple, clean and readable, but requires using a dedicated parser.
71
- :doc: `Learn the YAML syntax </components/yaml/yaml_format >`;
72
- * **XML **: supports IDE autocompletion/validation and is parsed natively by PHP,
70
+ * **YAML **: simple, clean and readable, but not all IDEs support autocompletion
71
+ and validation for it. :doc: `Learn the YAML syntax </components/yaml/yaml_format >`;
72
+ * **XML **:autocompleted/validated by most IDEs and is parsed natively by PHP,
73
73
but sometimes it generates too verbose configuration. `Learn the XML syntax `_;
74
74
* **PHP **: very powerful and it allows to create dynamic configuration, but the
75
75
resulting configuration is less readable than the other formats.
@@ -603,23 +603,9 @@ will load the parsed file instead of parsing the ``.env`` files again:
603
603
604
604
.. _configuration-env-var-web-server :
605
605
606
- Using ``.env `` files is the recommended way of using env vars in Symfony
607
- applications. However, you can also define env vars in the web server
608
- configuration if you prefer that:
609
-
610
- .. configuration-block ::
611
-
612
- .. code-block :: apache
613
-
614
- <VirtualHost *:80>
615
- # ...
616
-
617
- SetEnv DATABASE_URL "mysql://db_user:db_password@127.0.0.1:3306/db_name"
618
- </VirtualHost>
619
-
620
- .. code-block :: nginx
621
-
622
- fastcgi_param DATABASE_URL "mysql://db_user:db_password@127.0.0.1:3306/db_name";
606
+ Creating ``.env `` files is the easiest way of using env vars in Symfony
607
+ applications. However, you can also configure real env vars in your servers and
608
+ operating systems.
623
609
624
610
.. tip ::
625
611
@@ -643,30 +629,33 @@ Managing Multiple .env Files
643
629
The ``.env `` file defines the default values for all env vars. However, it's
644
630
common to override some of those values depending on the environment (e.g. to
645
631
use a different database for tests) or depending on the machine (e.g. to use a
646
- different OAuth token in your local machine while developing).
632
+ different OAuth token on your local machine while developing).
647
633
648
634
That's why you can define multiple ``.env `` files to override env vars. The
649
635
following list shows the files loaded in all environments. The ``.env `` file is
650
- the only mandatory file and each file overrides all the previous ones :
636
+ the only mandatory file and each file content overrides the previous one :
651
637
652
638
* ``.env ``: defines the default values of the env vars needed by the application;
653
- * ``.env.local ``: overrides env vars for all environments but only in your local
654
- machine;
655
- * ``.env.<environment> `` (e.g. ``.env.test ``): overrides env vars for some
656
- environment and for all machines;
657
- * ``.env.<environment>.local `` (e.g. ``.env.test.local ``): overrides env vars
658
- only for some environment and only in your local machine.
639
+ * ``.env.local ``: defines machine-specific overrides for env vars on all
640
+ environments. This file is not committed to the repository, so these overrides
641
+ only apply to the machine which contains the file (your local computer,
642
+ production server, etc.);
643
+ * ``.env.<environment> `` (e.g. ``.env.test ``): overrides env vars only for some
644
+ environment but for all machines;
645
+ * ``.env.<environment>.local `` (e.g. ``.env.test.local ``): defines machine-specific
646
+ env vars overrides only for some environment. It's similar to ``.env.local ``,
647
+ but the overrides only apply to some particular environment.
659
648
660
649
.. note ::
661
650
662
651
The real environment variables defined in the server always win over the
663
652
env vars created by the ``.env `` files.
664
653
665
654
The ``.env `` and ``.env.<environment> `` files should be committed to the shared
666
- repository because they are the same for all developers. However, the env files
667
- ending in ``.local `` (``.env.local `` and ``.env.<environment>.local ``) ** should
668
- not be committed ** because only you will use them. In fact, the `` .gitignore ``
669
- file that comes with Symfony prevents them from being committed.
655
+ repository because they are the same for all developers and machines . However,
656
+ the env files ending in ``.local `` (``.env.local `` and ``.env.<environment>.local ``)
657
+ ** should not be committed ** because only you will use them. In fact, the
658
+ `` .gitignore `` file that comes with Symfony prevents them from being committed.
670
659
671
660
.. caution ::
672
661
@@ -677,18 +666,18 @@ file that comes with Symfony prevents them from being committed.
677
666
Accessing Configuration Values
678
667
------------------------------
679
668
680
- Controllers and services can access to all the configuration parameters. This
681
- includes both the :ref: `parameteres defined by yourself <configuration-parameters >`
669
+ Controllers and services can access all the configuration parameters. This
670
+ includes both the :ref: `parameters defined by yourself <configuration-parameters >`
682
671
and the parameters created by packages/bundles. Run the following command to see
683
672
all the parameters that exist in your application:
684
673
685
674
.. code-block :: terminal
686
675
687
676
$ php bin/console debug:container --parameters
688
677
689
- Parameters are injected in services as arguments of their constructors.
678
+ Parameters are injected in services as arguments to their constructors.
690
679
:doc: `Service autowiring </service_container/autowiring >` doesn't work for
691
- parameters, so you must inject them explicitly:
680
+ parameters. Instead, inject them explicitly:
692
681
693
682
.. configuration-block ::
694
683
@@ -737,8 +726,8 @@ parameters, so you must inject them explicitly:
737
726
If you inject the same parameters over and over again, use instead the
738
727
``services._defaults.bind `` option. The arguments defined in that option are
739
728
injected automatically whenever a service constructor or controller action
740
- define an argument with that exact name. For example, if you want to inject the
741
- value of the :ref: `kernel.project_dir parameter <configuration-kernel-project-directory >`
729
+ define an argument with that exact name. For example, to inject the value of the
730
+ :ref: `kernel.project_dir parameter <configuration-kernel-project-directory >`
742
731
whenever a service/controller defines a ``$projectDir `` argument, use this:
743
732
744
733
.. configuration-block ::
@@ -799,28 +788,25 @@ whenever a service/controller defines a ``$projectDir`` argument, use this:
799
788
Finally, if some service needs to access to lots of parameters, instead of
800
789
injecting each of them individually, you can inject all the application
801
790
parameters at once by type-hinting any of its constructor arguments with the
802
- :class: `Symfony\\ Component\\ DependencyInjection\\ ParameterBag\\ ParameterBagInterface `
803
- or the new :class: `Symfony\\ Component\\ DependencyInjection\\ ParameterBag\\ ContainerBagInterface `.
804
- However, in these cases it's usually better to refactor the service and avoid
805
- requiring so many parameters::
791
+ :class: `Symfony\\ Component\\ DependencyInjection\\ ParameterBag\\ ContainerBagInterface `::
806
792
807
793
// src/Service/MessageGenerator.php
808
794
// ...
809
795
810
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface ;
796
+ use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface ;
811
797
812
798
class MessageGenerator
813
799
{
814
800
private $params;
815
801
816
- public function __construct(ParameterBagInterface $params)
802
+ public function __construct(ContainerBagInterface $params)
817
803
{
818
804
$this->params = $params;
819
805
}
820
806
821
807
public function someMethod()
822
808
{
823
- // get any param from $this->params, which stores all container parameters
809
+ // get any container parameter from $this->params, which stores all of them
824
810
$sender = $this->params->get('mailer_sender');
825
811
// ...
826
812
}
0 commit comments