cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Phalcon\Mvc\Micro\Collection missing via() method

Open mahelious opened this issue 11 years ago • 7 comments

doucmentation for Micro-controllers indicates the following to map multiple methods at once:

//Matches if the HTTP method is GET or POST $app->map('/repos/store/refs',"action_product")->via(array('GET', 'POST'));

However via() is absent from Phalcon\Mvc\Micro\Collection and throws an error when attempting to invoke.

mahelious avatar May 08 '15 15:05 mahelious

Can you please create issue in docs repo?

sergeyklay avatar May 08 '15 16:05 sergeyklay

I don't believe the issue is with the docs, the Micro Collection ought to have a via() method.

Upon further discovery there is another issue. I expect Phalcon\Mvc\Micro\Collection::map() to return an instance of Phalcon\Mvc\Micro\Collection. However the following snippet:

$t = $c->map('/', 'index');

assigns null to $t. Is that the expected behavior in Phalcon2?

mahelious avatar May 08 '15 16:05 mahelious

It is not, I will be able to fix this when I get home, if no one else makes a PR by then. See #10298/#10299

Green-Cat avatar May 08 '15 17:05 Green-Cat

The via() method however, does not even exist in 1.3.5, so not too sure about that one.

Green-Cat avatar May 08 '15 17:05 Green-Cat

Skimming the code I am mystified at how via() was ever working. The only clue I have is that in 1.3 map() seemed to return a Phalcon\Mvc\Micro\CollectionInterface while in 2.0 it returns a Phalcon\Mvc\Micro\Collection. It's not much help as there is no via function in ext/mvc/micro/collectioninterface.c (nor in ext/mvc/micro/collection.c for that matter). I can confirm the code worked in Phalcon 1.3.3.

In any case, map() adds an item to the collection _handlers with an empty method. Is there a "correct" way to populate the method (or preferably multiple methods) once map() is finished? My thought is immediately after calling map() to pop the last element, and then foreach over the list of methods to update _handlers with multiple "cloned" items, but I don't know if that matches the expected behavior.

Edit - Delving into 1.3.4 i'm finding Mvc\Router\Route::via(), which also exists in 2.0. My guess is that because map() previously returned a CollectionInterface which may have been able to reference the Route function? It seems like a stretch and i'm still not clear on the connection.

Any idea on why Phalcon\Mvc\Micro\Collection::map() was changed to return itself instead of the related interface? It seems that was intentional based on the phpdoc sig @return Phalcon\Mvc\Micro\Collection

mahelious avatar May 08 '15 18:05 mahelious

It implements the interface, so returning itself does return the interface.

Green-Cat avatar May 08 '15 18:05 Green-Cat

This is fixed in 2.0.x

andresgutierrez avatar May 11 '15 02:05 andresgutierrez