nur-sery/nur_src/ldap/io/LdifWriter.php

31 lines
672 B
PHP
Raw Normal View History

2024-04-04 22:21:20 +04:00
<?php
namespace nur\ldap\io;
use nur\A;
use nur\ldap\LdapObject;
/**
* Class LdifWriter
*/
class LdifWriter extends LdapWriter {
function write(?LdapObject $object, ?array $names=null): self {
if ($object !== null) {
$writer = $this->writer;
if ($names === null) $names = $object->keys();
if (!in_array("dn", $names)) {
A::insert($names, 0, "dn");
}
foreach ($names as $name) {
$values = $object->_get($name)->array();
if ($values !== null) {
foreach ($values as $value) {
$writer->wnl("$name: $value");
}
}
}
$writer->wnl();
}
return $this;
}
}