ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
CrawlerAssertion.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
6 
15 {
19  protected $f = null;
20 
21  public function __construct(){
22  $this->f = new Factory();
23  }
24 
29  public function isArray($array){
30  if(!is_array($array)){
31  throw $this->f->exception(CrawlerException::ARRAY_EXPECTED,$array);
32  }
33  }
34 
40  public function isString($string, $allow_empty = true){
41  if(!is_string($string)){
42  if(is_array($string)){
43  $string = json_encode($string);
44  }
45  throw $this->f->exception(CrawlerException::STRING_EXPECTED,(string)$string);
46  }if(!$allow_empty && $string == ""){
47  throw $this->f->exception(CrawlerException::EMPTY_STRING,(string)$string);
48  }
49  }
50 
56  public function isIndex($index, array $array){
57  if(!array_key_exists($index, $array)){
58  throw $this->f->exception(CrawlerException::INVALID_INDEX,$index);
59  }
60  }
61 
67  public function isNotIndex($index, array $array){
68  if(array_key_exists($index, $array)){
69  throw $this->f->exception(CrawlerException::DUPLICATE_ENTRY,$index);
70  }
71  }
72 
78  public function hasIndex($array,$index){
79  if(!array_key_exists($index, $array)){
80  throw $this->f->exception(CrawlerException::MISSING_INDEX,$index);
81  }
82  }
83 
89  public function isTypeOf($element,$class_name){
90  if(!get_class($element) == $class_name){
91  throw $this->f->exception(CrawlerException::INVALID_TYPE,"Expected: ".$class_name." got ".get_class($element));
92  }
93  }
94 }
Create styles array
The data for the language used.
Tests properties and throws exceptions if not met.