PageRenderTime 70ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 2ms

/libs/NetteX/loader.php

https://github.com/OndrejBrejla/apigen
PHP | 4529 lines | 4423 code | 99 blank | 7 comment | 50 complexity | 28c45b1894815c6ce4c225733b4c6bdc MD5 | raw file

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

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

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