10b3fd2d3SAndreas Gohr<?php 2*dad993c5SAndreas Gohr 30b3fd2d3SAndreas Gohr/** 40b3fd2d3SAndreas Gohr * This file is part of the FreeDSx LDAP package. 50b3fd2d3SAndreas Gohr * 60b3fd2d3SAndreas Gohr * (c) Chad Sikorra <Chad.Sikorra@gmail.com> 70b3fd2d3SAndreas Gohr * 80b3fd2d3SAndreas Gohr * For the full copyright and license information, please view the LICENSE 90b3fd2d3SAndreas Gohr * file that was distributed with this source code. 100b3fd2d3SAndreas Gohr */ 110b3fd2d3SAndreas Gohr 120b3fd2d3SAndreas Gohrnamespace FreeDSx\Ldap; 130b3fd2d3SAndreas Gohr 140b3fd2d3SAndreas Gohruse FreeDSx\Asn1\Type\AbstractType; 150b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Ad\DirSyncRequestControl; 160b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Ad\ExpectedEntryCountControl; 170b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Ad\ExtendedDnControl; 180b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Ad\PolicyHintsControl; 190b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Ad\SdFlagsControl; 200b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Ad\SetOwnerControl; 210b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Control; 220b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\PagingControl; 230b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Sorting\SortingControl; 240b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Sorting\SortKey; 250b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Control\Vlv\VlvControl; 260b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Protocol\ProtocolElementInterface; 270b3fd2d3SAndreas Gohruse FreeDSx\Ldap\Search\Filter\GreaterThanOrEqualFilter; 280b3fd2d3SAndreas Gohr 290b3fd2d3SAndreas Gohr/** 300b3fd2d3SAndreas Gohr * Provides some simple factory methods for building controls. 310b3fd2d3SAndreas Gohr * 320b3fd2d3SAndreas Gohr * @author Chad Sikorra <Chad.Sikorra@gmail.com> 330b3fd2d3SAndreas Gohr */ 340b3fd2d3SAndreas Gohrclass Controls 350b3fd2d3SAndreas Gohr{ 360b3fd2d3SAndreas Gohr /** 370b3fd2d3SAndreas Gohr * Create a generic control by OID. 380b3fd2d3SAndreas Gohr * 390b3fd2d3SAndreas Gohr * @param string $oid 400b3fd2d3SAndreas Gohr * @param bool $criticality 410b3fd2d3SAndreas Gohr * @param AbstractType|ProtocolElementInterface|null $value 420b3fd2d3SAndreas Gohr * @return Control 430b3fd2d3SAndreas Gohr */ 440b3fd2d3SAndreas Gohr public static function create(string $oid, bool $criticality = false, $value = null): Control 450b3fd2d3SAndreas Gohr { 460b3fd2d3SAndreas Gohr return new Control($oid, $criticality, $value); 470b3fd2d3SAndreas Gohr } 480b3fd2d3SAndreas Gohr 490b3fd2d3SAndreas Gohr /** 500b3fd2d3SAndreas Gohr * Creates an AD DirSync request control. 510b3fd2d3SAndreas Gohr * 520b3fd2d3SAndreas Gohr * @param int $flags 530b3fd2d3SAndreas Gohr * @param string $cookie 540b3fd2d3SAndreas Gohr * @param int $maxBytes 550b3fd2d3SAndreas Gohr * @return DirSyncRequestControl 560b3fd2d3SAndreas Gohr */ 570b3fd2d3SAndreas Gohr public static function dirSync(int $flags = DirSyncRequestControl::FLAG_INCREMENTAL_VALUES, string $cookie = '', int $maxBytes = 2147483647) 580b3fd2d3SAndreas Gohr { 590b3fd2d3SAndreas Gohr return new DirSyncRequestControl($flags, $cookie, $maxBytes); 600b3fd2d3SAndreas Gohr } 610b3fd2d3SAndreas Gohr 620b3fd2d3SAndreas Gohr /** 630b3fd2d3SAndreas Gohr * Create an AD ExpectedEntryCount control to help restrict / validate the amount of entries returned from a search. 640b3fd2d3SAndreas Gohr * 650b3fd2d3SAndreas Gohr * @param int $min 660b3fd2d3SAndreas Gohr * @param int $max 670b3fd2d3SAndreas Gohr * @return ExpectedEntryCountControl 680b3fd2d3SAndreas Gohr */ 690b3fd2d3SAndreas Gohr public static function expectedEntryCount(int $min, int $max): ExpectedEntryCountControl 700b3fd2d3SAndreas Gohr { 710b3fd2d3SAndreas Gohr return new ExpectedEntryCountControl($min, $max); 720b3fd2d3SAndreas Gohr } 730b3fd2d3SAndreas Gohr 740b3fd2d3SAndreas Gohr /** 750b3fd2d3SAndreas Gohr * Create an AD ExtendedDn control. 760b3fd2d3SAndreas Gohr * 770b3fd2d3SAndreas Gohr * @param bool $useHexFormat 780b3fd2d3SAndreas Gohr * @return ExtendedDnControl 790b3fd2d3SAndreas Gohr */ 800b3fd2d3SAndreas Gohr public static function extendedDn(bool $useHexFormat = false): ExtendedDnControl 810b3fd2d3SAndreas Gohr { 820b3fd2d3SAndreas Gohr return new ExtendedDnControl($useHexFormat); 830b3fd2d3SAndreas Gohr } 840b3fd2d3SAndreas Gohr 850b3fd2d3SAndreas Gohr /** 860b3fd2d3SAndreas Gohr * Create a paging control with a specific size. 870b3fd2d3SAndreas Gohr * 880b3fd2d3SAndreas Gohr * @param int $size 890b3fd2d3SAndreas Gohr * @param string $cookie 900b3fd2d3SAndreas Gohr * @return PagingControl 910b3fd2d3SAndreas Gohr */ 920b3fd2d3SAndreas Gohr public static function paging(int $size, string $cookie = ''): PagingControl 930b3fd2d3SAndreas Gohr { 940b3fd2d3SAndreas Gohr return new PagingControl($size, $cookie); 950b3fd2d3SAndreas Gohr } 960b3fd2d3SAndreas Gohr 970b3fd2d3SAndreas Gohr /** 980b3fd2d3SAndreas Gohr * Create an AD Policy Hints control. This enforces password constraints when modifying an AD password. 990b3fd2d3SAndreas Gohr * 1000b3fd2d3SAndreas Gohr * @param bool $isEnabled 1010b3fd2d3SAndreas Gohr * @return PolicyHintsControl 1020b3fd2d3SAndreas Gohr */ 1030b3fd2d3SAndreas Gohr public static function policyHints(bool $isEnabled = true): PolicyHintsControl 1040b3fd2d3SAndreas Gohr { 1050b3fd2d3SAndreas Gohr return new PolicyHintsControl($isEnabled); 1060b3fd2d3SAndreas Gohr } 1070b3fd2d3SAndreas Gohr 1080b3fd2d3SAndreas Gohr /** 1090b3fd2d3SAndreas Gohr * Create a password policy control. 1100b3fd2d3SAndreas Gohr * 1110b3fd2d3SAndreas Gohr * @param bool $criticality 1120b3fd2d3SAndreas Gohr * @return Control 1130b3fd2d3SAndreas Gohr */ 1140b3fd2d3SAndreas Gohr public static function pwdPolicy(bool $criticality = true): Control 1150b3fd2d3SAndreas Gohr { 1160b3fd2d3SAndreas Gohr return new Control(Control::OID_PWD_POLICY, $criticality); 1170b3fd2d3SAndreas Gohr } 1180b3fd2d3SAndreas Gohr 1190b3fd2d3SAndreas Gohr /** 1200b3fd2d3SAndreas Gohr * Create an AD Set Owner control. Pass it a string SID and use when adding objects to set the owner. 1210b3fd2d3SAndreas Gohr * 1220b3fd2d3SAndreas Gohr * @param string $sid 1230b3fd2d3SAndreas Gohr * @return SetOwnerControl 1240b3fd2d3SAndreas Gohr */ 1250b3fd2d3SAndreas Gohr public static function setOwner(string $sid): SetOwnerControl 1260b3fd2d3SAndreas Gohr { 1270b3fd2d3SAndreas Gohr return new SetOwnerControl($sid); 1280b3fd2d3SAndreas Gohr } 1290b3fd2d3SAndreas Gohr 1300b3fd2d3SAndreas Gohr /** 1310b3fd2d3SAndreas Gohr * Create an AD Show Deleted control. This will return deleted AD entries in a search. 1320b3fd2d3SAndreas Gohr * 1330b3fd2d3SAndreas Gohr * @return Control 1340b3fd2d3SAndreas Gohr */ 1350b3fd2d3SAndreas Gohr public static function showDeleted(): Control 1360b3fd2d3SAndreas Gohr { 1370b3fd2d3SAndreas Gohr return self::create(Control::OID_SHOW_DELETED, true); 1380b3fd2d3SAndreas Gohr } 1390b3fd2d3SAndreas Gohr 1400b3fd2d3SAndreas Gohr /** 1410b3fd2d3SAndreas Gohr * Create an AD Show Recycled control. This will return recycled AD entries in a search. 1420b3fd2d3SAndreas Gohr * 1430b3fd2d3SAndreas Gohr * @return Control 1440b3fd2d3SAndreas Gohr */ 1450b3fd2d3SAndreas Gohr public static function showRecycled(): Control 1460b3fd2d3SAndreas Gohr { 1470b3fd2d3SAndreas Gohr return self::create(Control::OID_SHOW_RECYCLED, true); 1480b3fd2d3SAndreas Gohr } 1490b3fd2d3SAndreas Gohr 1500b3fd2d3SAndreas Gohr /** 1510b3fd2d3SAndreas Gohr * Create a server side sort with a set of SortKey objects, or simple set of attribute names. 1520b3fd2d3SAndreas Gohr * 153*dad993c5SAndreas Gohr * @param SortKey|string ...$sortKeys 1540b3fd2d3SAndreas Gohr * @return SortingControl 1550b3fd2d3SAndreas Gohr */ 1560b3fd2d3SAndreas Gohr public static function sort(...$sortKeys): SortingControl 1570b3fd2d3SAndreas Gohr { 1580b3fd2d3SAndreas Gohr $keys = []; 1590b3fd2d3SAndreas Gohr foreach ($sortKeys as $sort) { 1600b3fd2d3SAndreas Gohr $keys[] = $sort instanceof SortKey ? $sort : new SortKey($sort); 1610b3fd2d3SAndreas Gohr } 1620b3fd2d3SAndreas Gohr 1630b3fd2d3SAndreas Gohr return new SortingControl(...$keys); 1640b3fd2d3SAndreas Gohr } 1650b3fd2d3SAndreas Gohr 1660b3fd2d3SAndreas Gohr /** 1670b3fd2d3SAndreas Gohr * Create a control for a subtree delete. On a delete request this will do a recursive delete from the DN and all 1680b3fd2d3SAndreas Gohr * of its children. 1690b3fd2d3SAndreas Gohr * 1700b3fd2d3SAndreas Gohr * @param bool $criticality 1710b3fd2d3SAndreas Gohr * @return Control 1720b3fd2d3SAndreas Gohr */ 1730b3fd2d3SAndreas Gohr public static function subtreeDelete(bool $criticality = false): Control 1740b3fd2d3SAndreas Gohr { 1750b3fd2d3SAndreas Gohr return new Control(Control::OID_SUBTREE_DELETE, $criticality); 1760b3fd2d3SAndreas Gohr } 1770b3fd2d3SAndreas Gohr 1780b3fd2d3SAndreas Gohr /** 1790b3fd2d3SAndreas Gohr * Create a VLV offset based control. 1800b3fd2d3SAndreas Gohr * 1810b3fd2d3SAndreas Gohr * @param int $before 1820b3fd2d3SAndreas Gohr * @param int $after 1830b3fd2d3SAndreas Gohr * @param int $offset 1840b3fd2d3SAndreas Gohr * @param int $count 1850b3fd2d3SAndreas Gohr * @param null|string $contextId 1860b3fd2d3SAndreas Gohr * @return VlvControl 1870b3fd2d3SAndreas Gohr */ 1880b3fd2d3SAndreas Gohr public static function vlv(int $before, int $after, int $offset = 1, int $count = 0, ?string $contextId = null): VlvControl 1890b3fd2d3SAndreas Gohr { 1900b3fd2d3SAndreas Gohr return new VlvControl($before, $after, $offset, $count, null, $contextId); 1910b3fd2d3SAndreas Gohr } 1920b3fd2d3SAndreas Gohr 1930b3fd2d3SAndreas Gohr /** 1940b3fd2d3SAndreas Gohr * Create a VLV filter based control. 1950b3fd2d3SAndreas Gohr * 1960b3fd2d3SAndreas Gohr * @param int $before 1970b3fd2d3SAndreas Gohr * @param int $after 1980b3fd2d3SAndreas Gohr * @param GreaterThanOrEqualFilter $filter 1990b3fd2d3SAndreas Gohr * @param null|string $contextId 2000b3fd2d3SAndreas Gohr * @return VlvControl 2010b3fd2d3SAndreas Gohr */ 2020b3fd2d3SAndreas Gohr public static function vlvFilter(int $before, int $after, GreaterThanOrEqualFilter $filter, ?string $contextId = null): VlvControl 2030b3fd2d3SAndreas Gohr { 2040b3fd2d3SAndreas Gohr return new VlvControl($before, $after, null, null, $filter, $contextId); 2050b3fd2d3SAndreas Gohr } 2060b3fd2d3SAndreas Gohr 2070b3fd2d3SAndreas Gohr /** 2080b3fd2d3SAndreas Gohr * Create an AD SD Flags Control. 2090b3fd2d3SAndreas Gohr * 2100b3fd2d3SAndreas Gohr * @param int $flags 2110b3fd2d3SAndreas Gohr * @return SdFlagsControl 2120b3fd2d3SAndreas Gohr */ 2130b3fd2d3SAndreas Gohr public static function sdFlags(int $flags): SdFlagsControl 2140b3fd2d3SAndreas Gohr { 2150b3fd2d3SAndreas Gohr return new SdFlagsControl($flags); 2160b3fd2d3SAndreas Gohr } 2170b3fd2d3SAndreas Gohr} 218