Start of using Attribute objects, rendering jpegphoto
This commit is contained in:
60
app/Classes/LDAP/Attribute/Binary.php
Normal file
60
app/Classes/LDAP/Attribute/Binary.php
Normal 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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
27
app/Classes/LDAP/Attribute/Binary/JpegPhoto.php
Normal file
27
app/Classes/LDAP/Attribute/Binary/JpegPhoto.php
Normal 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;
|
||||
}
|
||||
}
|
35
app/Classes/LDAP/Attribute/Factory.php
Normal file
35
app/Classes/LDAP/Attribute/Factory.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user