Commit 45afdc21 authored by Dainis Abols's avatar Dainis Abols
Browse files

Type updates

parent dfe6dfee
......@@ -2,7 +2,7 @@
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
use Lu\LDAPAuthorization\Types\TypeClass;
/**
* RequestType type
......@@ -11,46 +11,35 @@ use Psr\Log\LoggerAwareTrait;
* @owner University of Latvia
* @since 01.02.2022
*/
class RequestType
class RequestType extends TypeClass
{
use LoggerAwareTrait, TypeMethods;
use TypeMethods;
const BE = 'be';
const FE = 'fe';
/**
* Request type value
*
* @var string
*/
public string $value;
/**
* Validates value
*
* @param $value
* @return mixed
*/
private function validate($value)
public function validate($value)
{
if (!(strlen($value) > 0)) {
$this->logger->info(TypeErrors::REQUEST_TYPE_EMPTY);
$bt = debug_backtrace()[1];
unset($bt['object']); unset($bt['args']); unset($bt['type']);
$this->logger->error(TypeErrors::REQUEST_TYPE_EMPTY . ": " . print_r($bt, true));
}
if (!in_array($value, [RequestType::BE, RequestType::FE])) {
$this->logger->info(sprintf(TypeErrors::REQUEST_TYPE_INVALID, $value));
$bt = debug_backtrace()[1];
unset($bt['object']); unset($bt['args']); unset($bt['type']);
$this->logger->error(sprintf(TypeErrors::REQUEST_TYPE_INVALID, $value) . ": " . print_r($bt, true));
}
return $value;
}
/**
* Creates a valid `request_type`
*
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $this->validate($value);
}
}
......@@ -2,7 +2,7 @@
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
use Lu\LDAPAuthorization\Types\TypeClass;
/**
* Table type
......@@ -11,16 +11,9 @@ use Psr\Log\LoggerAwareTrait;
* @owner University of Latvia
* @since 01.02.2022
*/
class Table
class Table extends TypeClass
{
use LoggerAwareTrait, TypeMethods;
/**
* Database Table value
*
* @var string
*/
public string $value;
use TypeMethods;
/**
* Validates value
......@@ -28,22 +21,15 @@ class Table
* @param $value
* @return mixed
*/
private function validate($value)
public function validate($value)
{
if (!(strlen($value) > 0)) {
$this->logger->info(TypeErrors::TABLE_NAME_EMPTY);
$bt = debug_backtrace()[1];
unset($bt['object']); unset($bt['args']); unset($bt['type']);
$this->logger->warning(TypeErrors::TABLE_NAME_EMPTY . ": " . print_r($bt, true));
}
return $value;
}
/**
* Creates a valid `Table` name
*
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $this->validate($value);
}
}
......@@ -25,6 +25,6 @@ trait TypeMethods
*/
public function empty(): bool
{
return empty($this->value);
return empty($this->toString());
}
}
......@@ -2,7 +2,7 @@
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
use Lu\LDAPAuthorization\Types\TypeClass;
/**
* Username type
......@@ -11,16 +11,9 @@ use Psr\Log\LoggerAwareTrait;
* @owner University of Latvia
* @since 01.02.2022
*/
class Username
class Username extends TypeClass
{
use LoggerAwareTrait, TypeMethods;
/**
* Username value
*
* @var string
*/
public string $value;
use TypeMethods;
/**
* Validates value
......@@ -28,22 +21,15 @@ class Username
* @param $value
* @return mixed
*/
private function validate($value)
public function validate($value)
{
if (!(strlen($value) > 0)) {
$this->logger->info(TypeErrors::USERNAME_EMPTY);
$bt = debug_backtrace()[1];
unset($bt['object']); unset($bt['args']); unset($bt['type']);
$this->logger->info(TypeErrors::USERNAME_EMPTY . ": " . print_r($bt, true));
}
return $value;
}
/**
* Creates a valid `username`
*
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $this->validate($value);
}
}
This diff is collapsed.
{
"name": "luitd/lu-api",
"version": "3.0.0",
"version": "3.0.1",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
......
......@@ -14,7 +14,7 @@ $EM_CONF[$_EXTKEY] = [
'title' => 'LU API',
'description' => 'REST API Integration for TYPO3',
'category' => 'plugin',
'version' => '3.0.0',
'version' => 'v3.0.1',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment