Attribute is no longer iterable - cant be used now that we manage attribute tags

This commit is contained in:
Deon George 2025-04-05 14:49:45 +11:00
parent cf535286c5
commit 28f4869628
3 changed files with 17 additions and 39 deletions

View File

@ -12,7 +12,7 @@ use App\Ldap\Entry;
/**
* Represents an attribute of an LDAP Object
*/
class Attribute implements \Countable, \ArrayAccess, \Iterator
class Attribute implements \Countable, \ArrayAccess
{
// Attribute Name
protected string $name;
@ -181,44 +181,19 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
/* INTERFACE */
public function current(): mixed
{
return $this->values->get($this->counter);
}
public function next(): void
{
$this->counter++;
}
public function key(): mixed
{
return $this->counter;
}
public function valid(): bool
{
return $this->values->has($this->counter);
}
public function rewind(): void
{
$this->counter = 0;
}
public function count(): int
{
return $this->values->count();
return $this->_values->dot()->count();
}
public function offsetExists(mixed $offset): bool
{
return ! is_null($this->values->has($offset));
return $this->_values->dot()->has($offset);
}
public function offsetGet(mixed $offset): mixed
{
return $this->values->get($offset);
return $this->_values->dot()->get($offset);
}
public function offsetSet(mixed $offset, mixed $value): void
@ -323,12 +298,12 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
public function render_item_old(string $dotkey): ?string
{
return Arr::get($this->_values_old->dot(),$dotkey);
return Arr::get($this->values_old->dot(),$dotkey);
}
public function render_item_new(string $dotkey): ?string
{
return Arr::get($this->_values->dot(),$dotkey);
return Arr::get($this->values->dot(),$dotkey);
}
/**

View File

@ -267,19 +267,22 @@ class HomeController extends Controller
// We need to process and encrypt the password
if ($request->userpassword) {
$passwords = [];
foreach ($request->userpassword as $key => $value) {
$po = $o->getObject('userpassword');
foreach (Arr::dot($request->userpassword) as $dotkey => $value) {
// If the password is still the MD5 of the old password, then it hasnt changed
if (($old=Arr::get($o->userpassword,$key)) && ($value === md5($old))) {
array_push($passwords,$old);
if (($old=Arr::get($po,$dotkey)) && ($value === md5($old))) {
$passwords[$dotkey] = $value;
continue;
}
if ($value) {
$type = Arr::get($request->userpassword_hash,$key);
array_push($passwords,Password::hash_id($type)->encode($value));
$type = Arr::get($request->userpassword_hash,$dotkey);
$passwords[$dotkey] = Password::hash_id($type)
->encode($value);
}
}
$o->userpassword = $passwords;
$o->userpassword = Arr::undot($passwords);
}
if (! $o->getDirty())

View File

@ -11,8 +11,8 @@ trait MD5Updates
{
public function isDirty(): bool
{
foreach ($this->values->diff($this->values_old) as $key => $value)
if (md5(Arr::get($this->values_old,$key)) !== $value)
foreach ($this->values_old->dot()->keys()->merge($this->values->dot()->keys())->unique() as $dotkey)
if (md5(Arr::get($this->values_old->dot(),$dotkey)) !== Arr::get($this->values->dot(),$dotkey))
return TRUE;
return FALSE;