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\Protocol; 130b3fd2d3SAndreas Gohr 14*dad993c5SAndreas Gohruse Countable; 150b3fd2d3SAndreas Gohruse FreeDSx\Ldap\LdapUrl; 16*dad993c5SAndreas Gohruse function count; 17*dad993c5SAndreas Gohruse function strtolower; 180b3fd2d3SAndreas Gohr 190b3fd2d3SAndreas Gohr/** 200b3fd2d3SAndreas Gohr * Keeps track of referrals while they are being chased. 210b3fd2d3SAndreas Gohr * 220b3fd2d3SAndreas Gohr * @author Chad Sikorra <Chad.Sikorra@gmail.com> 230b3fd2d3SAndreas Gohr */ 24*dad993c5SAndreas Gohrclass ReferralContext implements Countable 250b3fd2d3SAndreas Gohr{ 260b3fd2d3SAndreas Gohr /** 270b3fd2d3SAndreas Gohr * @var LdapUrl[] 280b3fd2d3SAndreas Gohr */ 290b3fd2d3SAndreas Gohr protected $referrals = []; 300b3fd2d3SAndreas Gohr 310b3fd2d3SAndreas Gohr /** 320b3fd2d3SAndreas Gohr * @param LdapUrl ...$referrals 330b3fd2d3SAndreas Gohr */ 340b3fd2d3SAndreas Gohr public function __construct(LdapUrl ...$referrals) 350b3fd2d3SAndreas Gohr { 360b3fd2d3SAndreas Gohr $this->referrals = $referrals; 370b3fd2d3SAndreas Gohr } 380b3fd2d3SAndreas Gohr 390b3fd2d3SAndreas Gohr /** 400b3fd2d3SAndreas Gohr * @return LdapUrl[] 410b3fd2d3SAndreas Gohr */ 420b3fd2d3SAndreas Gohr public function getReferrals(): array 430b3fd2d3SAndreas Gohr { 440b3fd2d3SAndreas Gohr return $this->referrals; 450b3fd2d3SAndreas Gohr } 460b3fd2d3SAndreas Gohr 470b3fd2d3SAndreas Gohr /** 480b3fd2d3SAndreas Gohr * @param LdapUrl $referral 490b3fd2d3SAndreas Gohr * @return $this 500b3fd2d3SAndreas Gohr */ 510b3fd2d3SAndreas Gohr public function addReferral(LdapUrl $referral) 520b3fd2d3SAndreas Gohr { 530b3fd2d3SAndreas Gohr $this->referrals[] = $referral; 540b3fd2d3SAndreas Gohr 550b3fd2d3SAndreas Gohr return $this; 560b3fd2d3SAndreas Gohr } 570b3fd2d3SAndreas Gohr 580b3fd2d3SAndreas Gohr /** 590b3fd2d3SAndreas Gohr * @param LdapUrl $url 600b3fd2d3SAndreas Gohr * @return bool 610b3fd2d3SAndreas Gohr */ 620b3fd2d3SAndreas Gohr public function hasReferral(LdapUrl $url): bool 630b3fd2d3SAndreas Gohr { 640b3fd2d3SAndreas Gohr foreach ($this->referrals as $referral) { 65*dad993c5SAndreas Gohr if (strtolower($referral->toString()) === strtolower($url->toString())) { 660b3fd2d3SAndreas Gohr return true; 670b3fd2d3SAndreas Gohr } 680b3fd2d3SAndreas Gohr } 690b3fd2d3SAndreas Gohr 700b3fd2d3SAndreas Gohr return false; 710b3fd2d3SAndreas Gohr } 720b3fd2d3SAndreas Gohr 730b3fd2d3SAndreas Gohr /** 74*dad993c5SAndreas Gohr * @inheritDoc 75*dad993c5SAndreas Gohr * @psalm-return 0|positive-int 760b3fd2d3SAndreas Gohr */ 77*dad993c5SAndreas Gohr public function count(): int 780b3fd2d3SAndreas Gohr { 79*dad993c5SAndreas Gohr return count($this->referrals); 800b3fd2d3SAndreas Gohr } 810b3fd2d3SAndreas Gohr} 82