new: [legacy] handler added for Legacy APIs

- allows for a remap of the parameters and subsequent calls to modern functions
pull/5435/head
iglocska 2019-11-26 19:01:22 +01:00
parent f1c6465050
commit e7173e2ee4
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 45 additions and 2 deletions

View File

@ -62,6 +62,8 @@ class AppController extends Controller
'attributes' => array('text', 'downloadAttachment', 'returnAttributes', 'restSearch', 'rpz', 'bro'),
);
protected $_legacyParams = array();
public function __construct($id = false, $table = null, $ds = null)
{
parent::__construct($id, $table, $ds);
@ -704,9 +706,8 @@ class AppController extends Controller
}
// generic function to standardise on the collection of parameters. Accepts posted request objects, url params, named url params
protected function _harvestParameters($options, &$exception)
protected function _harvestParameters($options, &$exception, $data = array())
{
$data = array();
if (!empty($options['request']->is('post'))) {
if (empty($options['request']->data)) {
$exception = $this->RestResponse->throwException(
@ -1100,4 +1101,46 @@ class AppController extends Controller
}
}
protected function _legacyAPIRemap($options = array())
{
if (!empty($options['key'])) {
$user = $this->_getApiAuthUser($key, $exception);
} else {
$user = $this->Auth->user();
}
if ($user === false) {
return $exception;
}
$ordered_url_params = array();
foreach ($options['paramArray'] as $k => $param) {
if (isset($options['ordered_url_params'][$k])) {
$ordered_url_params[$param] = $options['ordered_url_params'][$k];
} else {
$ordered_url_params[$param] = false;
}
}
$filterData = array(
'request' => $options['request'],
'named_params' => $options['named_params'],
'paramArray' => $options['paramArray'],
'ordered_url_params' => $ordered_url_params
);
$exception = false;
$filters = $this->_harvestParameters($filterData, $exception);
if (!empty($options['injectedParams'])) {
foreach ($options['injectedParams'] as $injectedParam => $injectedValue) {
$filters[$injectedParam] = $injectedValue;
}
}
if (!empty($options['alias'])) {
foreach ($options['alias'] as $from => $to) {
if (!empty($filters[$from])) {
$filters[$to] = $filters[$from];
}
}
}
$this->_legacyParams = $filters;
return true;
}
}