Added methods registerMethod() and reorderMethods() to \KimchiAPI > KimchiAPI
This commit is contained in:
parent
b48187c6e1
commit
56447575a5
|
@ -3,7 +3,9 @@
|
|||
namespace KimchiAPI;
|
||||
|
||||
// Define server information for response headers
|
||||
use KimchiAPI\Exceptions\MethodAlreadyRegisteredException;
|
||||
use KimchiAPI\Exceptions\MissingComponentsException;
|
||||
use KimchiAPI\Interfaces\MethodInterface;
|
||||
use KimchiAPI\Utilities\Converter;
|
||||
use RuntimeException;
|
||||
|
||||
|
@ -42,4 +44,35 @@
|
|||
$this->server_name = Converter::functionNameSafe($server_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodInterface $method
|
||||
* @throws MethodAlreadyRegisteredException
|
||||
*/
|
||||
public function registerMethod(MethodInterface $method)
|
||||
{
|
||||
if(isset($this->methods[$method->getVersion() . ':' . $method->getMethod()]))
|
||||
throw new MethodAlreadyRegisteredException('The method ' . $method->getMethod() . ' (' . $method->getVersion() . ') is already registered');
|
||||
|
||||
$this->methods[$method->getVersion() . ':' . $method->getMethod()] = $method;
|
||||
$this->reorderMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders the methods into alphabetical order
|
||||
*/
|
||||
private function reorderMethods()
|
||||
{
|
||||
$method_reordered = array_keys($this->methods);
|
||||
sort($method_reordered);
|
||||
$methods_clean = [];
|
||||
|
||||
foreach($method_reordered as $method_name)
|
||||
{
|
||||
if(is_int($method_name) == false)
|
||||
$methods_clean[$method_name] = $this->methods[$method_name];
|
||||
}
|
||||
|
||||
$this->methods = $methods_clean;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
namespace KimchiAPI\Objects;
|
||||
|
||||
use Exception;
|
||||
use KimchiRPC\Abstracts\Types\ProtocolType;
|
||||
|
||||
class Response
|
||||
{
|
||||
|
|
|
@ -37,4 +37,6 @@
|
|||
{
|
||||
return (strlen($input) > $length) ? substr($input,0, $length).'...' : $input;
|
||||
}
|
||||
|
||||
public static function methodResigtratio
|
||||
}
|
Loading…
Reference in New Issue