Symfony2のparametersを使ってみます

こんな config/parameters.yml があったとします。

parameters:
    my_application:
        end_of_maintainance: 2015-01-01 12:34:56
        is_stable: true
        release_manager: "Foo Bar"
        description: |
            This stable version is the right choice for projects
            that need to be maintained for a long period of time.
        latest_beta:  ~
        latest_minor: 1.0.20
        supported_orms:
            - Propel
            - Doctrine
        archives: { source: [zip, tgz], sandbox: [zip, tgz] }

コンテナ経由でこれらを参照することができます。
コマンドを作って試してみます。

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestParametersCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('sample:parameters');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $params = $this->getContainer()->getParameter('my_application');
        print_r($params);
    }
}

実行結果はこんな感じです。

$ php app/console sample:parameters
Array
(
    [end_of_maintainance] => 1420083296
    [is_stable] => 1
    [release_manager] => Foo Bar
    [description] => This stable version is the right choice for projects
that need to be maintained for a long period of time.

    [latest_beta] =>
    [latest_minor] => 1.0.20
    [supported_orms] => Array
        (
            [0] => Propel
            [1] => Doctrine
        )

    [archives] => Array
        (
            [source] => Array
                (
                    [0] => zip
                    [1] => tgz
                )

            [sandbox] => Array
                (
                    [0] => zip
                    [1] => tgz
                )

        )

)

日時も認識された様です。(エポック)

$ date -d @1420083296 +"%Y/%m/%d %H:%M:%S"
2015/01/01 12:34:56

なお、インデントは2文字だと「Indentation problem」って怒られてしまいます。ふぅん。