64 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Classes\LDAP\Attribute;
use Illuminate\Contracts\View\View;
2023-04-12 08:17:57 +10:00
use Illuminate\Support\Collection;
use App\Classes\LDAP\Attribute;
/**
2023-03-02 18:21:53 +11:00
* Represents an ObjectClass Attribute
*/
final class ObjectClass extends Attribute
{
// The schema ObjectClasses for this objectclass of a DN
protected Collection $oc_schema;
2023-04-12 08:17:57 +10:00
/**
* Create an ObjectClass Attribute
*
* @param string $dn DN this attribute is used in
* @param string $name Name of the attribute
* @param array $values Current Values
* @param array $oc The objectclasses that the DN of this attribute has
*/
public function __construct(string $dn,string $name,array $values,array $oc=[])
{
parent::__construct($dn,$name,$values,['top']);
2023-04-12 08:17:57 +10:00
$this->oc_schema = config('server')
->schema('objectclasses')
->filter(fn($item)=>$this->values->merge($this->values_old)->unique()->contains($item->name));
}
2023-04-12 08:17:57 +10:00
public function __get(string $key): mixed
{
return match ($key) {
'structural' => $this->oc_schema->filter(fn($item) => $item->isStructural()),
default => parent::__get($key),
};
}
2023-04-12 08:17:57 +10:00
/**
* Is a specific value the structural objectclass
*
* @param string $value
* @return bool
*/
public function isStructural(string $value): bool
{
return $this->structural
->map(fn($item)=>$item->name)
->contains($value);
2023-04-12 08:17:57 +10:00
}
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('old',$old)
->with('new',$new);
}
}