Created
October 7, 2020 20:13
-
-
Save tobyjoiner/499379774ea79cdacf9eae2000e3295b to your computer and use it in GitHub Desktop.
Search a class object for the methods available.
This file contains hidden or 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
class Query | |
{ | |
private $haystack; | |
private $matches; | |
public function handle($class, $find='') | |
{ | |
$this->getHaystack($class); | |
$this->setMatches($find); | |
return $this->matches; | |
// dd($this->haystack[0], $this->matches); | |
} | |
private function getHaystack($className) | |
{ | |
$this->haystack = get_class_methods($className); | |
return $this; | |
} | |
private function setMatches($needle){ | |
$this->matches = | |
array_filter( | |
$this->haystack, | |
function($var) use ($needle) { | |
return (bool)preg_match("/$needle/i",$var); | |
} | |
); | |
return $this; | |
} | |
} | |
$query = new Query; | |
$results = $query->handle(Illuminate\Support\Arr::class, 'save'); | |
dd($results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment