Skip to content

Instantly share code, notes, and snippets.

@tobyjoiner
Created October 7, 2020 20:13
Show Gist options
  • Save tobyjoiner/499379774ea79cdacf9eae2000e3295b to your computer and use it in GitHub Desktop.
Save tobyjoiner/499379774ea79cdacf9eae2000e3295b to your computer and use it in GitHub Desktop.
Search a class object for the methods available.
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