Skip to content

Commit

Permalink
Merge branch 'feature/remove-usage-of-opt/options' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
trq committed Aug 2, 2012
2 parents 8bcd96c + 5c37f47 commit b5bf870
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
18 changes: 7 additions & 11 deletions lib/Proem/Api/Routing/Route/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ abstract class Generic implements Template
/**
* Instantiate this route
*
* @param array $options An array of Proem\Api\Util\Opt\Option objects
* $options = ['rule', 'targets', 'filters', 'method', 'callback'];
*
* @param array $options
*/
public function __construct(array $options)
{
$this->options = $this->setOptions([
'rule' => (new Option)->type('string')->required(),
'targets' => (new Option([]))->type('array'),
'filters' => (new Option([]))->type('array'),
'method' => (new Option(null))->type('string'),
'callback' => (new Option)->type('callable')
], $options);

if (is_callable($this->options->callback)) {
$this->options = $options;

if (isset($this->options['callback']) && is_callable($this->options['callback'])) {
$this->hasCallback = true;
}

Expand Down Expand Up @@ -154,7 +150,7 @@ public function getPayload()
*/
public function call(Request $request)
{
(new Callback($this->options->callback, $request))->call();
(new Callback($this->options['callback'], $request))->call();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/Proem/Api/Routing/Route/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ public function __construct(array $options) {
*/
public function process(Request $request)
{
if (!$this->options->rule) {
if (!isset($this->options['rule'])) {
return false;
}

$rule = $this->options->rule;
$target = $this->options->targets;
$custom_filters = $this->options->filters;
$method = $this->options->method ?: 'GET';
$rule = $this->options['rule'];
$target = isset($this->options['targets']) ? $this->options['targets'] : [];
$custom_filters = isset($this->options['filters']) ? $this->options['filters'] : [];
$method = isset($this->options['method']) ? $this->options['method'] : 'GET';

$default_tokens = $this->default_tokens;
$default_filters = $this->default_filters;
Expand Down
14 changes: 8 additions & 6 deletions lib/Proem/Api/Routing/Route/StaticRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ class StaticRoute extends Generic
{
public function process(Request $request)
{
if (!$this->options->rule) {
if (!isset($this->options['rule'])) {
return false;
}

if (!isset($this->options->targets['module']) || !isset($this->options->targets['controller']) || !isset($this->options->targets['action'])) {
$method = isset($this->options['method']) ? $this->options['method'] : 'GET';

if (!isset($this->options['targets']) || !isset($this->options['targets']['module']) || !isset($this->options['targets']['controller']) || !isset($this->options['targets']['action'])) {
return false;
}

if ($request->getRequestUri() == $this->options->rule && $request->getMethod() == ($this->options->method ?: 'GET')) {
$this->getPayload()->set('module', $this->options->targets['module']);
$this->getPayload()->set('controller', $this->options->targets['controller']);
$this->getPayload()->set('action', $this->options->targets['action']);
if ($request->getRequestUri() == $this->options['rule'] && $request->getMethod() == $method) {
$this->getPayload()->set('module', $this->options['targets']['module']);
$this->getPayload()->set('controller', $this->options['targets']['controller']);
$this->getPayload()->set('action', $this->options['targets']['action']);

$this->setMatch();
$this->getPayload()->set('request', $request);
Expand Down

0 comments on commit b5bf870

Please sign in to comment.