Skip to content

Commit

Permalink
Merge pull request #2 from f4usto/master
Browse files Browse the repository at this point in the history
merge exclude, params included and now it refreshes after the set
  • Loading branch information
beeblebrox3 committed Nov 4, 2015
2 parents 48b9e94 + db57054 commit ff9b34a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/Sigep/Request/TraitRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ public function setDefaultOffset($offset)
$this->defaultOffset = $offset;
}

public function params($forceRefresh = false) {
$data = array();

if ($forceRefresh) $this->refresh($this->get);

$data['paginate'] = $this->paginate();
$data['page'] = $this->page();
$data['offset'] = $this->offset();
$data['filter'] = $this->filter();
$data['embed'] = $this->embed();
$data['sort'] = $this->sort();
$data['search'] = $this->search();

return $data;
}

/**
* Determine if request wants paginated data
* @return bool
Expand Down Expand Up @@ -161,9 +177,9 @@ public function embed()
$this->embed = explode(',', $this->embed);
}

$this->embed = array_map(function ($element) {
$this->embed = array_unique(array_map(function ($element) {
return strtr($element, ':', '.');
}, $this->embed);
}, $this->embed));
}

return $this->embed;
Expand Down Expand Up @@ -297,7 +313,7 @@ private function getFilters($rules)
* @param array $rules
*/
private function extractFilterConfig(array &$pointer, array $rules)
{
{
foreach ($rules as $rule) {
if ($rule === '') {
continue;
Expand All @@ -319,7 +335,7 @@ private function extractFilterConfig(array &$pointer, array $rules)
/**
* Add or replace request parameters
* @param $type string type of operation. Can be add or replace
* @param $array array associative array with parameter name and value
* @param $array array associative array with parameter name and value, where value must be a string
* @param $operator string
*/
public function set($type, $array, $operator = 'OR')
Expand All @@ -338,6 +354,8 @@ public function set($type, $array, $operator = 'OR')
}
}
}

$this->refresh($this->get);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Sigep/Request/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function testReplaceFilter()
'name' => 'luis'
);

$this->object->set('replace', array ('name' => ''));
$this->object->set('replace', array ('name' => ''));

$this->assertEquals(array (
), $this->object->filter());
Expand Down

0 comments on commit ff9b34a

Please sign in to comment.