1<?php 2/** 3 * This file is part of the FreeDSx LDAP package. 4 * 5 * (c) Chad Sikorra <Chad.Sikorra@gmail.com> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11namespace FreeDSx\Ldap\Control\Ad; 12 13use FreeDSx\Asn1\Asn1; 14use FreeDSx\Asn1\Type\AbstractType; 15use FreeDSx\Asn1\Type\OctetStringType; 16use FreeDSx\Ldap\Control\Control; 17use FreeDSx\Ldap\Exception\ProtocolException; 18 19/** 20 * Implements the AD SetOwner control. 21 * 22 * SID octetString 23 * 24 * https://msdn.microsoft.com/en-us/library/dn392490.aspx 25 * @author Chad Sikorra <Chad.Sikorra@gmail.com> 26 */ 27class SetOwnerControl extends Control 28{ 29 /** 30 * @var string 31 */ 32 protected $sid; 33 34 /** 35 * @param string $sid 36 */ 37 public function __construct(string $sid) 38 { 39 $this->sid = $sid; 40 parent::__construct(self::OID_SET_OWNER, true); 41 } 42 43 /** 44 * @param string $sid 45 * @return $this 46 */ 47 public function setSid(string $sid) 48 { 49 $this->sid = $sid; 50 51 return $this; 52 } 53 54 /** 55 * @return string 56 */ 57 public function getSid(): string 58 { 59 return $this->sid; 60 } 61 62 /** 63 * {@inheritdoc} 64 */ 65 public function toAsn1(): AbstractType 66 { 67 $this->controlValue = Asn1::octetString($this->sid); 68 69 return parent::toAsn1(); 70 } 71 72 /** 73 * {@inheritdoc} 74 */ 75 public static function fromAsn1(AbstractType $type) 76 { 77 $request = self::decodeEncodedValue($type); 78 if (!$request instanceof OctetStringType) { 79 throw new ProtocolException('A SetOwner control value must be an octet string type.'); 80 } 81 /** @var OctetStringType $request */ 82 $control = new self( 83 $request->getValue() 84 ); 85 86 return self::mergeControlData($control, $type); 87 } 88} 89