Skip to content

Instantly share code, notes, and snippets.

@hypertensy
Created August 10, 2020 10:12
Show Gist options
  • Save hypertensy/018289c0a598d7edeaccf18d8734b7e5 to your computer and use it in GitHub Desktop.
Save hypertensy/018289c0a598d7edeaccf18d8734b7e5 to your computer and use it in GitHub Desktop.
<?php
namespace Warface;
use Warface\Exceptions\WarfaceExceptions;
use Warface\Exceptions\WarfaceExceptionsCode;
use Warface\Exceptions\WarfaceExceptionsMsg;
class ApiClient
{
private RequestController $controller;
/**
* ApiClient constructor.
* @param string $region
*/
public function __construct(string $region = RequestController::REGION_RU)
{
$this->controller = new RequestController($region);
}
/**
* @param $methodName
* @param $arguments
* @return mixed
* @throws WarfaceExceptions
*/
public function __call($methodName, $arguments)
{
$class = __NAMESPACE__ . "\Methods\\" . ucfirst($methodName);
if (!class_exists($class)) {
throw new WarfaceExceptions(WarfaceExceptionsMsg::MSG_BRANCH_METHOD_NOT_FOUND, WarfaceExceptionsCode::CODE_REQUEST_NOT_FOUND);
}
return new $class($this->controller);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment