This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier b0994603bb merged branch lyrixx/routing-annot-default-values (PR #5904)
This PR was squashed before being merged into the master branch (closes #5904).

Commits
-------

84adcb1 [2.2][Routing] Added support for default attributes with default values of method params

Discussion
----------

[2.2][Routing] Added support for default attributes with default values of method params

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

With this patch, you can configure your default values likes this:

``` php
/**
 * @Route("/hi/{name}", name="hi")
 */
public function hiAction($name = "Bob")
{
    return new Response($name);
}
```

---------------------------------------------------------------------------

by Tobion at 2012-11-03T23:15:32Z

I'm unsure. How does one know if that param defines a default value or a requirement? It's too vague.

---------------------------------------------------------------------------

by lyrixx at 2012-11-03T23:35:27Z

It's only a default value, not a requirement.
It's just a shortcut to avoid  `defaults={"name"="bob"}`

---------------------------------------------------------------------------

by Tobion at 2012-11-03T23:43:51Z

Yes, but its not clear. It could also be a shortcut to `requirements={"name"="bob"}`, which has totally different meaning. So it's not self-explanatory.
-1 for me.

---------------------------------------------------------------------------

by lyrixx at 2012-11-03T23:48:21Z

it is the default php behavior. It's a default value for a variable...

---------------------------------------------------------------------------

by stof at 2012-11-04T00:22:58Z

@Tobion using the default value of the method to set a requirement does not make any sense. I don't see why someone would expect this behavior

---------------------------------------------------------------------------

by fabpot at 2012-11-06T10:12:05Z

@lyrixx Can you add some unit tests?

---------------------------------------------------------------------------

by Tobion at 2012-11-06T10:28:42Z

Oh I misunderstood the PR. I thought this makes the `name` param default to `hi`. `@Route("/hi/{name}", name="hi")`. But it's just the name of the route. Your example was easy to misinterpret as you used `name` everywhere.

---------------------------------------------------------------------------

by fabpot at 2012-11-10T08:33:13Z

@lyrixx Can you finish this PR?

---------------------------------------------------------------------------

by lyrixx at 2012-11-10T13:16:34Z

@fabpot Yes i will as soon as possible.

---------------------------------------------------------------------------

by lyrixx at 2012-11-10T18:34:07Z

I rebase and amend my commit. (I changed doc in commit message to be less confusing)

I will try to add tests.
But for now, `AnnotationClassLoader::load` is not really tested, and `AnnotationClassLoader::addRoute` is absolutely not tested. So I think I should add tests for these methods ? And then add tests for my patch.
I will try tomorrow.

---------------------------------------------------------------------------

by lyrixx at 2012-11-11T18:23:41Z

@fabpot I added new tests. I tried to made very atomic commits.
2012-11-12 10:46:50 +01:00
src/Symfony merged branch lyrixx/routing-annot-default-values (PR #5904) 2012-11-12 10:46:50 +01:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore ignore composer.phar 2012-04-20 14:10:06 +01:00
.travis.yml Merge branch '2.1' 2012-09-20 10:40:30 +02:00
autoload.php.dist removed manual locale stub autoload 2012-10-03 13:58:05 +03:00
CHANGELOG-2.0.md updated CHANGELOG for 2.0.18 2012-10-25 10:56:03 +02:00
CHANGELOG-2.1.md updated CHANGELOG for 2.1.3 2012-10-30 09:13:22 +01:00
composer.json Add missing symfony/stopwatch in the replace section of composer.json 2012-11-10 18:59:49 +01:00
CONTRIBUTING.md Create CONTRIBUTING.md file for auto-linking in PR's 2012-09-17 14:40:53 -04:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.1.3 2012-10-30 09:13:54 +01:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
phpunit.xml.dist [Locale] Fixed tests 2012-09-24 10:11:13 +02:00
README.md Point to information on how to run the test suite. (closes #5405) 2012-09-01 08:52:18 +02:00
UPGRADE-2.1.md Update UPGRADE-2.1.md 2012-11-07 13:13:48 +01:00
UPGRADE-2.2.md [FrameworkBundle] move change note to changelog of FrameworkBundle instead of master UPGRADE-2.2 2012-11-11 21:12:12 +01:00

README

Build Status

What is Symfony2?

Symfony2 is a PHP 5.3 full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easy to maintain websites with PHP.

Symfony can be used to develop all kind of websites, from your personal blog to high traffic ones like Dailymotion or Yahoo! Answers.

Requirements

Symfony2 is only supported on PHP 5.3.3 and up.

Be warned that PHP versions before 5.3.8 are known to be buggy and might not work for you:

Installation

The best way to install Symfony2 is to download the Symfony Standard Edition available at http://symfony.com/download.

Documentation

The "Quick Tour" tutorial gives you a first feeling of the framework. If, like us, you think that Symfony2 can help speed up your development and take the quality of your work to the next level, read the official Symfony2 documentation.

Contributing

Symfony2 is an open source, community-driven project. If you'd like to contribute, please read the Contributing Code part of the documentation. If you're submitting a pull request, please follow the guidelines in the Submitting a Patch section.

Running Symfony2 Tests

Information on how to run the Symfony2 test suite can be found in the Running Symfony2 Tests section.