From 69919837436a475cc45216d75031e013374015c3 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 20 Jan 2024 10:36:30 +1100 Subject: [PATCH] Rework Components to use consistent variables and interface --- app/Classes/LDAP/Attribute.php | 27 ++++++++++++++----- .../LDAP/Attribute/Binary/JpegPhoto.php | 7 ++--- app/Classes/LDAP/Attribute/Internal.php | 2 +- .../LDAP/Attribute/Internal/Timestamp.php | 2 +- app/Classes/LDAP/Attribute/ObjectClass.php | 6 +++-- app/Classes/LDAP/Attribute/Password.php | 7 ++--- app/Classes/LDAP/Attribute/Schema.php | 2 +- .../LDAP/Attribute/Schema/Mechanisms.php | 2 +- app/Classes/LDAP/Attribute/Schema/OID.php | 2 +- app/View/Components/Attribute.php | 8 +++--- .../views/components/attribute-type.blade.php | 2 +- .../attribute/binary/jpegphoto.blade.php | 4 +-- 12 files changed, 46 insertions(+), 25 deletions(-) diff --git a/app/Classes/LDAP/Attribute.php b/app/Classes/LDAP/Attribute.php index b4857d7..5a185bc 100644 --- a/app/Classes/LDAP/Attribute.php +++ b/app/Classes/LDAP/Attribute.php @@ -101,7 +101,7 @@ class Attribute implements \Countable, \ArrayAccess $this->values = collect($values); $this->lang_tags = collect(); $this->required_by = collect(); - $this->oldValues = collect(); + $this->oldValues = collect($values); // No need to load our schema for internal attributes if (! $this->is_internal) @@ -143,6 +143,8 @@ class Attribute implements \Countable, \ArrayAccess 'name' => $this->schema ? $this->schema->{$key} : $this->{$key}, // Attribute name in lower case 'name_lc' => strtolower($this->name), + // Old Values + 'old_values' => $this->oldValues, // Attribute values 'values' => $this->values, @@ -150,9 +152,20 @@ class Attribute implements \Countable, \ArrayAccess }; } + public function __set(string $key,mixed $values): void + { + switch ($key) { + case 'value': + $this->values = collect($values); + break; + + default: + } + } + public function __toString(): string { - return $this->__get('name'); + return $this->name; } public function count(): int @@ -230,15 +243,17 @@ class Attribute implements \Countable, \ArrayAccess * Display the attribute value * * @param bool $edit - * @param bool $blank + * @param bool $old + * @param bool $new * @return View */ - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { return view('components.attribute') + ->with('o',$this) ->with('edit',$edit) - ->with('new',FALSE) - ->with('o',$this); + ->with('old',$old) + ->with('new',$new); } /** diff --git a/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php b/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php index a9ae277..b1a68fe 100644 --- a/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php +++ b/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php @@ -21,12 +21,13 @@ final class JpegPhoto extends Binary $this->internal = FALSE; } - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { return view('components.attribute.binary.jpegphoto') - ->with('edit',$edit) - ->with('blank',$blank) ->with('o',$this) + ->with('edit',$edit) + ->with('old',$old) + ->with('new',$new) ->with('f',new \finfo); } } \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Internal.php b/app/Classes/LDAP/Attribute/Internal.php index d0c6029..a2848c3 100644 --- a/app/Classes/LDAP/Attribute/Internal.php +++ b/app/Classes/LDAP/Attribute/Internal.php @@ -13,7 +13,7 @@ abstract class Internal extends Attribute { protected bool $is_internal = TRUE; - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { // @note Internal attributes cannot be edited return view('components.attribute.internal') diff --git a/app/Classes/LDAP/Attribute/Internal/Timestamp.php b/app/Classes/LDAP/Attribute/Internal/Timestamp.php index 64adf22..52070f5 100644 --- a/app/Classes/LDAP/Attribute/Internal/Timestamp.php +++ b/app/Classes/LDAP/Attribute/Internal/Timestamp.php @@ -11,7 +11,7 @@ use App\Classes\LDAP\Attribute\Internal; */ final class Timestamp extends Internal { - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { // @note Internal attributes cannot be edited return view('components.attribute.internal.timestamp') diff --git a/app/Classes/LDAP/Attribute/ObjectClass.php b/app/Classes/LDAP/Attribute/ObjectClass.php index fa6b0fe..e2b42c9 100644 --- a/app/Classes/LDAP/Attribute/ObjectClass.php +++ b/app/Classes/LDAP/Attribute/ObjectClass.php @@ -39,10 +39,12 @@ final class ObjectClass extends Attribute return $this->structural->search($value) !== FALSE; } - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { return view('components.attribute.objectclass') + ->with('o',$this) ->with('edit',$edit) - ->with('o',$this); + ->with('old',$old) + ->with('new',$new); } } \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Password.php b/app/Classes/LDAP/Attribute/Password.php index 1a64c9c..ba182bd 100644 --- a/app/Classes/LDAP/Attribute/Password.php +++ b/app/Classes/LDAP/Attribute/Password.php @@ -14,11 +14,12 @@ final class Password extends Attribute { use MD5Updates; - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { return view('components.attribute.password') + ->with('o',$this) ->with('edit',$edit) - ->with('blank',$blank) - ->with('o',$this); + ->with('old',$old) + ->with('new',$new); } } \ No newline at end of file diff --git a/app/Classes/LDAP/Attribute/Schema.php b/app/Classes/LDAP/Attribute/Schema.php index be47dfb..ef5699c 100644 --- a/app/Classes/LDAP/Attribute/Schema.php +++ b/app/Classes/LDAP/Attribute/Schema.php @@ -49,7 +49,7 @@ abstract class Schema extends Attribute return Arr::get(($array ? $array->get($string) : []),$key); } - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { // @note Schema attributes cannot be edited return view('components.attribute.internal') diff --git a/app/Classes/LDAP/Attribute/Schema/Mechanisms.php b/app/Classes/LDAP/Attribute/Schema/Mechanisms.php index 6cf4480..8034b93 100644 --- a/app/Classes/LDAP/Attribute/Schema/Mechanisms.php +++ b/app/Classes/LDAP/Attribute/Schema/Mechanisms.php @@ -33,7 +33,7 @@ final class Mechanisms extends Schema return parent::_get(config_path('ldap_supported_saslmechanisms.txt'),$string,$key); } - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { // @note Schema attributes cannot be edited return view('components.attribute.schema.mechanisms') diff --git a/app/Classes/LDAP/Attribute/Schema/OID.php b/app/Classes/LDAP/Attribute/Schema/OID.php index 1c0a26e..77a75d3 100644 --- a/app/Classes/LDAP/Attribute/Schema/OID.php +++ b/app/Classes/LDAP/Attribute/Schema/OID.php @@ -34,7 +34,7 @@ final class OID extends Schema return parent::_get(config_path('ldap_supported_oids.txt'),$string,$key); } - public function render(bool $edit=FALSE,bool $blank=FALSE): View + public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { // @note Schema attributes cannot be edited return view('components.attribute.schema.oid') diff --git a/app/View/Components/Attribute.php b/app/View/Components/Attribute.php index 58168e6..b5599fb 100644 --- a/app/View/Components/Attribute.php +++ b/app/View/Components/Attribute.php @@ -11,16 +11,18 @@ class Attribute extends Component public LDAPAttribute $o; public bool $edit; public bool $new; + public bool $old; /** * Create a new component instance. * * @return void */ - public function __construct(bool $edit,LDAPAttribute $o,bool $new=FALSE) + public function __construct(LDAPAttribute $o,bool $edit,bool $old=FALSE,bool $new=FALSE) { - $this->edit = $edit; $this->o = $o; + $this->edit = $edit; + $this->old = $old; $this->new = $new; } @@ -31,6 +33,6 @@ class Attribute extends Component */ public function render() { - return $this->o->render($this->edit,$this->new); + return $this->o->render($this->edit,$this->old,$this->new); } } \ No newline at end of file diff --git a/resources/views/components/attribute-type.blade.php b/resources/views/components/attribute-type.blade.php index e376b27..f684b12 100644 --- a/resources/views/components/attribute-type.blade.php +++ b/resources/views/components/attribute-type.blade.php @@ -15,6 +15,6 @@ - + \ No newline at end of file diff --git a/resources/views/components/attribute/binary/jpegphoto.blade.php b/resources/views/components/attribute/binary/jpegphoto.blade.php index 03c7bb0..e8ab6e7 100644 --- a/resources/views/components/attribute/binary/jpegphoto.blade.php +++ b/resources/views/components/attribute/binary/jpegphoto.blade.php @@ -1,8 +1,8 @@ - + - @foreach ($o->values as $value) + @foreach (($old ? $o->old_values : $o->values) as $value) @switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) @case('image/jpeg')