ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContext.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 class ilContext
14 {
15  protected static $class_name; // [string]
16  protected static $type; // [int]
17 
18  const CONTEXT_WEB = 1;
19  const CONTEXT_CRON = 2;
20  const CONTEXT_RSS = 3;
21  const CONTEXT_ICAL = 4;
22  const CONTEXT_SOAP = 5;
23  const CONTEXT_WEBDAV = 6;
24  const CONTEXT_RSS_AUTH = 7;
28  const CONTEXT_UNITTEST = 11;
29  const CONTEXT_REST = 12;
30 
37  public static function init($a_type)
38  {
40  if($class_name)
41  {
42  include_once "Services/Context/classes/class.".$class_name.".php";
43  self::$class_name = $class_name;
44  self::$type = $a_type;
45  return true;
46  }
47  return false;
48  }
49 
56  protected function getClassForType($a_type)
57  {
58  switch($a_type)
59  {
60  case self::CONTEXT_WEB:
61  return "ilContextWeb";
62 
63  case self::CONTEXT_CRON:
64  return "ilContextCron";
65 
66  case self::CONTEXT_RSS:
67  return "ilContextRss";
68 
69  case self::CONTEXT_ICAL:
70  return "ilContextIcal";
71 
72  case self::CONTEXT_SOAP:
73  return "ilContextSoap";
74 
75  case self::CONTEXT_WEBDAV:
76  return "ilContextWebdav";
77 
78  case self::CONTEXT_RSS_AUTH:
79  return "ilContextRssAuth";
80 
81  case self::CONTEXT_WEB_ACCESS_CHECK:
82  return "ilContextWebAccessCheck";
83 
84  case self::CONTEXT_SESSION_REMINDER:
85  return "ilContextSessionReminder";
86 
87  case self::CONTEXT_SOAP_WITHOUT_CLIENT:
88  return "ilContextSoapWithoutClient";
89 
90  case self::CONTEXT_UNITTEST:
91  return "ilContextUnitTest";
92 
93  case self::CONTEXT_REST:
94  return 'ilContextRest';
95  }
96  }
97 
104  protected static function callContext($a_method)
105  {
106  if(!self::$class_name)
107  {
108  self::init(self::CONTEXT_WEB);
109  }
110  return call_user_func(array(self::$class_name, $a_method));
111  }
112 
118  public static function supportsRedirects()
119  {
120  global $ilCtrl;
121 
122  // asynchronous calls must never be redirected
123  if($ilCtrl && $ilCtrl->isAsynch())
124  {
125  return false;
126  }
127 
128  return (bool)self::callContext("supportsRedirects");
129  }
130 
136  public static function hasUser()
137  {
138  return (bool)self::callContext("hasUser");
139  }
140 
146  public static function usesHTTP()
147  {
148  return (bool)self::callContext("usesHTTP");
149  }
150 
156  public static function hasHTML()
157  {
158  return (bool)self::callContext("hasHTML");
159  }
160 
166  public static function usesTemplate()
167  {
168  return (bool)self::callContext("usesTemplate");
169  }
170 
176  public static function initClient()
177  {
178  return (bool)self::callContext("initClient");
179  }
180 
186  public static function doAuthentication()
187  {
188  return (bool)self::callContext("doAuthentication");
189  }
190 
196  public static function getType()
197  {
198  return self::$type;
199  }
200 }
201 
202 ?>