Added echoareas and fileareas

This commit is contained in:
Deon George
2021-08-11 23:45:30 +10:00
parent c7388c2db6
commit eb0405f019
19 changed files with 773 additions and 48 deletions

50
app/Traits/EncodeUTF8.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
/**
* Encode our data so that it can be serialised
*/
namespace App\Traits;
trait EncodeUTF8
{
private function encode(): array
{
$values = [];
$properties = (new \ReflectionClass($this))->getProperties();
$class = get_class($this);
foreach ($properties as $property) {
// Dont serialize the validation error
if ($property->name == 'errors')
continue;
if ($property->isStatic()) {
continue;
}
$property->setAccessible(true);
if (! $property->isInitialized($this)) {
continue;
}
$name = $property->getName();
$encode = in_array($name,self::cast_utf8);
if ($property->isPrivate()) {
$name = "\0{$class}\0{$name}";
} elseif ($property->isProtected()) {
$name = "\0*\0{$name}";
}
$property->setAccessible(true);
$value = $property->getValue($this);
$values[$name] = $encode ? utf8_encode($value) : $value;
}
return $values;
}
}