Phalcon\Mvc\Micro\Collection missing via() method
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.
Can you please create issue in docs repo?
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?
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
The via() method however, does not even exist in 1.3.5, so not too sure about that one.
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
It implements the interface, so returning itself does return the interface.
This is fixed in 2.0.x