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

30 lines
662 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;
use nur\yaml;
/**
* Class YamlWriter
*/
class YamlWriter extends LdapWriter {
function write(?LdapObject $object, ?array $names=null): self {
if ($object !== null) {
if ($names === null) $names = $object->keys();
if (!in_array("dn", $names)) {
A::insert($names, 0, "dn");
}
$values = [];
foreach ($names as $name) {
$value = $object->all($name);
if (count($value) == 1) $value = $value[0];
$values[$name] = $value;
}
$writer = $this->writer;
$writer->wnl(yaml::with($values));
}
return $this;
}
}