ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ProxyChain.php
Go to the documentation of this file.
1<?php
2
44{
45
46 protected $chain = array();
47
60 public function __construct(array $chain)
61 {
62 // Ensure that we have an indexed array
63 $this->chain = array_values($chain);
64 }
65
73 public function matches(array $list)
74 {
75 $list = array_values($list); // Ensure that we have an indexed array
76 if ($this->isSizeValid($list)) {
77 $mismatch = false;
78 foreach ($this->chain as $i => $search) {
79 $proxy_url = $list[$i];
80 if (preg_match('/^\/.*\/[ixASUXu]*$/s', $search)) {
81 if (preg_match($search, $proxy_url)) {
83 "Found regexp " . $search . " matching " . $proxy_url
84 );
85 } else {
87 "No regexp match " . $search . " != " . $proxy_url
88 );
89 $mismatch = true;
90 break;
91 }
92 } else {
93 if (strncasecmp($search, $proxy_url, strlen($search)) == 0) {
95 "Found string " . $search . " matching " . $proxy_url
96 );
97 } else {
99 "No match " . $search . " != " . $proxy_url
100 );
101 $mismatch = true;
102 break;
103 }
104 }
105 }
106 if (!$mismatch) {
107 phpCAS::trace("Proxy chain matches");
108 return true;
109 }
110 } else {
111 phpCAS::trace("Proxy chain skipped: size mismatch");
112 }
113 return false;
114 }
115
123 protected function isSizeValid (array $list)
124 {
125 return (sizeof($this->chain) == sizeof($list));
126 }
127}
An exception for terminatinating execution or to throw for unit testing.
A normal proxy-chain definition that lists each level of the chain as either a string or regular expr...
Definition: ProxyChain.php:44
isSizeValid(array $list)
Validate the size of the the list as compared to our chain.
Definition: ProxyChain.php:123
matches(array $list)
Match a list of proxies.
Definition: ProxyChain.php:73
__construct(array $chain)
A chain is an array of strings or regexp strings that will be matched against.
Definition: ProxyChain.php:60
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:579
An interface for classes that define a list of allowed proxies in front of the current application.
Definition: Interface.php:42