public static function buildModel($action = 'find', $name, array $args)
{
$name = str_replace($action, '', $name);
preg_match('/By(.+)/', $name, $matches);
if (empty($matches) && $args[0] instanceof \Modler\Model) {
$model = $name;
$data = $args[0]->toArray();
} else {
$property = lcfirst($matches[1]);
$model = str_replace($matches[0], '', $name);
$data = array($property => $args[0]);
}
$modelNs = '\\Psecio\\Gatekeeper\\' . $model . 'Model';
if (!class_exists($modelNs)) {
throw new Exception\ModelNotFoundException('Model type ' . $model . ' could not be found');
}
$instance = new $modelNs(self::$datasource);
$instance = self::$datasource->find($instance, $data);
return $instance;
}