Routing in Symfony 1.4: Is there a way to allow sf_method = OPTIONS for HTTP presale requests
you may all know that browsers in some cases precede HTTP requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests
My web app is still on Symfony1. I want to implement a RESTful service and hence use Symfony routing to allow certain HTTP request methods like GET or POST ( http://symfony.com/legacy/doc/reference/1_4/en/10-Routing#chapter_10_sub_sf_method ).
Example:
login:
url: /v1/login
class: sfRequestRoute
param: { module: rest, action: login }
requirements:
sf_method: [post, put, delete]
#sf_method: [options] NOT WORKING
It seems to me that OPTIONS requests cannot be defined / handled as sf_method value. Because I could not find any information, if my idea is correct, I wonder if I am correct, or maybe there is a solution that I could not find either.
Thanks in advance!
source to share
Sorry to revive this old question, but I found a solution. I faced the same problem and I added a request method OPTIONS
to the allowed methods in lib/sfRequest.class.php
and lib/sfWebRequest.class.php
. You can check the latest commit here to see the differences: 6ad018c
Since I cannot update the original Symfony1 GitHub repository, I created a copy with additional fixes needed due to various PHP updates. This fixes deprecated PHP warnings due to the use of a modifier /e
in preg_replace calls.
Please note that this is still not compatible with Symfony1 PHP7. I have been doing this successfully with PHP 5.6.30
Repository https://github.com/diem-project/symfony.git
Background: Diem is using Symfony1 (1.4.20) hence the GitHub organization diem-project
source to share