Commit 6914f289 authored by Dainis Abols's avatar Dainis Abols
Browse files

Added main `TypeClass` as LDAPAuthorization extension

Version 3.0.4
parent b5050c98
......@@ -2,8 +2,6 @@
namespace Lu\LuApi\Types;
use Lu\LDAPAuthorization\Types\TypeClass;
/**
* RequestType type
*
......
......@@ -2,8 +2,6 @@
namespace Lu\LuApi\Types;
use Lu\LDAPAuthorization\Types\TypeClass;
/**
* Table type
*
......
<?php
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
/**
* Type class definitions
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @since 07.02.2022
*/
class TypeClass extends \Lu\LDAPAuthorization\Types\TypeClass
{
use LoggerAwareTrait;
/**
* Type value
*
* @var mixed
*/
private $value;
/**
* Validates value
*
* @param $value
*
* @return
*/
public function validate($value)
{
return $value;
}
/**
* Get value
*/
public function getValue()
{
return $this->value;
}
/**
* Creates a valid value
*
* @param $value
*/
public function __construct($value)
{
$this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
$this->value = $this->validate($value);
}
/**
* Overwrite default (string) modifier
*
* @return mixed|string
*/
public function __toString()
{
return $this->toString();
}
/**
* Retrieve string value
*
* @return mixed|string
*/
public function toString(): string
{
return (string)$this->value;
}
/**
* Retrieve int value
*
* @return int
*/
public function toInt(): int
{
return (int)$this->value;
}
/**
* Retrieve list value
*
* @return array
*/
public function toList(): array
{
return (array)$this->value;
}
/**
* Check if objects match
*
* @param $value
*
* @return bool
*/
public function equals($value): bool
{
return $this == $value;
}
/**
* Set values, to use in json
*/
public function jsonSerialize(): array
{
return [$this->value];
}
/**
* Convert to JSON
*
* @param bool $pretty
*
* @return string
*/
public function toJson(bool $pretty = false): string
{
return json_encode($this, $pretty ? JSON_PRETTY_PRINT : 0);
}
/**
* Convert to XML
*
* @param bool $pretty
*
* @return string
* @throws \Exception
*/
public function toXml(bool $pretty = false): string
{
// Fetch called class name
$classes = explode('\\', get_class($this));
$class_name = end($classes);
$object = new \SimpleXMLElement('<'.$class_name.'/>');
$data = is_array($this->value) ?: ['value' => $this->value];
foreach ($data as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
$this->to_xml($new_object, $value);
} else {
// if the key is an integer, it needs text with it to actually work.
if ($key != 0 && $key == (int)$key) {
$key = "key_$key";
}
$object->addChild($key, $value);
}
}
// Check for pretty print request
if ($pretty) {
$dom = new \DOMDocument('1.0');
$dom->preserveWhiteSpace = true;
$dom->formatOutput = true;
$dom->loadXML($object->asXML());
return $dom->saveXML();
}
return preg_replace("/\r|\n/", "", $object->asXML());
}
}
......@@ -2,8 +2,6 @@
namespace Lu\LuApi\Types;
use Lu\LDAPAuthorization\Types\TypeClass;
/**
* Username type
*
......
{
"name": "luitd/lu-api",
"version": "3.0.3",
"version": "3.0.4",
"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.3',
'version' => '3.0.4',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......
......@@ -4,7 +4,7 @@
## Version
3.0.3
3.0.4
## Dependencies
......
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