1<?php 2// declare(strict_types=1); 3 4require_once './Services/ActiveRecord/class.ActiveRecord.php'; 5require_once './Services/WebAccessChecker/class.ilWACException.php'; 6 7/** 8 * Class ilWACSecurePath 9 * 10 * @author Fabian Schmid <fs@studer-raimann.ch> 11 * @version 1.0.0 12 */ 13class ilWACSecurePath extends ActiveRecord 14{ 15 16 /** 17 * @return string 18 * @description Return the Name of your Database Table 19 * @deprecated 20 */ 21 public static function returnDbTableName() 22 { 23 return 'il_wac_secure_path'; 24 } 25 26 27 /** 28 * Searches a checking instance for the given wac path. If a checking instance is found, wac will try to create a instance of the found checker. 29 * The path concatenation pattern for the inclusion is {ComponentDirectory}/classes/class.{CheckingClass}.php. Furthermore the included 30 * class must implement the ilWACCeckingClass interface. 31 * 32 * @param ilWACPath $ilWACPath The wac path which should be used to search a checking instance. 33 * 34 * @return ilWACCheckingClass The newly created checking instance. 35 * 36 * @throws ilWACException Thrown if the the checking instance is not found or if the concatenated path is not valid to the checking instance. 37 */ 38 public static function getCheckingInstance(ilWACPath $ilWACPath) 39 { 40 /** 41 * @var $obj ilWACSecurePath 42 */ 43 $obj = self::find($ilWACPath->getModuleType()); 44 if (!$obj) { 45 throw new ilWACException(ilWACException::CODE_NO_PATH, 'No Checking Instance found for id: ' . $ilWACPath->getSecurePathId()); 46 } 47 48 $secure_path_checking_class = $obj->getComponentDirectory() . '/classes/class.' . $obj->getCheckingClass() . '.php'; 49 if (!file_exists($secure_path_checking_class)) { 50 throw new ilWACException(ilWACException::CODE_NO_PATH, 'Checking Instance not found in path: ' . $secure_path_checking_class); 51 } 52 53 require_once($secure_path_checking_class); 54 $class_name = $obj->getCheckingClass(); 55 56 return new $class_name(); 57 } 58 59 60 /** 61 * Searches a checking instance for the given wac path. 62 * 63 * @param ilWACPath $ilWACPath The wac path which should be used to search the checking instance. 64 * 65 * @return bool true if a checking instance is found otherwise false. 66 */ 67 public static function hasCheckingInstanceRegistered(ilWACPath $ilWACPath) 68 { 69 $obj = self::find($ilWACPath->getModuleType()); 70 return !is_null($obj); 71 } 72 73 74 /** 75 * @return bool 76 */ 77 public function hasCheckingInstance() 78 { 79 return $this->has_checking_instance; 80 } 81 82 83 /** 84 * @var string 85 * 86 * @con_is_primary true 87 * @con_is_unique true 88 * @con_has_field true 89 * @con_fieldtype text 90 * @con_length 64 91 */ 92 protected $path = ''; 93 /** 94 * @var string 95 * 96 * @con_has_field true 97 * @con_fieldtype text 98 * @con_length 256 99 */ 100 protected $component_directory = ''; 101 /** 102 * @var string 103 * 104 * @con_has_field true 105 * @con_fieldtype text 106 * @con_length 256 107 */ 108 protected $checking_class = ''; 109 /** 110 * @var string 111 * 112 * @con_has_field true 113 * @con_fieldtype integer 114 * @con_length 1 115 */ 116 protected $in_sec_folder = false; 117 /** 118 * @var bool 119 */ 120 protected $has_checking_instance = false; 121 122 123 /** 124 * @return string 125 */ 126 public function getPath() 127 { 128 return (string) $this->path; 129 } 130 131 132 /** 133 * @param string $path 134 * @return void 135 */ 136 public function setPath($path) 137 { 138 assert(is_string($path)); 139 $this->path = $path; 140 } 141 142 143 /** 144 * @return string 145 */ 146 public function getComponentDirectory() 147 { 148 preg_match("/[\\\|\\/](Services|Modules|Customizing)[\\\|\\/].*/u", $this->component_directory, $matches); 149 150 return (string) '.' . $matches[0]; 151 } 152 153 154 /** 155 * @param string $component_directory 156 * @return void 157 */ 158 public function setComponentDirectory($component_directory) 159 { 160 assert(is_string($component_directory)); 161 $this->component_directory = $component_directory; 162 } 163 164 165 /** 166 * @return string 167 */ 168 public function getCheckingClass() 169 { 170 return (string) $this->checking_class; 171 } 172 173 174 /** 175 * @param string $checking_class 176 * @return void 177 */ 178 public function setCheckingClass($checking_class) 179 { 180 assert(is_string($checking_class)); 181 $this->checking_class = $checking_class; 182 } 183 184 185 /** 186 * @param bool $has_checking_instance 187 * @return void 188 */ 189 public function setHasCheckingInstance($has_checking_instance) 190 { 191 assert(is_bool($has_checking_instance)); 192 $this->has_checking_instance = $has_checking_instance; 193 } 194 195 196 /** 197 * @return string 198 */ 199 public function getInSecFolder() 200 { 201 return (string) $this->in_sec_folder; 202 } 203 204 205 /** 206 * @param string $in_sec_folder 207 */ 208 public function setInSecFolder($in_sec_folder) 209 { 210 // assert(is_string($in_sec_folder)); 211 $this->in_sec_folder = $in_sec_folder; 212 } 213} 214