PageRenderTime 77ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 2ms

/libs/loader.php

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

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