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 c8ebc1e74b merged branch sli-systems/dc-1 (PR #6080)
This PR was squashed before being merged into the master branch (closes #6080).

Commits
-------

e477a2e Handle case of static controller method and controllers using magic __call() method

Discussion
----------

Handle case of static controller method and controllers using magic __call() method

Improve collecting controller details for edge cases where:
- controller is array, but contains class name and static method
- method doesn't exist, but is handled by magic __call() method

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

by fabpot at 2012-11-21T08:12:08Z

Can you add some unit tests?

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

by sli-systems at 2012-11-21T22:19:17Z

@pierredup
I disagree with the your comment about is_callable() only working with objects. The PHP docs state that the first  argument is a callable, so it can be a string, array, closure, and perhaps more.

The test I added also shows that the code works as is :)

I've thought about your suggestion of adding reflection to look up the location of __call(). However, I think this doesn't really  add a lot and only complicates matters. Also, as you can see in the new test, there is also __callStatic() to consider.

The fact that file/line are n/a is  correct, because the most typical case will be that __call() and __callStatic() will delegate to some other method that might not even be in the same class/file (a subclass I would expect), IMHO.

@fabpot
Good catch  about the '/'. I hope the test is complete enough. Looks more like an exercise on PHP callables than anything else, tho ;)

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

by pierredup at 2012-11-22T04:56:18Z

True that ````is_callable```` takes any callable argument, except in the one specific case where you have a ````__call()```` method, and pass an array with the first paramater as a string.

Take the following example:

    class Controller {
        public function __call($method, $arguments) {}
    }

    $controller = array('Controller', 'action');

    var_dump(is_callable($controller));

Here ````is_callable($controller)```` will actually return ````false````, where if you have ````$controller = array(new Controller, 'action');```` it would return true.

Of course if you have a ````__callStatic```` method, then it would always return true.

Your tests doesn't seem to cover this use case

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

by sli-systems at 2012-11-22T20:27:05Z

Hmm, maybe. I have to admin that I do not know about this case. OTOH, if is_callable returns false is it really callable then? I would think this more of a PHP bug then?

I think I might have come across this case during coding, but then dismissed it because in that case FilterControllerEvent failed already before the data collector code is reached.

In FilterControllerEvent there is a check on is_callable and a LogicException is thrown if $controller is not callable.

So, is FilterControllerEvent wrong  too then?

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

by pierredup at 2012-11-22T20:41:14Z

One would think that if is_callable returns false, then the controller isn't callable, but in the case I mentioned above, the controller is in fact callable. I also thought it was a bug with php, but the php-internals don't seem to think so.

The problem is, if you specify the class as a string, php looks for a static method, even if you have a __call method, it won't be registered.

I will have a look at the FilterControllerEvent to see if this use case applies there as well.

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

by sli-systems at 2012-11-22T20:50:32Z

Rather strange - if that is the case then using is_callable seems pretty pointless and the only way would be to try to execute the controller to find out if it is, in fact, callable...

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

by pierredup at 2012-11-22T20:51:07Z

Okay so it actually seems that the case above isn't callable after all. If the controller is specified as a string, then a static method need to exist. Hence why it works with __callStatic. Only when an instance of the class is specified, will it handle the __call method.

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

by sli-systems at 2012-11-22T20:57:55Z

So the tests are sufficient then?

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

by pierredup at 2012-11-22T20:59:22Z

Yes it is.
This happens when you just assume something without actually testing it :)

Sorry for the hassle
2012-11-24 13:13:43 +01:00
src/Symfony merged branch sli-systems/dc-1 (PR #6080) 2012-11-24 13:13:43 +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 [travis-ci] Zend Garbage Collection only for PHP5.4 2012-11-19 15:21:43 +01:00
autoload.php.dist [travis-ci] Zend Garbage Collection only for PHP5.4 2012-11-19 15:21:43 +01: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 [travis-ci] Zend Garbage Collection only for PHP5.4 2012-11-19 15:21:43 +01: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 [Form] Update password type trimming to false 2012-11-16 14:51:56 +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.