I have a problem to get PUT request data.
I follow this skeleton project : Phalcon-api-oauth2
when I send PUT request, the result always empty array()
I have tried changed the several code :
micro.php
before
public function setRoutes($file) {
if (!file_exists($file)) {
throw new \Exception('Unable to load routes file');
}
$routes = include($file);
if (!empty($routes)) {
foreach($routes as $obj) {
switch($obj['method']) {
case 'get':
$this->get($obj['route'], $obj['handler']);
break;
case 'post':
$this->post($obj['route'], $obj['handler']);
break;
case 'delete':
$this->delete($obj['route'], $obj['handler']);
break;
case 'put':
$this->head($obj['route'], $obj['handler']);
break;
case 'options':
$this->options($obj['route'], $obj['handler']);
break;
case 'patch':
$this->patch($obj['route'], $obj['handler']);
break;
default:
break;
}
}
}
}
after
public function setRoutes($file) {
if (!file_exists($file)) {
throw new \Exception('Unable to load routes file');
}
$routes = include($file);
if (!empty($routes)) {
foreach($routes as $obj) {
switch($obj['method']) {
case 'get':
$this->get($obj['route'], $obj['handler']);
break;
case 'post':
$this->post($obj['route'], $obj['handler']);
break;
case 'delete':
$this->delete($obj['route'], $obj['handler']);
break;
case 'put':
$this->put($obj['route'], $obj['handler']);
break;
case 'options':
$this->options($obj['route'], $obj['handler']);
break;
case 'patch':
$this->patch($obj['route'], $obj['handler']);
break;
default:
break;
}
}
}
}
I added new method for PUT request in
vendor/Oauth2/src/Oauth2/Server/Storage/Pdo/Mysql/Request.php
public function put($index = NULL)
{
// print_r($this->request->getPut()); // I can see the PUT request data here
return $this->request->getPut($index);
}
also added in
vendor/league/oauth2-server/src/League/OAuth2/Server/Util/RequestInterface.php
public function put($index = null);
then modified this class
vendor/league/oauth2-server/src/League/OAuth2/Server/Util/Request.php
class Request implements RequestInterface
{
protected $get = array();
protected $post = array();
protected $cookies = array();
protected $files = array();
protected $server = array();
protected $headers = array();
protected $put = array(); // new property added
// new $put parameter added */
public function __construct(array $get = array(), array $post = array(), array $put = array(), array $cookies = array(), array $files = array(), array $server = array(), $headers = array())
{
$this->get = $get;
$this->post = $post;
$this->put = $put;
$this->cookies = $cookies;
$this->files = $files;
$this->server = $server;
if (empty($headers)) {
$this->headers = $this->readHeaders();
} else {
$this->headers = $this->normalizeHeaders($headers);
}
}
/* new method added */
public function put($index = null, $default = null)
{
return $this->getPropertyValue('put', $index, $default);
}
....
can anyone please let me know what wrong with the code ?
Cheers.