I've recently started working with Symfony Routing component.
My routes yaml look like this:
custom:
path: /custom
defaults: {controller: custom, action: refresh}
methods: [POST]
schemes: [https]
default:
path: /{controller}/{action}
defaults: {controller : index, action: index}
However url https://my.domain.com/custom" gets resolved to the default route even if it goes after the custom one in yaml file. Request method, according to my jQuery .ajax settings and Chrome console, is POST:
XHR finished loading: POST "https://my.domain.com/custom".
or according to Chrome network -> headers:
Request URL:https://my.domain.com/custom
Request Method:POST
If I change request method to get, leaving yaml configuration the same, it does not work either, which is of course expected. If I change yaml configuration for custom route to accept GET instead of POST, and send a GET request, it does work, as expected again. But if I change yaml configuration for custom route to accept GET and send a POST request, it works, i.e. custom rule is matched! It seems like browser's POST request is interpreted as GET on the server side, in some sense.
In a case it's some sort of weird Chrome bug, I've tried Firefox, with the same results.
Then I've tried printing $_SERVER['REQUEST_METHOD'] and it's results are as expected, POST if request was POST, GET if request was GET. So it seems to me it's Symfony's fault somewhere, maybe I misconfigured something.
Here's my relevant PHP code:
$args = isset($_REQUEST['args']) ? $_REQUEST['args'] : '';
$request = Request::createFromGlobals();
$locator = new FileLocator(HOME_PATH . 'config');
$loader = new YamlFileLoader($locator);
$routes = $loader->load('routes.yml');
$context = new RequestContext($_SERVER['REQUEST_URI']);
$context->setScheme($request->getScheme());
$context->setHost($_SERVER['SERVER_NAME']);
$matcher = new UrlMatcher($routes, $context);
try
{
$match = $matcher->match('/' . rtrim($args, '/'));
....
}
....
I have a strong feeling I'm just doing something fundamentally wrong with request and context here, but that's how I managed to get them working, and it used to work well so far, with GET routes at least. Thanks in advance for your help!