Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jan 24, 2017
1 parent 02a22b6 commit 621a5b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 26 deletions.
56 changes: 44 additions & 12 deletions src/Request/AdapterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,63 @@ trait AdapterExtension
];

/**
* @param $call
* @param $name
*
* @throws \BadFunctionCallException
*/
private function allowMethods($call, $name)
{
if (empty($this->allowMethods[$call]))
{
throw new \BadFunctionCallException('Not found `' . $name . '`');
}
}

/**
* @param $call
* @param $arguments
*
* @return mixed
*/
private function unsafeFilter($call, $arguments)
{
$arguments[1] = isset($arguments[1]) ? $arguments[1] : null;
$arguments[2] = false;

return call_user_func_array([$this, $call], $arguments);
}

/**
* @param $name
*
* @throws \BadFunctionCallException
* @return array
*/
public function __call($name, $arguments)
private function parameterInit($name)
{
$parameters = preg_replace('~([A-Z])~', '_$1', $name, 1);

$parameters = $this->normalizeLow($parameters);
list ($call, $filter) = explode('_', $parameters);

if (empty($this->allowMethods[$call]))
{
throw new \BadFunctionCallException('Not found `' . $name . '`');
}
return explode('_', $parameters);
}

/**
* @param $name
* @param $arguments
*
* @return mixed
*
* @throws \BadFunctionCallException
*/
public function __call($name, $arguments)
{
list ($call, $filter) = $this->parameterInit($name);

$this->allowMethods($call, $name);

if ($filter === 'unsafe')
{
$arguments[1] = isset($arguments[1]) ? $arguments[1] : null;
$arguments[2] = false;

return call_user_func_array([$this, $call], $arguments);
return $this->unsafeFilter($call, $arguments);
}

return $this->filterVariable(
Expand Down
22 changes: 8 additions & 14 deletions src/Request/RequestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public function queryString($url = null)
/**
* @param array $data
* @param int|array $options
*
* @return string
*/
public function json(array $data = array(), $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
{
Expand All @@ -98,21 +100,13 @@ public function json(array $data = array(), $options = JSON_PRETTY_PRINT | JSON_
header('Content-type: application/json; charset=utf-8');
}

if (is_array($options))
{
$this->helper->json()->reset();

foreach ($options as $option)
{
$this->helper->json()->addOption($option);
}
}
else
{
$this->helper->json()->setOption($options);
}
/**
* @var \Deimos\Helper\Helpers\Json $json
*/
$json = $this->helper->json();
$json->setOption((array)$options);

return $this->helper->json()->encode($data);
return $json->encode($data);

}

Expand Down

0 comments on commit 621a5b9

Please sign in to comment.