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\Protocol; 12 13use FreeDSx\Ldap\LdapUrl; 14 15/** 16 * Keeps track of referrals while they are being chased. 17 * 18 * @author Chad Sikorra <Chad.Sikorra@gmail.com> 19 */ 20class ReferralContext 21{ 22 /** 23 * @var LdapUrl[] 24 */ 25 protected $referrals = []; 26 27 /** 28 * @param LdapUrl ...$referrals 29 */ 30 public function __construct(LdapUrl ...$referrals) 31 { 32 $this->referrals = $referrals; 33 } 34 35 /** 36 * @return LdapUrl[] 37 */ 38 public function getReferrals(): array 39 { 40 return $this->referrals; 41 } 42 43 /** 44 * @param LdapUrl $referral 45 * @return $this 46 */ 47 public function addReferral(LdapUrl $referral) 48 { 49 $this->referrals[] = $referral; 50 51 return $this; 52 } 53 54 /** 55 * @param LdapUrl $url 56 * @return bool 57 */ 58 public function hasReferral(LdapUrl $url): bool 59 { 60 foreach ($this->referrals as $referral) { 61 if (\strtolower($referral->toString()) === \strtolower($url->toString())) { 62 return true; 63 } 64 } 65 66 return false; 67 } 68 69 /** 70 * @return int 71 */ 72 public function count() 73 { 74 return \count($this->referrals); 75 } 76} 77