mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-13 07:18:39 +00:00
Test fixes
This commit is contained in:
parent
35ffdf666a
commit
20b07d5959
|
|
@ -77,33 +77,37 @@ class Client extends SocketAbstract
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while ($this->run) {
|
while ($this->run) {
|
||||||
$i++;
|
try {
|
||||||
$msg = 'disconnect';
|
$i++;
|
||||||
socket_write($this->sock, $msg, strlen($msg));
|
$msg = 'disconnect';
|
||||||
|
socket_write($this->sock, $msg, strlen($msg));
|
||||||
|
|
||||||
$read = [$this->sock];
|
$read = [$this->sock];
|
||||||
|
|
||||||
//if(socket_select($read, $write = null, $except = null, 0) < 1) {
|
//if(socket_select($read, $write = null, $except = null, 0) < 1) {
|
||||||
// error
|
// error
|
||||||
// socket_last_error();
|
// socket_last_error();
|
||||||
// socket_strerror(socket_last_error());
|
// socket_strerror(socket_last_error());
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (count($read) > 0) {
|
if (count($read) > 0) {
|
||||||
$data = socket_read($this->sock, 1024);
|
$data = socket_read($this->sock, 1024);
|
||||||
|
|
||||||
/* Server no data */
|
/* Server no data */
|
||||||
if ($data === false) {
|
if ($data === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normalize */
|
/* Normalize */
|
||||||
$data = trim($data);
|
$data = trim($data);
|
||||||
|
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
$data = explode(' ', $data);
|
$data = explode(' ', $data);
|
||||||
$this->commands->trigger($data[0], 0, $data);
|
$this->commands->trigger($data[0], 0, $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (\Error $e) {
|
||||||
|
$this->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
*/
|
*/
|
||||||
namespace phpOMS\Validation;
|
namespace phpOMS\Validation;
|
||||||
|
use phpOMS\Utils\StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validator class.
|
* Validator class.
|
||||||
|
|
@ -36,11 +37,11 @@ final class Validator extends ValidatorAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public static function isValid($var, $constraints)
|
public static function isValid($var, array $constraints)
|
||||||
{
|
{
|
||||||
foreach ($constraints as $callback => $settings) {
|
foreach ($constraints as $callback => $settings) {
|
||||||
$valid = self::$callback($var, ...$settings);
|
$valid = self::$callback($var, ...$settings);
|
||||||
$valid = (self::endsWith($callback, 'Not') ? $valid : !$valid);
|
$valid = (StringUtils::endsWith($callback, 'Not') ? $valid : !$valid);
|
||||||
|
|
||||||
if (!$valid) {
|
if (!$valid) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -50,27 +51,11 @@ final class Validator extends ValidatorAbstract
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* String ends with ?
|
|
||||||
*
|
|
||||||
* @param string $haystack String to search in
|
|
||||||
* @param string $needle String to search for
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public static function endsWith($haystack, $needle)
|
|
||||||
{
|
|
||||||
return $needle === '' || strpos($haystack, $needle, strlen($haystack) - strlen($needle)) !== false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate variable by type.
|
* Validate variable by type.
|
||||||
*
|
*
|
||||||
* @param mixed $var Variable to validate
|
* @param mixed $var Variable to validate
|
||||||
* @param string[] $constraint Array of allowed types
|
* @param string[]|string $constraint Array of allowed types
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
|
|
@ -79,6 +64,10 @@ final class Validator extends ValidatorAbstract
|
||||||
*/
|
*/
|
||||||
public static function isType($var, $constraint)
|
public static function isType($var, $constraint)
|
||||||
{
|
{
|
||||||
|
if (!is_array($constraint)) {
|
||||||
|
$constraint = [$constraint];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($constraint as $key => $value) {
|
foreach ($constraint as $key => $value) {
|
||||||
if (!is_a($var, $value)) {
|
if (!is_a($var, $value)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -100,7 +89,7 @@ final class Validator extends ValidatorAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public static function hasLength($var, $min = 0, $max = PHP_INT_MAX)
|
public static function hasLength(string $var, int $min = 0, int $max = PHP_INT_MAX)
|
||||||
{
|
{
|
||||||
$length = strlen($var);
|
$length = strlen($var);
|
||||||
|
|
||||||
|
|
@ -114,17 +103,17 @@ final class Validator extends ValidatorAbstract
|
||||||
/**
|
/**
|
||||||
* Validate variable by substring.
|
* Validate variable by substring.
|
||||||
*
|
*
|
||||||
* @param string $var Variable to validate
|
* @param string $var Variable to validate
|
||||||
* @param string $substr Substring
|
* @param string|array $substr Substring
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public static function contains($var, $substr)
|
public static function contains(string $var, $substr)
|
||||||
{
|
{
|
||||||
return (strpos($var, $substr) !== false ? true : false);
|
return StringUtils::contains($var, $substr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -138,7 +127,7 @@ final class Validator extends ValidatorAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public static function matches($var, $pattern)
|
public static function matches(string $var, string $pattern)
|
||||||
{
|
{
|
||||||
return (preg_match($pattern, $var) !== false ? true : false);
|
return (preg_match($pattern, $var) !== false ? true : false);
|
||||||
}
|
}
|
||||||
|
|
@ -163,20 +152,4 @@ final class Validator extends ValidatorAbstract
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* String starts with ?
|
|
||||||
*
|
|
||||||
* @param string $haystack String to search in
|
|
||||||
* @param string $needle String to search for
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public static function startsWith($haystack, $needle)
|
|
||||||
{
|
|
||||||
return $needle === '' || strrpos($haystack, $needle, -strlen($haystack)) !== false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -248,34 +248,6 @@ class View implements \Serializable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get view/template response.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function render() : string
|
|
||||||
{
|
|
||||||
$path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php');
|
|
||||||
|
|
||||||
if ($path === false || Validator::startsWith($path, ROOT_PATH) === false) {
|
|
||||||
throw new PathException($oldPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
$data = include $path;
|
|
||||||
$ob = ob_get_clean();
|
|
||||||
|
|
||||||
if (is_array($data)) {
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ob;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id Data Id
|
* @param string $id Data Id
|
||||||
*
|
*
|
||||||
|
|
@ -384,6 +356,34 @@ class View implements \Serializable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get view/template response.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function render() : string
|
||||||
|
{
|
||||||
|
$path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php');
|
||||||
|
|
||||||
|
if ($path === false || Validator::startsWith($path, ROOT_PATH) === false) {
|
||||||
|
throw new PathException($oldPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
/** @noinspection PhpIncludeInspection */
|
||||||
|
$data = include $path;
|
||||||
|
$ob = ob_get_clean();
|
||||||
|
|
||||||
|
if (is_array($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ob;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize view for rendering.
|
* Serialize view for rendering.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user