Skip to content

Core\Ldap\Ad\GroupType::with

$groupType->with({…}): Core\Ldap\Ad\GroupType$groupType->with(
    {…},
): Core\Ldap\Ad\GroupType

Returns a copy of a group type with some flags set or cleared, such as $type->with({ security: false }). Each option is one flag: true sets it, and false clears it. A flag you do not name stays as it is.

The object you call with on does not change. Call bits() on the copy to get the new number of groupType, for example to write it back to the directory.

with does not check that the flags make sense together. A group has exactly one scope, so when you change the scope, clear the old one and set the new one in the same call.

Options

  • systembooloptionaltrue sets the flag and false clears it. Leave it out to keep the flag as it is.
  • globalbooloptionaltrue sets the flag and false clears it. Leave it out to keep the flag as it is.
  • domainLocalbooloptionaltrue sets the flag and false clears it. Leave it out to keep the flag as it is.
  • universalbooloptionaltrue sets the flag and false clears it. Leave it out to keep the flag as it is.
  • appBasicbooloptionaltrue sets the flag and false clears it. Leave it out to keep the flag as it is.
  • appQuerybooloptionaltrue sets the flag and false clears it. Leave it out to keep the flag as it is.
  • securitybooloptionaltrue sets the flag and false clears it. Leave it out to keep the flag as it is.

Return value

Returns Core\Ldap\Ad\GroupType. A new Core\Ldap\Ad\GroupType. The object you call it on does not change.

Examples

The examples below run with this configuration file.

nvs.toml
# These examples use the LDAP directory server on this computer at port 16636.
# `tls_ca_file` is the certificate that the server's certificate is checked against.
[ldap.corp]
url = "ldaps://127.0.0.1:16636"
base = "DC=example,DC=test"
user = "CN=Reader,OU=Company,DC=example,DC=test"
password = "Novis-reader-1"
tls_ca_file = "../../../../../tests/db/ca.crt"
timeout = "5s"
# The program may open the `corp` directory.
[capabilities.ldap]
connect = ["corp"]

Make a security group

<?nvs
// Shows how to get the group type of a mailing list turned into a security group.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
var $type = $corp->read('CN=Newsletter,OU=Company,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) {
// `with` sets the flags you name and keeps every other flag.
var $changed = $type->with({ security: true });
// The group stays global. This prints `security: true, global: true`.
echo 'security: ', $changed->isSecurityGroup() ? 'true' : 'false';
echo ', global: ', $changed->isGlobal() ? 'true' : 'false', "\n";
}
Output
security: true, global: true

The original does not change

<?nvs
// Shows that `with` returns a new object, and the object you call it on does not change.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
var $type = $corp->read('CN=Employees,OU=Company,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) {
var $list = $type->with({ security: false });
// This prints `-2147483646` and then `2`.
echo $type->bits(), "\n";
echo $list->bits(), "\n";
}
Output
-2147483646
2

Change the scope

<?nvs
// Shows how to change the scope of a group from global to universal in one call.
// requires: samba-ad
var $corp = Core\Ldap::connect('corp');
var $type = $corp->read('CN=Managers,OU=Company,DC=example,DC=test', { select: ['groupType'] })?->groupType();
if ($type != null) {
// A group has one scope, so clear the `global` flag and set the `universal` flag together.
var $universal = $type->with({ global: false, universal: true });
// This prints `global: false, universal: true` and then `-2147483640`.
echo 'global: ', $universal->isGlobal() ? 'true' : 'false';
echo ', universal: ', $universal->isUniversal() ? 'true' : 'false', "\n";
echo $universal->bits(), "\n";
}
Output
global: false, universal: true
-2147483640