-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sagautam5/dev
Basic search and recursive search on each entity
- Loading branch information
Showing
19 changed files
with
329 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
|
||
namespace Sagautam5\LocalStateNepal\Entities; | ||
|
||
|
||
class BaseEntity | ||
{ | ||
/** | ||
* @var | ||
*/ | ||
protected $items; | ||
|
||
/** | ||
* Filter data by key value pair | ||
* | ||
* @param $key | ||
* @param $value | ||
* @param $data | ||
* @param bool $exact | ||
* @return array | ||
*/ | ||
protected function filter($key, $value, $data, $exact = false) | ||
{ | ||
return array_values(array_filter($data, function ($item) use ($key, $value, $exact) { | ||
return ($exact ? ($item->$key == $value ? true:false) :(is_int(strpos($item->$key, $value)) ? true:false)); | ||
})); | ||
} | ||
|
||
/** | ||
* Recursive Search Data | ||
* | ||
* @param $params | ||
* @param array $data | ||
* @return array|mixed | ||
*/ | ||
public function recursiveSearch($params, $data = []) | ||
{ | ||
$data = $data ? $data : $this->items; | ||
|
||
$param = count($params) ? array_pop($params):null; | ||
|
||
$data = $param ? $this->filter($param['key'], $param['value'], $data, $param['exact']):$data; | ||
|
||
return ($param && $data) ? $this->recursiveSearch($params, $data):$data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.