<?php
namespace Koselig\Proxy;
use Illuminate\Support\Str;
use WP_Query;
class Query
{
private $query;
public static function instance(WP_Query $query)
{
$instance = new static;
$instance->query = $query;
return $instance;
}
public function __get($name)
{
return $this->query->{Str::snake($name)};
}
public function __call($name, $arguments)
{
$name = Str::snake($name);
$name = str_replace('has', 'have', $name);
if (!method_exists($this->query, $name)) {
if (method_exists($this->query, 'the_' . $name)) {
$name = 'the_' . $name;
} elseif (method_exists($this->query, 'is_' . $name)) {
$name = 'is_' . $name;
} elseif (method_exists($this->query, 'get_' . $name)) {
$name = 'get_' . $name;
}
}
return $this->query->{$name}(...$arguments);
}
}