Start of using Attribute objects, rendering jpegphoto

This commit is contained in:
Deon George
2021-12-08 23:26:12 +11:00
parent 2ccc1d3b83
commit a80a2725bc
10 changed files with 147 additions and 99 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Classes\LDAP\Attribute;
use App\Classes\LDAP\Attribute;
/**
* Represents an attribute whose values are binary
*
* @package phpLDAPadmin
* @subpackage Templates
*/
class Binary extends Attribute
{
/*
protected $filepaths;
protected $filenames;
public function __construct($name,$values,$server_id,$source=null) {
parent::__construct($name,$values,$server_id,$source);
$this->filepaths = array();
$this->filenames = array();
}
public function getFileNames() {
return $this->filenames;
}
public function getFileName($i) {
if (isset($this->filenames[$i])) return $this->filenames[$i];
else return null;
}
public function addFileName($name, $i = -1) {
if ($i < 0) {
$this->filenames[] = $name;
} else {
$this->filenames[$i] = $name;
}
}
public function getFilePaths() {
return $this->filepaths;
}
public function getFilePath($i) {
if (isset($this->filepaths[$i])) return $this->filepaths[$i];
else return null;
}
public function addFilePath($path, $i = -1) {
if ($i < 0) {
$this->filepaths[] = $path;
} else {
$this->filepaths[$i] = $path;
}
}
*/
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Classes\LDAP\Attribute\Binary;
use App\Classes\LDAP\Attribute\Binary;
/**
* Represents an attribute whose values are jpeg pictures
*/
class JpegPhoto extends Binary
{
public function __toString(): string
{
$result = '';
$f = new \finfo;
foreach ($this->values as $value) {
switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) {
case 'image/jpeg':
default:
$result .= sprintf("<img style='display:block; width:100px;height:100px;' src='data:%s;base64, %s' />",$x,base64_encode($value));
}
}
return $result;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Classes\LDAP\Attribute;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
use App\Classes\LDAP\{Attribute};
class Factory
{
private const LOGKEY = 'LAf';
/**
* @var array event type to event class mapping
*/
public const map = [
'jpegphoto'=>Attribute\Binary\JpegPhoto::class,
];
/**
* Returns new event instance
*
* @param string $attribute
* @param array $values
* @return Attribute
*/
public static function create(string $attribute,array $values): Attribute
{
$class = Arr::get(self::map,strtolower($attribute),Attribute::class);
Log::debug(sprintf('%s:Creating LDAP Attribute [%s] as [%s]',static::LOGKEY,$attribute,$class));
return new $class($attribute,$values);
}
}