Commit fd333ff6 authored by Dainis Abols's avatar Dainis Abols
Browse files

New Type Class `EmptyTypeClass`, added debug methods to DataHelper,

parent 6914f289
......@@ -21,7 +21,7 @@ class LuisContacts
*
* @array
*/
private $conf = [];
private $conf;
/**
* The desired request type
......
......@@ -195,4 +195,146 @@ class DataHelper
return $result;
}
static public function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
static public function isArnisIpAddress()
{
return in_array(self::getRealIpAddr(), ['5.179.12.250', '10.0.42.2']);
}
static public function isDainisIpAddress()
{
return in_array(self::getRealIpAddr(), ['5.179.12.220','5.179.19.241']);
}
static public function isLaurisIpAddress()
{
return in_array(self::getRealIpAddr(), ['5.179.12.225', '5.179.12.204']);
}
/**
* Debug function for data output
*
* @param $var
* @param bool $die
* @param string $trace
*
* @return void
*/
static public function ddump($var, bool $die, string $trace = ""): void
{
// Add style for pretty view ✌(◕‿-)✌
echo '<style>pre { overflow: auto; border: 1px solid #f0f0f0; padding: 15px 10px 10px 10px; margin: 10px; width: calc(100%-20px); background-color: #fefefe; }</style>';
// Echo trace
if ($trace) {
echo '<span style="color: #bbbbbb; font-size: 12px; margin: -10px 0 0 30px; position: absolute; padding: 5px; background-color: #fff;">'.$trace.'</span>';
}
// Echo with different styles
if ($var === null) {
echo '<pre><em style="color: blue;">null</em></pre>';
} else if ($var === '') {
echo '<pre><em style="color: blue;">empty string</em></pre>';
} else if ($var === false) {
echo '<pre><em style="color: red;">false</em></pre>';
} else if ($var === true) {
echo '<pre><em style="color: green;">true</em></pre>';
} else if (is_array($var) && empty($var)) {
echo '<pre><em style="color: blue;">empty array</em></pre>';
} else if (is_object($var) && empty($var)) {
echo '<pre><em style="color: blue;">empty object</em></pre>';
} else if (is_array($var) || is_object($var)) {
echo '<pre>', print_r($var, true), '</pre>';
} else {
echo '<pre>', print_r($var, true), '</pre>';
}
// Check if die requested
if ($die) {
die();
}
}
/**
* Debug function with die at the end
*
* @param $var
* @param bool $die
*/
static public function ddd($var, bool $die = true)
{
// Don't allow execution if not local DEV IP address
if (!self::isDainisIpAddress()) {
return;
}
// Go to dump
self::ddump($var, $die, self::getCaller());
}
/**
* Debug function with die at the end
*
* @param $var
* @param bool $die
*/
static public function da($var, bool $die = true)
{
// Don't allow execution if not local DEV IP address
if (!self::isArnisIpAddress()) {
return;
}
// Go to dump
self::ddump($var, $die, self::getCaller());
}
/**
* Debug function with die at the end
*
* @param $var
* @param bool $die
*/
static public function dk($var, bool $die = true)
{
// Don't allow execution if not local DEV IP address
if (!self::isLaurisIpAddress()) {
return;
}
// Go to dump
self::ddump($var, $die, self::getCaller());
}
/**
* Fetch caller location
*
* @return string
*/
static public function getCaller(): string
{
global $CFG;
$trace = debug_backtrace();
$caller = $trace[1];
$caller = str_replace(@$CFG->dirroot.'/mod/luolimpmanager/', null, $caller['file']) . ' @line ' . $caller['line'];
return $caller;
}
}
\ No newline at end of file
<?php
namespace Lu\LuApi\Types;
use Psr\Log\LoggerAwareTrait;
/**
* Type class definitions
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @since 07.02.2022
*/
class EmptyTypeClass 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()
{
$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());
}
}
{
"name": "luitd/lu-api",
"version": "3.0.4",
"version": "3.0.5",
"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.4',
'version' => '3.0.5',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......
......@@ -4,7 +4,7 @@
## Version
3.0.4
3.0.5
## 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