Commit ca3a77d5 authored by Fabien Potencier's avatar Fabien Potencier

feature #1122 Add OPTIONS request routing directly to Application (jimdoescode, jim)

This PR was submitted for the master branch but it was merged into the 1.3 branch instead (closes #1122).

Discussion
----------

Add OPTIONS request routing directly to Application

I think it's important to add this HTTP Method directly to the application because it's often called automatically by browsers during AJAX requests. Meaning it's required that anyone sending AJAX requests to Silex will have to implement some kind of OPTIONS handling. I realize that you can use the match and method calls to do this same thing but those make routing OPTIONS requests less obvious.

Commits
-------

20be5c99 Fixed whitespace issue
45dc2bcc Add options request capability to controller collection
7ca60854 Update Application add options method for handling option routing
parents 14e39452 20be5c99
......@@ -263,6 +263,19 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
return $this['controllers']->delete($pattern, $to);
}
/**
* Maps an OPTIONS request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function options($pattern, $to = null)
{
return $this['controllers']->options($pattern, $to);
}
/**
* Maps a PATCH request to a callable.
*
......
......@@ -136,6 +136,19 @@ class ControllerCollection
return $this->match($pattern, $to)->method('DELETE');
}
/**
* Maps an OPTIONS request to a callable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return Controller
*/
public function options($pattern, $to = null)
{
return $this->match($pattern, $to)->method('OPTIONS');
}
/**
* Maps a PATCH request to a callable.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment