PageRenderTime 73ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 2ms

/libs/Nette/loader.php

https://github.com/vrana/mvc-exception-demo
PHP | 5110 lines | 4867 code | 207 blank | 36 comment | 172 complexity | dd45e470084c05f79f3a6bac5f762b97 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php //netteloader=IComponent
  2. /**
  3. * Nette Framework
  4. *
  5. * Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)
  6. *
  7. * This source file is subject to the "Nette license" that is bundled
  8. * with this package in the file license.txt, and/or GPL license.
  9. *
  10. * For more information please see http://nette.org
  11. *
  12. * @copyright Copyright (c) 2004, 2010 David Grudl
  13. * @license http://nette.org/license Nette license
  14. * @link http://nette.org
  15. * @category Nette
  16. * @package Nette
  17. */
  18. if(!defined('PHP_VERSION_ID')){$tmp=explode('.',PHP_VERSION);define('PHP_VERSION_ID',($tmp[0]*10000+$tmp[1]*100+$tmp[2]));}if(PHP_VERSION_ID<50200){throw
  19. new
  20. Exception('Nette Framework requires PHP 5.2.0 or newer.');}error_reporting(E_ALL|E_STRICT);@set_magic_quotes_runtime(FALSE);iconv_set_encoding('internal_encoding','UTF-8');extension_loaded('mbstring')&&mb_internal_encoding('UTF-8');header('X-Powered-By: Nette Framework');define('NETTE',TRUE);define('NETTE_VERSION_ID',10000);define('NETTE_PACKAGE','PHP 5.2');function
  21. callback($callback,$m=NULL){return($m===NULL&&$callback
  22. instanceof
  23. Callback)?$callback:new
  24. Callback($callback,$m);}function
  25. dump($var){foreach(func_get_args()as$arg)Debug::dump($arg);return$var;}interface
  26. IComponent{const
  27. NAME_SEPARATOR='-';function
  28. getName();function
  29. getParent();function
  30. setParent(IComponentContainer$parent=NULL,$name=NULL);}interface
  31. IComponentContainer
  32. extends
  33. IComponent{function
  34. addComponent(IComponent$component,$name);function
  35. removeComponent(IComponent$component);function
  36. getComponent($name);function
  37. getComponents($deep=FALSE,$filterType=NULL);}interface
  38. INamingContainer
  39. extends
  40. IComponentContainer{}interface
  41. ISignalReceiver{function
  42. signalReceived($signal);}interface
  43. IStatePersistent{function
  44. loadState(array$params);function
  45. saveState(array&$params);}interface
  46. IRenderable{function
  47. invalidateControl();function
  48. isControlInvalid();}interface
  49. IPartiallyRenderable
  50. extends
  51. IRenderable{}interface
  52. IPresenter{function
  53. run(PresenterRequest$request);}interface
  54. IPresenterLoader{function
  55. getPresenterClass(&$name);}interface
  56. IPresenterResponse{function
  57. send();}interface
  58. IRouter{const
  59. ONE_WAY=1;const
  60. SECURED=2;function
  61. match(IHttpRequest$httpRequest);function
  62. constructUrl(PresenterRequest$appRequest,IHttpRequest$httpRequest);}interface
  63. IDebugPanel{function
  64. getTab();function
  65. getPanel();function
  66. getId();}interface
  67. ICacheStorage{function
  68. read($key);function
  69. write($key,$data,array$dependencies);function
  70. remove($key);function
  71. clean(array$conds);}interface
  72. IConfigAdapter{static
  73. function
  74. load($file,$section=NULL);static
  75. function
  76. save($config,$file,$section=NULL);}interface
  77. IServiceLocator{function
  78. addService($name,$service,$singleton=TRUE,array$options=NULL);function
  79. getService($name,array$options=NULL);function
  80. removeService($name);function
  81. hasService($name);}interface
  82. IFormControl{function
  83. loadHttpData();function
  84. setValue($value);function
  85. getValue();function
  86. getRules();function
  87. getErrors();function
  88. isDisabled();function
  89. translate($s,$count=NULL);}interface
  90. ISubmitterControl
  91. extends
  92. IFormControl{function
  93. isSubmittedBy();function
  94. getValidationScope();}interface
  95. IFormRenderer{function
  96. render(Form$form);}interface
  97. IMailer{function
  98. send(Mail$mail);}interface
  99. IAnnotation{function
  100. __construct(array$values);}interface
  101. IAuthenticator{const
  102. USERNAME='username';const
  103. PASSWORD='password';const
  104. IDENTITY_NOT_FOUND=1;const
  105. INVALID_CREDENTIAL=2;const
  106. FAILURE=3;const
  107. NOT_APPROVED=4;function
  108. authenticate(array$credentials);}interface
  109. IAuthorizator{const
  110. ALL=NULL;const
  111. ALLOW=TRUE;const
  112. DENY=FALSE;function
  113. isAllowed($role=self::ALL,$resource=self::ALL,$privilege=self::ALL);}interface
  114. IIdentity{function
  115. getId();function
  116. getRoles();}interface
  117. IResource{function
  118. getResourceId();}interface
  119. IRole{function
  120. getRoleId();}interface
  121. ITemplate{function
  122. render();}interface
  123. IFileTemplate
  124. extends
  125. ITemplate{function
  126. setFile($file);function
  127. getFile();}interface
  128. ITranslator{function
  129. translate($message,$count=NULL);}interface
  130. IHttpRequest{const
  131. GET='GET',POST='POST',HEAD='HEAD',PUT='PUT',DELETE='DELETE';function
  132. getUri();function
  133. getQuery($key=NULL,$default=NULL);function
  134. getPost($key=NULL,$default=NULL);function
  135. getPostRaw();function
  136. getFile($key);function
  137. getFiles();function
  138. getCookie($key,$default=NULL);function
  139. getCookies();function
  140. getMethod();function
  141. isMethod($method);function
  142. getHeader($header,$default=NULL);function
  143. getHeaders();function
  144. isSecured();function
  145. isAjax();function
  146. getRemoteAddress();function
  147. getRemoteHost();}interface
  148. IHttpResponse{const
  149. PERMANENT=2116333333;const
  150. BROWSER=0;const
  151. S200_OK=200,S204_NO_CONTENT=204,S300_MULTIPLE_CHOICES=300,S301_MOVED_PERMANENTLY=301,S302_FOUND=302,S303_SEE_OTHER=303,S303_POST_GET=303,S304_NOT_MODIFIED=304,S307_TEMPORARY_REDIRECT=307,S400_BAD_REQUEST=400,S401_UNAUTHORIZED=401,S403_FORBIDDEN=403,S404_NOT_FOUND=404,S405_METHOD_NOT_ALLOWED=405,S410_GONE=410,S500_INTERNAL_SERVER_ERROR=500,S501_NOT_IMPLEMENTED=501,S503_SERVICE_UNAVAILABLE=503;function
  152. setCode($code);function
  153. getCode();function
  154. setHeader($name,$value);function
  155. addHeader($name,$value);function
  156. setContentType($type,$charset=NULL);function
  157. redirect($url,$code=self::S302_FOUND);function
  158. setExpiration($seconds);function
  159. isSent();function
  160. getHeaders();function
  161. setCookie($name,$value,$expire,$path=NULL,$domain=NULL,$secure=NULL);function
  162. deleteCookie($name,$path=NULL,$domain=NULL,$secure=NULL);}interface
  163. IUser{function
  164. login($username,$password,$extra=NULL);function
  165. logout($clearIdentity=FALSE);function
  166. isLoggedIn();function
  167. getIdentity();function
  168. setAuthenticationHandler(IAuthenticator$handler);function
  169. getAuthenticationHandler();function
  170. setNamespace($namespace);function
  171. getNamespace();function
  172. getRoles();function
  173. isInRole($role);function
  174. isAllowed();function
  175. setAuthorizationHandler(IAuthorizator$handler);function
  176. getAuthorizationHandler();}class
  177. ArgumentOutOfRangeException
  178. extends
  179. InvalidArgumentException{}class
  180. InvalidStateException
  181. extends
  182. RuntimeException{function
  183. __construct($message='',$code=0,Exception$previous=NULL){if(PHP_VERSION_ID<50300){$this->previous=$previous;parent::__construct($message,$code);}else{parent::__construct($message,$code,$previous);}}}class
  184. NotImplementedException
  185. extends
  186. LogicException{}class
  187. NotSupportedException
  188. extends
  189. LogicException{}class
  190. DeprecatedException
  191. extends
  192. NotSupportedException{}class
  193. MemberAccessException
  194. extends
  195. LogicException{}class
  196. IOException
  197. extends
  198. RuntimeException{}class
  199. FileNotFoundException
  200. extends
  201. IOException{}class
  202. DirectoryNotFoundException
  203. extends
  204. IOException{}class
  205. FatalErrorException
  206. extends
  207. Exception{private$severity;function
  208. __construct($message,$code,$severity,$file,$line,$context){parent::__construct($message,$code);$this->severity=$severity;$this->file=$file;$this->line=$line;$this->context=$context;}function
  209. getSeverity(){return$this->severity;}}final
  210. class
  211. Framework{const
  212. NAME='Nette Framework';const
  213. VERSION='1.0-dev';const
  214. REVISION='1ac0863 released on 2010-07-01';final
  215. function
  216. __construct(){throw
  217. new
  218. LogicException("Cannot instantiate static class ".get_class($this));}static
  219. function
  220. promo(){echo'<a href="http://nette.org" title="Nette Framework - The Most Innovative PHP Framework"><img ','src="http://files.nette.org/icons/nette-powered.gif" alt="Powered by Nette Framework" width="80" height="15" /></a>';}}abstract
  221. class
  222. Object{function
  223. getReflection(){return
  224. new
  225. ClassReflection($this);}function
  226. __call($name,$args){return
  227. ObjectMixin::call($this,$name,$args);}static
  228. function
  229. __callStatic($name,$args){$class=get_called_class();throw
  230. new
  231. MemberAccessException("Call to undefined static method $class::$name().");}static
  232. function
  233. extensionMethod($name,$callback=NULL){if(strpos($name,'::')===FALSE){$class=get_called_class();}else{list($class,$name)=explode('::',$name);}$class=new
  234. ClassReflection($class);if($callback===NULL){return$class->getExtensionMethod($name);}else{$class->setExtensionMethod($name,$callback);}}function&__get($name){return
  235. ObjectMixin::get($this,$name);}function
  236. __set($name,$value){return
  237. ObjectMixin::set($this,$name,$value);}function
  238. __isset($name){return
  239. ObjectMixin::has($this,$name);}function
  240. __unset($name){throw
  241. new
  242. MemberAccessException("Cannot unset the property {$this->reflection->name}::\$$name.");}}final
  243. class
  244. ObjectMixin{private
  245. static$methods;final
  246. function
  247. __construct(){throw
  248. new
  249. LogicException("Cannot instantiate static class ".get_class($this));}static
  250. function
  251. call($_this,$name,$args){$class=new
  252. ClassReflection($_this);if($name===''){throw
  253. new
  254. MemberAccessException("Call to class '$class->name' method without name.");}if($class->hasEventProperty($name)){if(is_array($list=$_this->$name)||$list
  255. instanceof
  256. Traversable){foreach($list
  257. as$handler){callback($handler)->invokeArgs($args);}}return
  258. NULL;}if($cb=$class->getExtensionMethod($name)){array_unshift($args,$_this);return$cb->invokeArgs($args);}throw
  259. new
  260. MemberAccessException("Call to undefined method $class->name::$name().");}static
  261. function&get($_this,$name){$class=get_class($_this);if($name===''){throw
  262. new
  263. MemberAccessException("Cannot read a class '$class' property without name.");}if(!isset(self::$methods[$class])){self::$methods[$class]=array_flip(get_class_methods($class));}$name[0]=$name[0]&"\xDF";$m='get'.$name;if(isset(self::$methods[$class][$m])){$val=$_this->$m();return$val;}$m='is'.$name;if(isset(self::$methods[$class][$m])){$val=$_this->$m();return$val;}$name=func_get_arg(1);throw
  264. new
  265. MemberAccessException("Cannot read an undeclared property $class::\$$name.");}static
  266. function
  267. set($_this,$name,$value){$class=get_class($_this);if($name===''){throw
  268. new
  269. MemberAccessException("Cannot write to a class '$class' property without name.");}if(!isset(self::$methods[$class])){self::$methods[$class]=array_flip(get_class_methods($class));}$name[0]=$name[0]&"\xDF";if(isset(self::$methods[$class]['get'.$name])||isset(self::$methods[$class]['is'.$name])){$m='set'.$name;if(isset(self::$methods[$class][$m])){$_this->$m($value);return;}else{$name=func_get_arg(1);throw
  270. new
  271. MemberAccessException("Cannot write to a read-only property $class::\$$name.");}}$name=func_get_arg(1);throw
  272. new
  273. MemberAccessException("Cannot write to an undeclared property $class::\$$name.");}static
  274. function
  275. has($_this,$name){if($name===''){return
  276. FALSE;}$class=get_class($_this);if(!isset(self::$methods[$class])){self::$methods[$class]=array_flip(get_class_methods($class));}$name[0]=$name[0]&"\xDF";return
  277. isset(self::$methods[$class]['get'.$name])||isset(self::$methods[$class]['is'.$name]);}}final
  278. class
  279. Callback
  280. extends
  281. Object{private$cb;function
  282. __construct($t,$m=NULL){if($m===NULL){$this->cb=$t;}else{$this->cb=array($t,$m);}if(is_object($this->cb)){$this->cb=array($this->cb,'__invoke');}elseif(PHP_VERSION_ID<50202){if(is_string($this->cb)&&strpos($this->cb,':')){$this->cb=explode('::',$this->cb);}if(is_array($this->cb)&&is_string($this->cb[0])&&$a=strrpos($this->cb[0],'\\')){$this->cb[0]=substr($this->cb[0],$a+1);}}else{if(is_string($this->cb)&&$a=strrpos($this->cb,'\\')){$this->cb=substr($this->cb,$a+1);}elseif(is_array($this->cb)&&is_string($this->cb[0])&&$a=strrpos($this->cb[0],'\\')){$this->cb[0]=substr($this->cb[0],$a+1);}}if(!is_callable($this->cb,TRUE)){throw
  283. new
  284. InvalidArgumentException("Invalid callback.");}}function
  285. __invoke(){if(!is_callable($this->cb)){throw
  286. new
  287. InvalidStateException("Callback '$this' is not callable.");}$args=func_get_args();return
  288. call_user_func_array($this->cb,$args);}function
  289. invoke(){if(!is_callable($this->cb)){throw
  290. new
  291. InvalidStateException("Callback '$this' is not callable.");}$args=func_get_args();return
  292. call_user_func_array($this->cb,$args);}function
  293. invokeArgs(array$args){if(!is_callable($this->cb)){throw
  294. new
  295. InvalidStateException("Callback '$this' is not callable.");}return
  296. call_user_func_array($this->cb,$args);}function
  297. isCallable(){return
  298. is_callable($this->cb);}function
  299. getNative(){return$this->cb;}function
  300. __toString(){is_callable($this->cb,TRUE,$textual);return$textual;}}final
  301. class
  302. LimitedScope{private
  303. static$vars;final
  304. function
  305. __construct(){throw
  306. new
  307. LogicException("Cannot instantiate static class ".get_class($this));}static
  308. function
  309. evaluate(){if(func_num_args()>1){self::$vars=func_get_arg(1);extract(self::$vars);}return
  310. eval('?>'.func_get_arg(0));}static
  311. function
  312. load(){if(func_num_args()>1){self::$vars=func_get_arg(1);extract(self::$vars);}return include func_get_arg(0);}}abstract
  313. class
  314. AutoLoader
  315. extends
  316. Object{static
  317. private$loaders=array();public
  318. static$count=0;final
  319. static
  320. function
  321. load($type){foreach(func_get_args()as$type){if(!class_exists($type)){throw
  322. new
  323. InvalidStateException("Unable to load class or interface '$type'.");}}}final
  324. static
  325. function
  326. getLoaders(){return
  327. array_values(self::$loaders);}function
  328. register(){if(!function_exists('spl_autoload_register')){throw
  329. new
  330. RuntimeException('spl_autoload does not exist in this PHP installation.');}spl_autoload_register(array($this,'tryLoad'));self::$loaders[spl_object_hash($this)]=$this;}function
  331. unregister(){unset(self::$loaders[spl_object_hash($this)]);return
  332. spl_autoload_unregister(array($this,'tryLoad'));}abstract
  333. function
  334. tryLoad($type);}abstract
  335. class
  336. Component
  337. extends
  338. Object
  339. implements
  340. IComponent{private$parent;private$name;private$monitors=array();function
  341. __construct(IComponentContainer$parent=NULL,$name=NULL){if($parent!==NULL){$parent->addComponent($this,$name);}elseif(is_string($name)){$this->name=$name;}}function
  342. lookup($type,$need=TRUE){if($a=strrpos($type,'\\'))$type=substr($type,$a+1);if(!isset($this->monitors[$type])){$obj=$this->parent;$path=self::NAME_SEPARATOR.$this->name;$depth=1;while($obj!==NULL){if($obj
  343. instanceof$type)break;$path=self::NAME_SEPARATOR.$obj->getName().$path;$depth++;$obj=$obj->getParent();if($obj===$this)$obj=NULL;}if($obj){$this->monitors[$type]=array($obj,$depth,substr($path,1),FALSE);}else{$this->monitors[$type]=array(NULL,NULL,NULL,FALSE);}}if($need&&$this->monitors[$type][0]===NULL){throw
  344. new
  345. InvalidStateException("Component '$this->name' is not attached to '$type'.");}return$this->monitors[$type][0];}function
  346. lookupPath($type,$need=TRUE){if($a=strrpos($type,'\\'))$type=substr($type,$a+1);$this->lookup($type,$need);return$this->monitors[$type][2];}function
  347. monitor($type){if($a=strrpos($type,'\\'))$type=substr($type,$a+1);if(empty($this->monitors[$type][3])){if($obj=$this->lookup($type,FALSE)){$this->attached($obj);}$this->monitors[$type][3]=TRUE;}}function
  348. unmonitor($type){if($a=strrpos($type,'\\'))$type=substr($type,$a+1);unset($this->monitors[$type]);}protected
  349. function
  350. attached($obj){}protected
  351. function
  352. detached($obj){}final
  353. function
  354. getName(){return$this->name;}final
  355. function
  356. getParent(){return$this->parent;}function
  357. setParent(IComponentContainer$parent=NULL,$name=NULL){if($parent===NULL&&$this->parent===NULL&&$name!==NULL){$this->name=$name;return$this;}elseif($parent===$this->parent&&$name===NULL){return$this;}if($this->parent!==NULL&&$parent!==NULL){throw
  358. new
  359. InvalidStateException("Component '$this->name' already has a parent.");}if($parent===NULL){$this->refreshMonitors(0);$this->parent=NULL;}else{$this->validateParent($parent);$this->parent=$parent;if($name!==NULL)$this->name=$name;$tmp=array();$this->refreshMonitors(0,$tmp);}return$this;}protected
  360. function
  361. validateParent(IComponentContainer$parent){}private
  362. function
  363. refreshMonitors($depth,&$missing=NULL,&$listeners=array()){if($this
  364. instanceof
  365. IComponentContainer){foreach($this->getComponents()as$component){if($component
  366. instanceof
  367. Component){$component->refreshMonitors($depth+1,$missing,$listeners);}}}if($missing===NULL){foreach($this->monitors
  368. as$type=>$rec){if(isset($rec[1])&&$rec[1]>$depth){if($rec[3]){$this->monitors[$type]=array(NULL,NULL,NULL,TRUE);$listeners[]=array($this,$rec[0]);}else{unset($this->monitors[$type]);}}}}else{foreach($this->monitors
  369. as$type=>$rec){if(isset($rec[0])){continue;}elseif(!$rec[3]){unset($this->monitors[$type]);}elseif(isset($missing[$type])){$this->monitors[$type]=array(NULL,NULL,NULL,TRUE);}else{$this->monitors[$type]=NULL;if($obj=$this->lookup($type,FALSE)){$listeners[]=array($this,$obj);}else{$missing[$type]=TRUE;}$this->monitors[$type][3]=TRUE;}}}if($depth===0){$method=$missing===NULL?'detached':'attached';foreach($listeners
  370. as$item){$item[0]->$method($item[1]);}}}function
  371. __clone(){if($this->parent===NULL){return;}elseif($this->parent
  372. instanceof
  373. ComponentContainer){$this->parent=$this->parent->_isCloning();if($this->parent===NULL){$this->refreshMonitors(0);}}else{$this->parent=NULL;$this->refreshMonitors(0);}}final
  374. function
  375. __wakeup(){throw
  376. new
  377. NotImplementedException;}}class
  378. ComponentContainer
  379. extends
  380. Component
  381. implements
  382. IComponentContainer{private$components=array();private$cloning;function
  383. addComponent(IComponent$component,$name,$insertBefore=NULL){if($name===NULL){$name=$component->getName();}if(is_int($name)){$name=(string)$name;}elseif(!is_string($name)){throw
  384. new
  385. InvalidArgumentException("Component name must be integer or string, ".gettype($name)." given.");}elseif(!preg_match('#^[a-zA-Z0-9_]+$#',$name)){throw
  386. new
  387. InvalidArgumentException("Component name must be non-empty alphanumeric string, '$name' given.");}if(isset($this->components[$name])){throw
  388. new
  389. InvalidStateException("Component with name '$name' already exists.");}$obj=$this;do{if($obj===$component){throw
  390. new
  391. InvalidStateException("Circular reference detected while adding component '$name'.");}$obj=$obj->getParent();}while($obj!==NULL);$this->validateChildComponent($component);try{if(isset($this->components[$insertBefore])){$tmp=array();foreach($this->components
  392. as$k=>$v){if($k===$insertBefore)$tmp[$name]=$component;$tmp[$k]=$v;}$this->components=$tmp;}else{$this->components[$name]=$component;}$component->setParent($this,$name);}catch(Exception$e){unset($this->components[$name]);throw$e;}}function
  393. removeComponent(IComponent$component){$name=$component->getName();if(!isset($this->components[$name])||$this->components[$name]!==$component){throw
  394. new
  395. InvalidArgumentException("Component named '$name' is not located in this container.");}unset($this->components[$name]);$component->setParent(NULL);}final
  396. function
  397. getComponent($name,$need=TRUE){if(is_int($name)){$name=(string)$name;}elseif(!is_string($name)){throw
  398. new
  399. InvalidArgumentException("Component name must be integer or string, ".gettype($name)." given.");}else{$a=strpos($name,self::NAME_SEPARATOR);if($a!==FALSE){$ext=(string)substr($name,$a+1);$name=substr($name,0,$a);}if($name===''){throw
  400. new
  401. InvalidArgumentException("Component or subcomponent name must not be empty string.");}}if(!isset($this->components[$name])){$component=$this->createComponent($name);if($component
  402. instanceof
  403. IComponent&&$component->getParent()===NULL){$this->addComponent($component,$name);}}if(isset($this->components[$name])){if(!isset($ext)){return$this->components[$name];}elseif($this->components[$name]instanceof
  404. IComponentContainer){return$this->components[$name]->getComponent($ext,$need);}elseif($need){throw
  405. new
  406. InvalidArgumentException("Component with name '$name' is not container and cannot have '$ext' component.");}}elseif($need){throw
  407. new
  408. InvalidArgumentException("Component with name '$name' does not exist.");}}protected
  409. function
  410. createComponent($name){$ucname=ucfirst($name);$method='createComponent'.$ucname;if($ucname!==$name&&method_exists($this,$method)&&$this->getReflection()->getMethod($method)->getName()===$method){return$this->$method($name);}}final
  411. function
  412. getComponents($deep=FALSE,$filterType=NULL){$iterator=new
  413. RecursiveComponentIterator($this->components);if($deep){$deep=$deep>0?RecursiveIteratorIterator::SELF_FIRST:RecursiveIteratorIterator::CHILD_FIRST;$iterator=new
  414. RecursiveIteratorIterator($iterator,$deep);}if($filterType){if($a=strrpos($filterType,'\\'))$filterType=substr($filterType,$a+1);$iterator=new
  415. InstanceFilterIterator($iterator,$filterType);}return$iterator;}protected
  416. function
  417. validateChildComponent(IComponent$child){}function
  418. __clone(){if($this->components){$oldMyself=reset($this->components)->getParent();$oldMyself->cloning=$this;foreach($this->components
  419. as$name=>$component){$this->components[$name]=clone$component;}$oldMyself->cloning=NULL;}parent::__clone();}function
  420. _isCloning(){return$this->cloning;}}class
  421. RecursiveComponentIterator
  422. extends
  423. RecursiveArrayIterator
  424. implements
  425. Countable{function
  426. hasChildren(){return$this->current()instanceof
  427. IComponentContainer;}function
  428. getChildren(){return$this->current()->getComponents();}function
  429. count(){return
  430. iterator_count($this);}}class
  431. FormContainer
  432. extends
  433. ComponentContainer
  434. implements
  435. ArrayAccess,INamingContainer{public$onValidate;protected$currentGroup;protected$valid;function
  436. setDefaults($values,$erase=FALSE){$form=$this->getForm(FALSE);if(!$form||!$form->isAnchored()||!$form->isSubmitted()){$this->setValues($values,$erase);}return$this;}function
  437. setValues($values,$erase=FALSE){if($values
  438. instanceof
  439. Traversable){$values=iterator_to_array($values);}elseif(!is_array($values)){throw
  440. new
  441. InvalidArgumentException("Values must be an array, ".gettype($values)." given.");}$cursor=&$values;$iterator=$this->getComponents(TRUE);foreach($iterator
  442. as$name=>$control){$sub=$iterator->getSubIterator();if(!isset($sub->cursor)){$sub->cursor=&$cursor;}if($control
  443. instanceof
  444. IFormControl){if((is_array($sub->cursor)||$sub->cursor
  445. instanceof
  446. ArrayAccess)&&array_key_exists($name,$sub->cursor)){$control->setValue($sub->cursor[$name]);}elseif($erase){$control->setValue(NULL);}}if($control
  447. instanceof
  448. INamingContainer){if((is_array($sub->cursor)||$sub->cursor
  449. instanceof
  450. ArrayAccess)&&isset($sub->cursor[$name])){$cursor=&$sub->cursor[$name];}else{unset($cursor);$cursor=NULL;}}}return$this;}function
  451. getValues(){$values=array();$cursor=&$values;$iterator=$this->getComponents(TRUE);foreach($iterator
  452. as$name=>$control){$sub=$iterator->getSubIterator();if(!isset($sub->cursor)){$sub->cursor=&$cursor;}if($control
  453. instanceof
  454. IFormControl&&!$control->isDisabled()&&!($control
  455. instanceof
  456. ISubmitterControl)){$sub->cursor[$name]=$control->getValue();}if($control
  457. instanceof
  458. INamingContainer){$cursor=&$sub->cursor[$name];$cursor=array();}}return$values;}function
  459. isValid(){if($this->valid===NULL){$this->validate();}return$this->valid;}function
  460. validate(){$this->valid=TRUE;$this->onValidate($this);foreach($this->getControls()as$control){if(!$control->getRules()->validate()){$this->valid=FALSE;}}}function
  461. setCurrentGroup(FormGroup$group=NULL){$this->currentGroup=$group;return$this;}function
  462. getCurrentGroup(){return$this->currentGroup;}function
  463. addComponent(IComponent$component,$name,$insertBefore=NULL){parent::addComponent($component,$name,$insertBefore);if($this->currentGroup!==NULL&&$component
  464. instanceof
  465. IFormControl){$this->currentGroup->add($component);}}function
  466. getControls(){return$this->getComponents(TRUE,'IFormControl');}function
  467. getForm($need=TRUE){return$this->lookup('Form',$need);}function
  468. addText($name,$label=NULL,$cols=NULL,$maxLength=NULL){return$this[$name]=new
  469. TextInput($label,$cols,$maxLength);}function
  470. addPassword($name,$label=NULL,$cols=NULL,$maxLength=NULL){$control=new
  471. TextInput($label,$cols,$maxLength);$control->setPasswordMode(TRUE);return$this[$name]=$control;}function
  472. addTextArea($name,$label=NULL,$cols=40,$rows=10){return$this[$name]=new
  473. TextArea($label,$cols,$rows);}function
  474. addFile($name,$label=NULL){return$this[$name]=new
  475. FileUpload($label);}function
  476. addHidden($name,$default=NULL){$control=new
  477. HiddenField;$control->setDefaultValue($default);return$this[$name]=$control;}function
  478. addCheckbox($name,$caption=NULL){return$this[$name]=new
  479. Checkbox($caption);}function
  480. addRadioList($name,$label=NULL,array$items=NULL){return$this[$name]=new
  481. RadioList($label,$items);}function
  482. addSelect($name,$label=NULL,array$items=NULL,$size=NULL){return$this[$name]=new
  483. SelectBox($label,$items,$size);}function
  484. addMultiSelect($name,$label=NULL,array$items=NULL,$size=NULL){return$this[$name]=new
  485. MultiSelectBox($label,$items,$size);}function
  486. addSubmit($name,$caption=NULL){return$this[$name]=new
  487. SubmitButton($caption);}function
  488. addButton($name,$caption){return$this[$name]=new
  489. Button($caption);}function
  490. addImage($name,$src=NULL,$alt=NULL){return$this[$name]=new
  491. ImageButton($src,$alt);}function
  492. addContainer($name){$control=new
  493. FormContainer;$control->currentGroup=$this->currentGroup;return$this[$name]=$control;}final
  494. function
  495. offsetSet($name,$component){$this->addComponent($component,$name);}final
  496. function
  497. offsetGet($name){return$this->getComponent($name,TRUE);}final
  498. function
  499. offsetExists($name){return$this->getComponent($name,FALSE)!==NULL;}final
  500. function
  501. offsetUnset($name){$component=$this->getComponent($name,FALSE);if($component!==NULL){$this->removeComponent($component);}}final
  502. function
  503. __clone(){throw
  504. new
  505. NotImplementedException('Form cloning is not supported yet.');}}class
  506. Form
  507. extends
  508. FormContainer{const
  509. EQUAL=':equal';const
  510. IS_IN=':equal';const
  511. FILLED=':filled';const
  512. VALID=':valid';const
  513. SUBMITTED=':submitted';const
  514. MIN_LENGTH=':minLength';const
  515. MAX_LENGTH=':maxLength';const
  516. LENGTH=':length';const
  517. EMAIL=':email';const
  518. URL=':url';const
  519. REGEXP=':regexp';const
  520. INTEGER=':integer';const
  521. NUMERIC=':integer';const
  522. FLOAT=':float';const
  523. RANGE=':range';const
  524. MAX_FILE_SIZE=':fileSize';const
  525. MIME_TYPE=':mimeType';const
  526. IMAGE=':image';const
  527. SCRIPT='Nette\\Forms\\InstantClientScript::javascript';const
  528. GET='get';const
  529. POST='post';const
  530. TRACKER_ID='_form_';const
  531. PROTECTOR_ID='_token_';public$onSubmit;public$onInvalidSubmit;private$submittedBy;private$httpData;private$element;private$renderer;private$translator;private$groups=array();private$errors=array();function
  532. __construct($name=NULL){$this->element=Html::el('form');$this->element->action='';$this->element->method=self::POST;$this->element->id='frm-'.$name;$this->monitor(__CLASS__);if($name!==NULL){$tracker=new
  533. HiddenField($name);$tracker->unmonitor(__CLASS__);$this[self::TRACKER_ID]=$tracker;}parent::__construct(NULL,$name);}protected
  534. function
  535. attached($obj){if($obj
  536. instanceof
  537. self){throw
  538. new
  539. InvalidStateException('Nested forms are forbidden.');}}final
  540. function
  541. getForm($need=TRUE){return$this;}function
  542. setAction($url){$this->element->action=$url;return$this;}function
  543. getAction(){return$this->element->action;}function
  544. setMethod($method){if($this->httpData!==NULL){throw
  545. new
  546. InvalidStateException(__METHOD__.'() must be called until the form is empty.');}$this->element->method=strtolower($method);return$this;}function
  547. getMethod(){return$this->element->method;}function
  548. addProtection($message=NULL,$timeout=NULL){$session=$this->getSession()->getNamespace('Nette.Forms.Form/CSRF');$key="key$timeout";if(isset($session->$key)){$token=$session->$key;}else{$session->$key=$token=md5(uniqid('',TRUE));}$session->setExpiration($timeout,$key);$this[self::PROTECTOR_ID]=new
  549. HiddenField($token);$this[self::PROTECTOR_ID]->addRule(':equal',empty($message)?'Security token did not match. Possible CSRF attack.':$message,$token);}function
  550. addGroup($caption=NULL,$setAsCurrent=TRUE){$group=new
  551. FormGroup;$group->setOption('label',$caption);$group->setOption('visual',TRUE);if($setAsCurrent){$this->setCurrentGroup($group);}if(isset($this->groups[$caption])){return$this->groups[]=$group;}else{return$this->groups[$caption]=$group;}}function
  552. removeGroup($name){if(is_string($name)&&isset($this->groups[$name])){$group=$this->groups[$name];}elseif($name
  553. instanceof
  554. FormGroup&&in_array($name,$this->groups,TRUE)){$group=$name;$name=array_search($group,$this->groups,TRUE);}else{throw
  555. new
  556. InvalidArgumentException("Group not found in form '$this->name'");}foreach($group->getControls()as$control){$this->removeComponent($control);}unset($this->groups[$name]);}function
  557. getGroups(){return$this->groups;}function
  558. getGroup($name){return
  559. isset($this->groups[$name])?$this->groups[$name]:NULL;}function
  560. setTranslator(ITranslator$translator=NULL){$this->translator=$translator;return$this;}final
  561. function
  562. getTranslator(){return$this->translator;}function
  563. isAnchored(){return
  564. TRUE;}final
  565. function
  566. isSubmitted(){if($this->submittedBy===NULL){$this->getHttpData();$this->submittedBy=!empty($this->httpData);}return$this->submittedBy;}function
  567. setSubmittedBy(ISubmitterControl$by=NULL){$this->submittedBy=$by===NULL?FALSE:$by;return$this;}final
  568. function
  569. getHttpData(){if($this->httpData===NULL){if(!$this->isAnchored()){throw
  570. new
  571. InvalidStateException('Form is not anchored and therefore can not determine whether it was submitted.');}$this->httpData=(array)$this->receiveHttpData();}return$this->httpData;}function
  572. fireEvents(){if(!$this->isSubmitted()){return;}elseif($this->submittedBy
  573. instanceof
  574. ISubmitterControl){if(!$this->submittedBy->getValidationScope()||$this->isValid()){$this->submittedBy->click();$this->onSubmit($this);}else{$this->submittedBy->onInvalidClick($this->submittedBy);$this->onInvalidSubmit($this);}}elseif($this->isValid()){$this->onSubmit($this);}else{$this->onInvalidSubmit($this);}}protected
  575. function
  576. receiveHttpData(){$httpRequest=$this->getHttpRequest();if(strcasecmp($this->getMethod(),$httpRequest->getMethod())){return;}$httpRequest->setEncoding('utf-8');if($httpRequest->isMethod('post')){$data=ArrayTools::mergeTree($httpRequest->getPost(),$httpRequest->getFiles());}else{$data=$httpRequest->getQuery();}if($tracker=$this->getComponent(self::TRACKER_ID,FALSE)){if(!isset($data[self::TRACKER_ID])||$data[self::TRACKER_ID]!==$tracker->getValue()){return;}}return$data;}function
  577. getValues(){$values=parent::getValues();unset($values[self::TRACKER_ID],$values[self::PROTECTOR_ID]);return$values;}function
  578. addError($message){$this->valid=FALSE;if($message!==NULL&&!in_array($message,$this->errors,TRUE)){$this->errors[]=$message;}}function
  579. getErrors(){return$this->errors;}function
  580. hasErrors(){return(bool)$this->getErrors();}function
  581. cleanErrors(){$this->errors=array();$this->valid=NULL;}function
  582. getElementPrototype(){return$this->element;}function
  583. setRenderer(IFormRenderer$renderer){$this->renderer=$renderer;return$this;}final
  584. function
  585. getRenderer(){if($this->renderer===NULL){$this->renderer=new
  586. ConventionalRenderer;}return$this->renderer;}function
  587. render(){$args=func_get_args();array_unshift($args,$this);echo
  588. call_user_func_array(array($this->getRenderer(),'render'),$args);}function
  589. __toString(){try{return$this->getRenderer()->render($this);}catch(Exception$e){if(func_get_args()&&func_get_arg(0)){throw$e;}else{Debug::toStringException($e);}}}protected
  590. function
  591. getHttpRequest(){return
  592. class_exists('Environment')?Environment::getHttpRequest():new
  593. HttpRequest;}protected
  594. function
  595. getSession(){return
  596. Environment::getSession();}}class
  597. AppForm
  598. extends
  599. Form
  600. implements
  601. ISignalReceiver{function
  602. __construct(IComponentContainer$parent=NULL,$name=NULL){parent::__construct();$this->monitor('Presenter');if($parent!==NULL){$parent->addComponent($this,$name);}}function
  603. getPresenter($need=TRUE){return$this->lookup('Presenter',$need);}protected
  604. function
  605. attached($presenter){if($presenter
  606. instanceof
  607. Presenter){$name=$this->lookupPath('Presenter');if(!isset($this->getElementPrototype()->id)){$this->getElementPrototype()->id='frm-'.$name;}$this->setAction(new
  608. Link($presenter,$name.self::NAME_SEPARATOR.'submit!',array()));if($this->isSubmitted()){foreach($this->getControls()as$control){$control->loadHttpData();}}}parent::attached($presenter);}function
  609. isAnchored(){return(bool)$this->getPresenter(FALSE);}protected
  610. function
  611. receiveHttpData(){$presenter=$this->getPresenter();if(!$presenter->isSignalReceiver($this,'submit')){return;}$isPost=$this->getMethod()===self::POST;$request=$presenter->getRequest();if($request->isMethod('forward')||$request->isMethod('post')!==$isPost){return;}if($isPost){return
  612. ArrayTools::mergeTree($request->getPost(),$request->getFiles());}else{return$request->getParams();}}function
  613. signalReceived($signal){if($signal==='submit'){$this->fireEvents();}else{throw
  614. new
  615. BadSignalException("There is no handler for signal '$signal' in {$this->reflection->name}.");}}}class
  616. Application
  617. extends
  618. Object{public
  619. static$maxLoop=20;public$defaultServices=array('Nette\\Application\\IRouter'=>'MultiRouter','Nette\\Application\\IPresenterLoader'=>array(__CLASS__,'createPresenterLoader'));public$catchExceptions;public$errorPresenter;public$onStartup;public$onShutdown;public$onRequest;public$onError;public$allowedMethods=array('GET','POST','HEAD','PUT','DELETE');private$requests=array();private$presenter;private$serviceLocator;function
  620. run(){$httpRequest=$this->getHttpRequest();$httpResponse=$this->getHttpResponse();$httpRequest->setEncoding('UTF-8');if(Environment::getVariable('baseUri')===NULL){Environment::setVariable('baseUri',$httpRequest->getUri()->getBasePath());}$session=$this->getSession();if(!$session->isStarted()&&$session->exists()){$session->start();}Debug::addPanel(new
  621. RoutingDebugger($this->getRouter(),$httpRequest));if($this->allowedMethods){$method=$httpRequest->getMethod();if(!in_array($method,$this->allowedMethods,TRUE)){$httpResponse->setCode(IHttpResponse::S501_NOT_IMPLEMENTED);$httpResponse->setHeader('Allow',implode(',',$this->allowedMethods));echo'<h1>Method '.htmlSpecialChars($method).' is not implemented</h1>';return;}}$request=NULL;$repeatedError=FALSE;do{try{if(count($this->requests)>self::$maxLoop){throw
  622. new
  623. ApplicationException('Too many loops detected in application life cycle.');}if(!$request){$this->onStartup($this);$router=$this->getRouter();if($router
  624. instanceof
  625. MultiRouter&&!count($router)){$router[]=new
  626. SimpleRouter(array('presenter'=>'Default','action'=>'default'));}$request=$router->match($httpRequest);if(!($request
  627. instanceof
  628. PresenterRequest)){$request=NULL;throw
  629. new
  630. BadRequestException('No route for HTTP request.');}if(strcasecmp($request->getPresenterName(),$this->errorPresenter)===0){throw
  631. new
  632. BadRequestException('Invalid request.');}}$this->requests[]=$request;$this->onRequest($this,$request);$presenter=$request->getPresenterName();try{$class=$this->getPresenterLoader()->getPresenterClass($presenter);$request->setPresenterName($presenter);}catch(InvalidPresenterException$e){throw
  633. new
  634. BadRequestException($e->getMessage(),404,$e);}$request->freeze();$this->presenter=new$class;$response=$this->presenter->run($request);if($response
  635. instanceof
  636. ForwardingResponse){$request=$response->getRequest();continue;}elseif($response
  637. instanceof
  638. IPresenterResponse){$response->send();}break;}catch(Exception$e){if($this->catchExceptions===NULL){$this->catchExceptions=Environment::isProduction();}$this->onError($this,$e);if(!$this->catchExceptions){$this->onShutdown($this,$e);throw$e;}if($repeatedError){$e=new
  639. ApplicationException('An error occured while executing error-presenter',0,$e);}if(!$httpResponse->isSent()){$httpResponse->setCode($e
  640. instanceof
  641. BadRequestException?$e->getCode():500);}if(!$repeatedError&&$this->errorPresenter){$repeatedError=TRUE;$request=new
  642. PresenterRequest($this->errorPresenter,PresenterRequest::FORWARD,array('exception'=>$e));}else{echo"<meta name='robots' content='noindex'>\n\n";if($e
  643. instanceof
  644. BadRequestException){echo"<title>404 Not Found</title>\n\n<h1>Not Found</h1>\n\n<p>The requested URL was not found on this server.</p>";}else{Debug::processException($e,FALSE);echo"<title>500 Internal Server Error</title>\n\n<h1>Server Error</h1>\n\n","<p>The server encountered an internal error and was unable to complete your request. Please try again later.</p>";}echo"\n\n<hr>\n<small><i>Nette Framework</i></small>";break;}}}while(1);$this->onShutdown($this,isset($e)?$e:NULL);}final
  645. function
  646. getRequests(){return$this->requests;}final
  647. function
  648. getPresenter(){return$this->presenter;}final
  649. function
  650. getServiceLocator(){if($this->serviceLocator===NULL){$this->serviceLocator=new
  651. ServiceLocator(Environment::getServiceLocator());foreach($this->defaultServices
  652. as$name=>$service){if(!$this->serviceLocator->hasService($name)){$this->serviceLocator->addService($name,$service);}}}return$this->serviceLocator;}final
  653. function
  654. getService($name,array$options=NULL){return$this->getServiceLocator()->getService($name,$options);}function
  655. getRouter(){return$this->getServiceLocator()->getService('Nette\\Application\\IRouter');}function
  656. setRouter(IRouter$router){$this->getServiceLocator()->addService('Nette\\Application\\IRouter',$router);return$this;}function
  657. getPresenterLoader(){return$this->getServiceLocator()->getService('Nette\\Application\\IPresenterLoader');}static
  658. function
  659. createPresenterLoader(){return
  660. new
  661. PresenterLoader(Environment::getVariable('appDir'));}function
  662. storeRequest($expiration='+ 10 minutes'){$session=$this->getSession('Nette.Application/requests');do{$key=substr(md5(lcg_value()),0,4);}while(isset($session[$key]));$session[$key]=end($this->requests);$session->setExpiration($expiration,$key);return$key;}function
  663. restoreRequest($key){$session=$this->getSession('Nette.Application/requests');if(isset($session[$key])){$request=clone$session[$key];unset($session[$key]);$request->setFlag(PresenterRequest::RESTORED,TRUE);$this->presenter->terminate(new
  664. ForwardingResponse($request));}}protected
  665. function
  666. getHttpRequest(){return
  667. Environment::getHttpRequest();}protected
  668. function
  669. getHttpResponse(){return
  670. Environment::getHttpResponse();}protected
  671. function
  672. getSession($namespace=NULL){return
  673. Environment::getSession($namespace);}}abstract
  674. class
  675. PresenterComponent
  676. extends
  677. ComponentContainer
  678. implements
  679. ISignalReceiver,IStatePersistent,ArrayAccess{protected$params=array();function
  680. __construct(IComponentContainer$parent=NULL,$name=NULL){$this->monitor('Presenter');parent::__construct($parent,$name);}function
  681. getPresenter($need=TRUE){return$this->lookup('Presenter',$need);}function
  682. getUniqueId(){return$this->lookupPath('Presenter',TRUE);}protected
  683. function
  684. attached($presenter){if($presenter
  685. instanceof
  686. Presenter){$this->loadState($presenter->popGlobalParams($this->getUniqueId()));}}protected
  687. function
  688. tryCall($method,array$params){$rc=$this->getReflection();if($rc->hasMethod($method)){$rm=$rc->getMethod($method);if($rm->isPublic()&&!$rm->isAbstract()&&!$rm->isStatic()){$rm->invokeNamedArgs($this,$params);return
  689. TRUE;}}return
  690. FALSE;}function
  691. getReflection(){return
  692. new
  693. PresenterComponentReflection($this);}function
  694. loadState(array$params){foreach($this->getReflection()->getPersistentParams()as$nm=>$meta){if(isset($params[$nm])){if(isset($meta['def'])){if(is_array($params[$nm])&&!is_array($meta['def'])){$params[$nm]=$meta['def'];}else{settype($params[$nm],gettype($meta['def']));}}$this->$nm=&$params[$nm];}}$this->params=$params;}function
  695. saveState(array&$params,$reflection=NULL){$reflection=$reflection===NULL?$this->getReflection():$reflection;foreach($reflection->getPersistentParams()as$nm=>$meta){if(isset($params[$nm])){$val=$params[$nm];}elseif(array_key_exists($nm,$params)){continue;}elseif(!isset($meta['since'])||$this
  696. instanceof$meta['since']){$val=$this->$nm;}else{continue;}if(is_object($val)){throw
  697. new
  698. InvalidStateException("Persistent parameter must be scalar or array, {$this->reflection->name}::\$$nm is ".gettype($val));}else{if(isset($meta['def'])){settype($val,gettype($meta['def']));if($val===$meta['def'])$val=NULL;}else{if((string)$val==='')$val=NULL;}$params[$nm]=$val;}}}final
  699. function
  700. getParam($name=NULL,$default=NULL){if(func_num_args()===0){return$this->params;}elseif(isset($this->params[$name])){return$this->params[$name];}else{return$default;}}final
  701. function
  702. getParamId($name){$uid=$this->getUniqueId();return$uid===''?$name:$uid.self::NAME_SEPARATOR.$name;}static
  703. function
  704. getPersistentParams(){$rc=new
  705. ClassReflection(func_get_arg(0));$params=array();foreach($rc->getProperties(ReflectionProperty::IS_PUBLIC)as$rp){if(!$rp->isStatic()&&$rp->hasAnnotation('persistent')){$params[]=$rp->getName();}}return$params;}function
  706. signalReceived($signal){if(!$this->tryCall($this->formatSignalMethod($signal),$this->params)){throw
  707. new
  708. BadSignalException("There is no handler for signal '$signal' in {$this->reflection->name} class.");}}function
  709. formatSignalMethod($signal){return$signal==NULL?NULL:'handle'.$signal;}function
  710. link($destination,$args=array()){if(!is_array($args)){$args=func_get_args();array_shift($args);}try{return$this->getPresenter()->createRequest($this,$destination,$args,'link');}catch(InvalidLinkException$e){return$this->getPresenter()->handleInvalidLink($e);}}function
  711. lazyLink($destination,$args=array()){if(!is_array($args)){$args=func_get_args();array_shift($args);}return
  712. new
  713. Link($this,$destination,$args);}function
  714. redirect($code,$destination=NULL,$args=array()){if(!is_numeric($code)){$args=$destination;$destination=$code;$code=NULL;}if(!is_array($args)){$args=func_get_args();if(is_numeric(array_shift($args)))array_shift($args);}$presenter=$this->getPresenter();$presenter->redirectUri($presenter->createRequest($this,$destination,$args,'redirect'),$code);}final
  715. function
  716. offsetSet($name,$component){$this->addComponent($component,$name);}final
  717. function
  718. offsetGet($name){return$this->getComponent($name,TRUE);}final
  719. function
  720. offsetExists($name){return$this->getComponent($name,FALSE)!==NULL;}final
  721. function
  722. offsetUnset($name){$component=$this->getComponent($name,FALSE);if($component!==NULL){$this->removeComponent($component);}}}abstract
  723. class
  724. Control
  725. extends
  726. PresenterComponent
  727. implements
  728. IPartiallyRenderable{private$template;private$invalidSnippets=array();final
  729. function
  730. getTemplate(){if($this->template===NULL){$value=$this->createTemplate();if(!($value
  731. instanceof
  732. ITemplate||$value===NULL)){$class=get_class($value);throw
  733. new
  734. UnexpectedValueException("Object returned by {$this->reflection->name}::createTemplate() must be instance of Nette\\Templates\\ITemplate, '$class' given.");}$this->template=$value;}return$this->template;}protected
  735. function
  736. createTemplate(){$template=new
  737. Template;$presenter=$this->getPresenter(FALSE);$template->onPrepareFilters[]=callback($this,'templatePrepareFilters');$template->component=$this;$template->control=$this;$template->presenter=$presenter;$template->baseUri=Environment::getVariable('baseUri');$template->basePath=rtrim($template->baseUri,'/');if($presenter!==NULL&&$presenter->hasFlashSession()){$id=$this->getParamId('flash');$template->flashes=$presenter->getFlashSession()->$id;}if(!isset($template->flashes)||!is_array($template->flashes)){$template->flashes=array();}$template->registerHelper('escape','TemplateHelpers::escapeHtml');$template->registerHelper('escapeUrl','rawurlencode');$template->registerHelper('stripTags','strip_tags');$template->registerHelper('nl2br','nl2br');$template->registerHelper('substr','iconv_substr');$template->registerHelper('repeat','str_repeat');$template->registerHelper('replaceRE','String::replace');$template->registerHelper('implode','implode');$template->registerHelper('number','number_format');$template->registerHelperLoader('TemplateHelpers::loader');return$template;}function
  738. templatePrepareFilters($template){$template->registerFilter(new
  739. LatteFilter);}function
  740. getWidget($name){return$this->getComponent($name);}function
  741. flashMessage($message,$type='info'){$id=$this->getParamId('flash');$messages=$this->getPresenter()->getFlashSession()->$id;$messages[]=$flash=(object)array('message'=>$message,'type'=>$type);$this->getTemplate()->flashes=$messages;$this->getPresenter()->getFlashSession()->$id=$messages;return$flash;}function
  742. invalidateControl($snippet=NULL){$this->invalidSnippets[$snippet]=TRUE;}function
  743. validateControl($snippet=NULL){if($snippet===NULL){$this->invalidSnippets=array();}else{unset($this->invalidSnippets[$snippet]);}}function
  744. isControlInvalid($snippet=NULL){if($snippet===NULL){if(count($this->invalidSnippets)>0){return
  745. TRUE;}else{foreach($this->getComponents()as$component){if($component
  746. instanceof
  747. IRenderable&&$component->isControlInvalid()){return
  748. TRUE;}}return
  749. FALSE;}}else{return
  750. isset($this->invalidSnippets[NULL])||isset($this->invalidSnippets[$snippet]);}}function
  751. getSnippetId($name=NULL){return'snippet-'.$this->getUniqueId().'-'.$name;}}class
  752. AbortException
  753. extends
  754. Exception{}class
  755. ApplicationException
  756. extends
  757. Exception{function
  758. __construct($message='',$code=0,Exception$previous=NULL){if(PHP_VERSION_ID<50300){$this->previous=$previous;parent::__construct($message,$code);}else{parent::__construct($message,$code,$previous);}}}class
  759. BadRequestException
  760. extends
  761. Exception{protected$defaultCode=404;function
  762. __construct($message='',$code=0,Exception$previous=NULL){if($code<200||$code>504){$code=$this->defaultCode;}if(PHP_VERSION_ID<50300){$this->previous=$previous;parent::__construct($message,$code);}else{parent::__construct($message,$code,$previous);}}}class
  763. BadSignalException
  764. extends
  765. BadRequestException{protected$defaultCode=403;}class
  766. ForbiddenRequestException
  767. extends
  768. BadRequestException{protected$defaultCode=403;}class
  769. InvalidLinkException
  770. extends
  771. Exception{}class
  772. InvalidPresenterException
  773. extends
  774. InvalidLinkException{}class
  775. Link
  776. extends
  777. Object{private$component;private$destination;private$params;function
  778. __construct(PresenterComponent$component,$destination,array$params){$this->component=$component;$this->destination=$destination;$this->params=$params;}function
  779. getDestination(){return$this->destination;}function
  780. setParam($key,$value){$this->params[$key]=$value;return$this;}function
  781. getParam($key){return
  782. isset($this->params[$key])?$this->params[$key]:NULL;}function
  783. getParams(){return$this->params;}function
  784. __toString(){try{return$this->component->link($this->destination,$this->params);}catch(Exception$e){Debug::toStringException($e);}}}abstract
  785. class
  786. Presenter
  787. extends
  788. Control
  789. implements
  790. IPresenter{const
  791. INVALID_LINK_SILENT=1;const
  792. INVALID_LINK_WARNING=2;const
  793. INVALID_LINK_EXCEPTION=3;const
  794. SIGNAL_KEY='do';const
  795. ACTION_KEY='action';const
  796. FLASH_KEY='_fid';public
  797. static$defaultAction='default';public
  798. static$invalidLinkMode;public$onShutdown;private$request;private$response;public$autoCanonicalize=TRUE;public$absoluteUrls=FALSE;private$globalParams;private$globalState;private$globalStateSinces;private$action;private$view;private$layout;private$payload;private$signalReceiver;private$signal;private$ajaxMode;private$startupCheck;private$lastCreatedRequest;private$lastCreatedRequestFlag;final
  799. function
  800. getRequest(){return$this->request;}final
  801. function
  802. getPresenter($need=TRUE){return$this;}final
  803. function
  804. getUniqueId(){return'';}function
  805. run(PresenterRequest$request){try{$this->request=$request;$this->payload=(object)NULL;$this->setParent($this->getParent(),$request->getPresenterName());$this->initGlobalParams();$this->startup();if(!$this->startupCheck){$class=$this->reflection->getMethod('startup')->getDeclaringClass()->getName();throw
  806. new
  807. InvalidStateException("Method $class::startup() or its descendant doesn't call parent::startup().");}$this->tryCall($this->formatActionMethod($this->getAction()),$this->params);if($this->autoCanonicalize){$this->canonicalize();}if($this->getHttpRequest()->isMethod('head')){$this->terminate();}$this->processSignal();$this->beforeRender();$this->tryCall($this->formatRenderMethod($this->getView()),$this->params);$this->afterRender();$this->saveGlobalState();if($this->isAjax()){$this->payload->state=$this->getGlobalState();}$this->sendTemplate();}catch(AbortException$e){}{if($this->isAjax())try{$hasPayload=(array)$this->payload;unset($hasPayload['state']);if($this->response
  808. instanceof
  809. RenderResponse&&($this->isControlInvalid()||$hasPayload)){SnippetHelper::$outputAllowed=FALSE;$this->response->send();$this->sendPayload();}elseif(!$this->response&&$hasPayload){$this->sendPayload();}}catch(AbortException$e){}if($this->hasFlashSession()){$this->getFlashSession()->setExpiration($this->response
  810. instanceof
  811. RedirectingResponse?'+ 30 seconds':'+ 3 seconds');}$this->onShutdown($this,$this->response);$this->shutdown($this->response);return$this->response;}}protected
  812. function
  813. startup(){$this->startupCheck=TRUE;}protected
  814. function
  815. beforeRender(){}protected
  816. function
  817. afterRender(){}protected
  818. function
  819. shutdown($response){}function
  820. processSignal(){if($this->signal===NULL)return;$component=$this->signalReceiver===''?$this:$this->getComponent($this->signalReceiver,FALSE);if($component===NULL){throw
  821. new
  822. BadSignalException("The signal receiver component '$this->signalReceiver' is not found.");}elseif(!$component
  823. instanceof
  824. ISignalReceiver){throw
  825. new
  826. BadSignalException("The signal receiver component '$this->signalReceiver' is not ISignalReceiver implementor.");}$component->signalReceived($this->signal);$this->signal=NULL;}final
  827. function
  828. getSignal(){return$this->signal===NULL?NULL:array($this->signalReceiver,$this->signal);}final
  829. function
  830. isSignalReceiver($component,$signal=NULL){if($component
  831. instanceof
  832. Component){$component=$component===$this?'':$component->lookupPath(__CLASS__,TRUE);}if($this->signal===NULL){return
  833. FALSE;}elseif($signal===TRUE){return$component===''||strncmp($this->signalReceiver.'-',$component.'-',strlen($component)+1)===0;}elseif($signal===NULL){return$this->signalReceiver===$component;}else{return$this->signalReceiver===$component&&strcasecmp($signal,$this->signal)===0;}}final
  834. function
  835. getAction($fullyQualified=FALSE){return$fullyQualified?':'.$this->getName().':'.$this->action:$this->action;}function
  836. changeAction($action){if(String::match($action,"#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*$#")){$this->action=$action;$this->view=$action;}else{throw
  837. new
  838. BadRequestException("Action name '$action' is not alphanumeric string.");}}final
  839. function
  840. getView(){return$this->view;}function
  841. setView($view){$this->view=(string)$view;return$this;}final
  842. function
  843. getLayout(){return$this->layout;}function
  844. setLayout($layout){$this->layout=$layout===FALSE?FALSE:(string)$layout;return$this;}function
  845. sendTemplate(){$template=$this->getTemplate();if(!$template)return;if($template
  846. instanceof
  847. IFileTemplate&&!$template->getFile()){$files=$this->formatTemplateFiles($this->getName(),$this->view);foreach($files
  848. as$file){if(is_file($file)){$template->setFile($file);break;}}if(!$template->getFile()){$file=str_replace(Environment::getVariable('appDir'),"\xE2\x80\xA6",reset($files));throw
  849. new
  850. BadRequestException("Page not found. Missing template '$file'.");}if($this->layout!==FALSE){$files=$this->formatLayoutTemplateFiles($this->getName(),$this->layout?$this->layout:'layout');foreach($files
  851. as$fi

Large files files are truncated, but you can click here to view the full file