PageRenderTime 75ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 3ms

/loader.php

https://github.com/romcok/google-translator
PHP | 5074 lines | 4868 code | 149 blank | 57 comment | 71 complexity | 19f157ee982ebd857664d4d39f093007 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. getName();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='0.9.3';const
  235. REVISION='cc750ea released on 2010-01-28';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);}final
  366. class
  367. Annotations{public
  368. static$useReflection;static
  369. function
  370. has(Reflector$r,$name){trigger_error(__METHOD__.'() is deprecated; use getReflection()->hasAnnotation() instead.',E_USER_WARNING);$cache=AnnotationsParser::getAll($r);return!empty($cache[$name]);}static
  371. function
  372. get(Reflector$r,$name){trigger_error(__METHOD__.'() is deprecated; use getReflection()->getAnnotation() instead.',E_USER_WARNING);$cache=AnnotationsParser::getAll($r);return
  373. isset($cache[$name])?end($cache[$name]):NULL;}static
  374. function
  375. getAll(Reflector$r,$name=NULL){trigger_error(__METHOD__.'() is deprecated; use getReflection()->getAnnotations() instead.',E_USER_WARNING);$cache=AnnotationsParser::getAll($r);if($name===NULL){return$cache;}elseif(isset($cache[$name])){return$cache[$name];}else{return
  376. array();}}}abstract
  377. class
  378. Component
  379. extends
  380. Object
  381. implements
  382. IComponent{private$parent;private$name;private$monitors=array();function
  383. __construct(IComponentContainer$parent=NULL,$name=NULL){if($parent!==NULL){$parent->addComponent($this,$name);}elseif(is_string($name)){$this->name=$name;}}function
  384. 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
  385. 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
  386. new
  387. InvalidStateException("Component '$this->name' is not attached to '$type'.");}return$this->monitors[$type][0];}function
  388. lookupPath($type,$need=TRUE){Framework::fixNamespace($type);$this->lookup($type,$need);return$this->monitors[$type][2];}function
  389. 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
  390. unmonitor($type){Framework::fixNamespace($type);unset($this->monitors[$type]);}protected
  391. function
  392. attached($obj){}protected
  393. function
  394. detached($obj){}final
  395. function
  396. getName(){return$this->name;}final
  397. function
  398. getParent(){return$this->parent;}function
  399. 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
  400. new
  401. 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
  402. function
  403. validateParent(IComponentContainer$parent){}private
  404. function
  405. refreshMonitors($depth,&$missing=NULL,&$listeners=array()){if($this
  406. instanceof
  407. IComponentContainer){foreach($this->getComponents()as$component){if($component
  408. instanceof
  409. Component){$component->refreshMonitors($depth+1,$missing,$listeners);}}}if($missing===NULL){foreach($this->monitors
  410. 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
  411. 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
  412. as$item){$item[0]->$method($item[1]);}}}function
  413. __clone(){if($this->parent===NULL){return;}elseif($this->parent
  414. instanceof
  415. ComponentContainer){$this->parent=$this->parent->_isCloning();if($this->parent===NULL){$this->refreshMonitors(0);}}else{$this->parent=NULL;$this->refreshMonitors(0);}}final
  416. function
  417. __wakeup(){throw
  418. new
  419. NotImplementedException;}}class
  420. ComponentContainer
  421. extends
  422. Component
  423. implements
  424. IComponentContainer{private$components=array();private$cloning;function
  425. addComponent(IComponent$component,$name,$insertBefore=NULL){if($name===NULL){$name=$component->getName();}if(is_int($name)){$name=(string)$name;}elseif(!is_string($name)){throw
  426. new
  427. InvalidArgumentException("Component name must be integer or string, ".gettype($name)." given.");}elseif(!preg_match('#^[a-zA-Z0-9_]+$#',$name)){throw
  428. new
  429. InvalidArgumentException("Component name must be non-empty alphanumeric string, '$name' given.");}if(isset($this->components[$name])){throw
  430. new
  431. InvalidStateException("Component with name '$name' already exists.");}$obj=$this;do{if($obj===$component){throw
  432. new
  433. 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
  434. 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
  435. removeComponent(IComponent$component){$name=$component->getName();if(!isset($this->components[$name])||$this->components[$name]!==$component){throw
  436. new
  437. InvalidArgumentException("Component named '$name' is not located in this container.");}unset($this->components[$name]);$component->setParent(NULL);}final
  438. function
  439. getComponent($name,$need=TRUE){if(is_int($name)){$name=(string)$name;}elseif(!is_string($name)){throw
  440. new
  441. 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
  442. new
  443. InvalidArgumentException("Component or subcomponent name must not be empty string.");}}if(!isset($this->components[$name])){$component=$this->createComponent($name);if($component
  444. instanceof
  445. 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
  446. IComponentContainer){return$this->components[$name]->getComponent($ext,$need);}elseif($need){throw
  447. new
  448. InvalidArgumentException("Component with name '$name' is not container and cannot have '$ext' component.");}}elseif($need){throw
  449. new
  450. InvalidArgumentException("Component with name '$name' does not exist.");}}protected
  451. function
  452. 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
  453. function
  454. getComponents($deep=FALSE,$filterType=NULL){$iterator=new
  455. RecursiveComponentIterator($this->components);if($deep){$deep=$deep>0?RecursiveIteratorIterator::SELF_FIRST:RecursiveIteratorIterator::CHILD_FIRST;$iterator=new
  456. RecursiveIteratorIterator($iterator,$deep);}if($filterType){Framework::fixNamespace($filterType);$iterator=new
  457. InstanceFilterIterator($iterator,$filterType);}return$iterator;}protected
  458. function
  459. validateChildComponent(IComponent$child){}function
  460. __clone(){if($this->components){$oldMyself=reset($this->components)->getParent();$oldMyself->cloning=$this;foreach($this->components
  461. as$name=>$component){$this->components[$name]=clone$component;}$oldMyself->cloning=NULL;}parent::__clone();}function
  462. _isCloning(){return$this->cloning;}}class
  463. RecursiveComponentIterator
  464. extends
  465. RecursiveArrayIterator
  466. implements
  467. Countable{function
  468. hasChildren(){return$this->current()instanceof
  469. IComponentContainer;}function
  470. getChildren(){return$this->current()->getComponents();}function
  471. count(){return
  472. iterator_count($this);}}class
  473. FormContainer
  474. extends
  475. ComponentContainer
  476. implements
  477. ArrayAccess,INamingContainer{public$onValidate;protected$currentGroup;protected$valid;function
  478. setDefaults($values,$erase=FALSE){$form=$this->getForm(FALSE);if(!$form||!$form->isAnchored()||!$form->isSubmitted()){$this->setValues($values,$erase);}return$this;}function
  479. setValues($values,$erase=FALSE){if($values
  480. instanceof
  481. Traversable){$values=iterator_to_array($values);}elseif(!is_array($values)){throw
  482. new
  483. InvalidArgumentException("Values must be an array, ".gettype($values)." given.");}$cursor=&$values;$iterator=$this->getComponents(TRUE);foreach($iterator
  484. as$name=>$control){$sub=$iterator->getSubIterator();if(!isset($sub->cursor)){$sub->cursor=&$cursor;}if($control
  485. instanceof
  486. IFormControl){if((is_array($sub->cursor)||$sub->cursor
  487. instanceof
  488. ArrayAccess)&&array_key_exists($name,$sub->cursor)){$control->setValue($sub->cursor[$name]);}elseif($erase){$control->setValue(NULL);}}if($control
  489. instanceof
  490. INamingContainer){if((is_array($sub->cursor)||$sub->cursor
  491. instanceof
  492. ArrayAccess)&&isset($sub->cursor[$name])){$cursor=&$sub->cursor[$name];}else{unset($cursor);$cursor=NULL;}}}return$this;}function
  493. getValues(){$values=array();$cursor=&$values;$iterator=$this->getComponents(TRUE);foreach($iterator
  494. as$name=>$control){$sub=$iterator->getSubIterator();if(!isset($sub->cursor)){$sub->cursor=&$cursor;}if($control
  495. instanceof
  496. IFormControl&&!$control->isDisabled()&&!($control
  497. instanceof
  498. ISubmitterControl)){$sub->cursor[$name]=$control->getValue();}if($control
  499. instanceof
  500. INamingContainer){$cursor=&$sub->cursor[$name];$cursor=array();}}return$values;}function
  501. isValid(){if($this->valid===NULL){$this->validate();}return$this->valid;}function
  502. validate(){$this->valid=TRUE;$this->onValidate($this);foreach($this->getControls()as$control){if(!$control->getRules()->validate()){$this->valid=FALSE;}}}function
  503. setCurrentGroup(FormGroup$group=NULL){$this->currentGroup=$group;return$this;}function
  504. addComponent(IComponent$component,$name,$insertBefore=NULL){parent::addComponent($component,$name,$insertBefore);if($this->currentGroup!==NULL&&$component
  505. instanceof
  506. IFormControl){$this->currentGroup->add($component);}}function
  507. getControls(){return$this->getComponents(TRUE,'Nette\Forms\IFormControl');}function
  508. getForm($need=TRUE){return$this->lookup('Nette\Forms\Form',$need);}function
  509. addText($name,$label=NULL,$cols=NULL,$maxLength=NULL){return$this[$name]=new
  510. TextInput($label,$cols,$maxLength);}function
  511. addPassword($name,$label=NULL,$cols=NULL,$maxLength=NULL){$control=new
  512. TextInput($label,$cols,$maxLength);$control->setPasswordMode(TRUE);$this->addComponent($control,$name);return$control;}function
  513. addTextArea($name,$label=NULL,$cols=40,$rows=10){return$this[$name]=new
  514. TextArea($label,$cols,$rows);}function
  515. addFile($name,$label=NULL){return$this[$name]=new
  516. FileUpload($label);}function
  517. addHidden($name){return$this[$name]=new
  518. HiddenField;}function
  519. addCheckbox($name,$caption){return$this[$name]=new
  520. Checkbox($caption);}function
  521. addRadioList($name,$label=NULL,array$items=NULL){return$this[$name]=new
  522. RadioList($label,$items);}function
  523. addSelect($name,$label=NULL,array$items=NULL,$size=NULL){return$this[$name]=new
  524. SelectBox($label,$items,$size);}function
  525. addMultiSelect($name,$label=NULL,array$items=NULL,$size=NULL){return$this[$name]=new
  526. MultiSelectBox($label,$items,$size);}function
  527. addSubmit($name,$caption){return$this[$name]=new
  528. SubmitButton($caption);}function
  529. addButton($name,$caption){return$this[$name]=new
  530. Button($caption);}function
  531. addImage($name,$src=NULL,$alt=NULL){return$this[$name]=new
  532. ImageButton($src,$alt);}function
  533. addContainer($name){$control=new
  534. FormContainer;$control->currentGroup=$this->currentGroup;return$this[$name]=$control;}final
  535. function
  536. offsetSet($name,$component){$this->addComponent($component,$name);}final
  537. function
  538. offsetGet($name){return$this->getComponent($name,TRUE);}final
  539. function
  540. offsetExists($name){return$this->getComponent($name,FALSE)!==NULL;}final
  541. function
  542. offsetUnset($name){$component=$this->getComponent($name,FALSE);if($component!==NULL){$this->removeComponent($component);}}final
  543. function
  544. __clone(){throw
  545. new
  546. NotImplementedException('Form cloning is not supported yet.');}}class
  547. Form
  548. extends
  549. FormContainer{const
  550. EQUAL=':equal';const
  551. IS_IN=':equal';const
  552. FILLED=':filled';const
  553. VALID=':valid';const
  554. SUBMITTED=':submitted';const
  555. MIN_LENGTH=':minLength';const
  556. MAX_LENGTH=':maxLength';const
  557. LENGTH=':length';const
  558. EMAIL=':email';const
  559. URL=':url';const
  560. REGEXP=':regexp';const
  561. INTEGER=':integer';const
  562. NUMERIC=':integer';const
  563. FLOAT=':float';const
  564. RANGE=':range';const
  565. MAX_FILE_SIZE=':fileSize';const
  566. MIME_TYPE=':mimeType';const
  567. SCRIPT='Nette\Forms\InstantClientScript::javascript';const
  568. GET='get';const
  569. POST='post';const
  570. TRACKER_ID='_form_';const
  571. 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
  572. __construct($name=NULL){$this->element=Html::el('form');$this->element->action='';$this->element->method=self::POST;$this->monitor(__CLASS__);if($name!==NULL){$tracker=new
  573. HiddenField($name);$tracker->unmonitor(__CLASS__);$this[self::TRACKER_ID]=$tracker;}parent::__construct(NULL,$name);}protected
  574. function
  575. attached($obj){if($obj
  576. instanceof
  577. self){throw
  578. new
  579. InvalidStateException('Nested forms are forbidden.');}}final
  580. function
  581. getForm($need=TRUE){return$this;}function
  582. setAction($url){$this->element->action=$url;return$this;}function
  583. getAction(){return$this->element->action;}function
  584. setMethod($method){if($this->httpData!==NULL){throw
  585. new
  586. InvalidStateException(__METHOD__.'() must be called until the form is empty.');}$this->element->method=strtolower($method);return$this;}function
  587. getMethod(){return$this->element->method;}function
  588. addTracker(){throw
  589. new
  590. DeprecatedException(__METHOD__.'() is deprecated; pass form name to the constructor.');}function
  591. 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
  592. HiddenField($token);$this[self::PROTECTOR_ID]->addRule(':equal',empty($message)?'Security token did not match. Possible CSRF attack.':$message,$token);}function
  593. addGroup($caption=NULL,$setAsCurrent=TRUE){$group=new
  594. 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
  595. removeGroup($name){if(is_string($name)&&isset($this->groups[$name])){$group=$this->groups[$name];}elseif($name
  596. instanceof
  597. FormGroup&&in_array($name,$this->groups,TRUE)){$group=$name;$name=array_search($group,$this->groups,TRUE);}else{throw
  598. new
  599. InvalidArgumentException("Group not found in form '$this->name'");}foreach($group->getControls()as$control){$this->removeComponent($control);}unset($this->groups[$name]);}function
  600. getGroups(){return$this->groups;}function
  601. getGroup($name){return
  602. isset($this->groups[$name])?$this->groups[$name]:NULL;}function
  603. setEncoding($value){$this->encoding=empty($value)?'UTF-8':strtoupper($value);if($this->encoding!=='UTF-8'&&!extension_loaded('mbstring')){throw
  604. new
  605. Exception("The PHP extension 'mbstring' is required for this encoding but is not loaded.");}return$this;}final
  606. function
  607. getEncoding(){return$this->encoding;}function
  608. setTranslator(ITranslator$translator=NULL){$this->translator=$translator;return$this;}final
  609. function
  610. getTranslator(){return$this->translator;}function
  611. isAnchored(){return
  612. TRUE;}final
  613. function
  614. isSubmitted(){if($this->submittedBy===NULL){$this->getHttpData();$this->submittedBy=!empty($this->httpData);}return$this->submittedBy;}function
  615. setSubmittedBy(ISubmitterControl$by=NULL){$this->submittedBy=$by===NULL?FALSE:$by;return$this;}final
  616. function
  617. getHttpData(){if($this->httpData===NULL){if(!$this->isAnchored()){throw
  618. new
  619. InvalidStateException('Form is not anchored and therefore can not determine whether it was submitted.');}$this->httpData=(array)$this->receiveHttpData();}return$this->httpData;}function
  620. fireEvents(){if(!$this->isSubmitted()){return;}elseif($this->submittedBy
  621. instanceof
  622. 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
  623. function
  624. 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
  625. processHttpRequest(){trigger_error(__METHOD__.'() is deprecated; use fireEvents() instead.',E_USER_WARNING);$this->fireEvents();}function
  626. getValues(){$values=parent::getValues();unset($values[self::TRACKER_ID],$values[self::PROTECTOR_ID]);return$values;}function
  627. addError($message){$this->valid=FALSE;if($message!==NULL&&!in_array($message,$this->errors,TRUE)){$this->errors[]=$message;}}function
  628. getErrors(){return$this->errors;}function
  629. hasErrors(){return(bool)$this->getErrors();}function
  630. cleanErrors(){$this->errors=array();$this->valid=NULL;}function
  631. getElementPrototype(){return$this->element;}function
  632. setRenderer(IFormRenderer$renderer){$this->renderer=$renderer;return$this;}final
  633. function
  634. getRenderer(){if($this->renderer===NULL){$this->renderer=new
  635. ConventionalRenderer;}return$this->renderer;}function
  636. 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
  637. mb_convert_encoding($s,'HTML-ENTITIES','UTF-8');}else{echo$s;}}function
  638. __toString(){try{if(strcmp($this->encoding,'UTF-8')){return
  639. 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
  640. function
  641. getHttpRequest(){return
  642. class_exists('Environment')?Environment::getHttpRequest():new
  643. HttpRequest;}protected
  644. function
  645. getSession(){return
  646. Environment::getSession();}}class
  647. AppForm
  648. extends
  649. Form
  650. implements
  651. ISignalReceiver{function
  652. __construct(IComponentContainer$parent=NULL,$name=NULL){parent::__construct();$this->monitor('Nette\Application\Presenter');if($parent!==NULL){$parent->addComponent($this,$name);}}function
  653. getPresenter($need=TRUE){return$this->lookup('Nette\Application\Presenter',$need);}protected
  654. function
  655. attached($presenter){if($presenter
  656. instanceof
  657. Presenter){$this->setAction(new
  658. 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
  659. isAnchored(){return(bool)$this->getPresenter(FALSE);}protected
  660. function
  661. 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
  662. ArrayTools::mergeTree($request->getPost(),$request->getFiles());}else{return$request->getParams();}}function
  663. signalReceived($signal){if($signal==='submit'){$this->fireEvents();}else{throw
  664. new
  665. BadSignalException("There is no handler for signal '$signal' in {$this->reflection->name}.");}}}class
  666. Application
  667. extends
  668. Object{public
  669. 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
  670. 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
  671. new
  672. ApplicationException('Too many loops detected in application life cycle.');}if(!$request){$this->onStartup($this);$router=$this->getRouter();if($router
  673. instanceof
  674. MultiRouter&&!count($router)){$router[]=new
  675. SimpleRouter(array('presenter'=>'Default','action'=>'default'));}$request=$router->match($httpRequest);if(!($request
  676. instanceof
  677. PresenterRequest)){$request=NULL;throw
  678. new
  679. BadRequestException('No route for HTTP request.');}if(strcasecmp($request->getPresenterName(),$this->errorPresenter)===0){throw
  680. new
  681. 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
  682. new
  683. BadRequestException($e->getMessage(),404,$e);}$request->freeze();$this->presenter=new$class;$response=$this->presenter->run($request);if($response
  684. instanceof
  685. ForwardingResponse){$request=$response->getRequest();continue;}elseif($response
  686. instanceof
  687. 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
  688. ApplicationException('An error occured while executing error-presenter',0,$e);}if(!$httpResponse->isSent()){$httpResponse->setCode($e
  689. instanceof
  690. BadRequestException?$e->getCode():500);}if(!$repeatedError&&$this->errorPresenter){$repeatedError=TRUE;$request=new
  691. PresenterRequest($this->errorPresenter,PresenterRequest::FORWARD,array('exception'=>$e));}else{echo"<meta name='robots' content='noindex'>\n\n";if($e
  692. instanceof
  693. 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
  694. function
  695. getRequests(){return$this->requests;}final
  696. function
  697. getPresenter(){return$this->presenter;}final
  698. function
  699. getServiceLocator(){if($this->serviceLocator===NULL){$this->serviceLocator=new
  700. ServiceLocator(Environment::getServiceLocator());foreach($this->defaultServices
  701. as$name=>$service){if(!$this->serviceLocator->hasService($name)){$this->serviceLocator->addService($name,$service);}}}return$this->serviceLocator;}final
  702. function
  703. getService($name,array$options=NULL){return$this->getServiceLocator()->getService($name,$options);}function
  704. getRouter(){return$this->getServiceLocator()->getService('Nette\Application\IRouter');}function
  705. setRouter(IRouter$router){$this->getServiceLocator()->addService('Nette\Application\IRouter',$router);return$this;}function
  706. getPresenterLoader(){return$this->getServiceLocator()->getService('Nette\Application\IPresenterLoader');}static
  707. function
  708. createPresenterLoader(){return
  709. new
  710. PresenterLoader(Environment::getVariable('appDir'));}function
  711. 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
  712. 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
  713. ForwardingResponse($request));}}protected
  714. function
  715. getHttpRequest(){return
  716. Environment::getHttpRequest();}protected
  717. function
  718. getHttpResponse(){return
  719. Environment::getHttpResponse();}protected
  720. function
  721. getSession($namespace=NULL){return
  722. Environment::getSession($namespace);}}abstract
  723. class
  724. PresenterComponent
  725. extends
  726. ComponentContainer
  727. implements
  728. ISignalReceiver,IStatePersistent,ArrayAccess{protected$params=array();function
  729. __construct(IComponentContainer$parent=NULL,$name=NULL){$this->monitor('Nette\Application\Presenter');parent::__construct($parent,$name);}function
  730. getPresenter($need=TRUE){return$this->lookup('Nette\Application\Presenter',$need);}function
  731. getUniqueId(){return$this->lookupPath('Nette\Application\Presenter',TRUE);}protected
  732. function
  733. attached($presenter){if($presenter
  734. instanceof
  735. Presenter){$this->loadState($presenter->popGlobalParams($this->getUniqueId()));}}protected
  736. function
  737. 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
  738. TRUE;}}return
  739. FALSE;}function
  740. getReflection(){return
  741. new
  742. PresenterComponentReflection($this);}function
  743. 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
  744. 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
  745. instanceof$meta['since']){$val=$this->$nm;}else{continue;}if(is_object($val)){throw
  746. new
  747. 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
  748. function
  749. 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
  750. function
  751. getParamId($name){$uid=$this->getUniqueId();return$uid===''?$name:$uid.self::NAME_SEPARATOR.$name;}static
  752. function
  753. getPersistentParams(){$rc=new
  754. 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
  755. signalReceived($signal){if(!$this->tryCall($this->formatSignalMethod($signal),$this->params)){throw
  756. new
  757. BadSignalException("There is no handler for signal '$signal' in {$this->reflection->name} class.");}}function
  758. formatSignalMethod($signal){return$signal==NULL?NULL:'handle'.$signal;}function
  759. 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
  760. lazyLink($destination,$args=array()){if(!is_array($args)){$args=func_get_args();array_shift($args);}return
  761. new
  762. Link($this,$destination,$args);}function
  763. ajaxLink($destination,$args=array()){throw
  764. new
  765. DeprecatedException(__METHOD__.'() is deprecated.');}function
  766. 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
  767. function
  768. offsetSet($name,$component){$this->addComponent($component,$name);}final
  769. function
  770. offsetGet($name){return$this->getComponent($name,TRUE);}final
  771. function
  772. offsetExists($name){return$this->getComponent($name,FALSE)!==NULL;}final
  773. function
  774. offsetUnset($name){$component=$this->getComponent($name,FALSE);if($component!==NULL){$this->removeComponent($component);}}}abstract
  775. class
  776. Control
  777. extends
  778. PresenterComponent
  779. implements
  780. IPartiallyRenderable{private$template;private$invalidSnippets=array();final
  781. function
  782. getTemplate(){if($this->template===NULL){$value=$this->createTemplate();if(!($value
  783. instanceof
  784. ITemplate||$value===NULL)){$class=get_class($value);throw
  785. new
  786. UnexpectedValueException("Object returned by {$this->reflection->name}::createTemplate() must be instance of Nette\\Templates\\ITemplate, '$class' given.");}$this->template=$value;}return$this->template;}protected
  787. function
  788. createTemplate(){$template=new
  789. 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
  790. templatePrepareFilters($template){$template->registerFilter(new
  791. LatteFilter);}function
  792. getWidget($name){return$this->getComponent($name);}function
  793. 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
  794. invalidateControl($snippet=NULL){$this->invalidSnippets[$snippet]=TRUE;}function
  795. validateControl($snippet=NULL){if($snippet===NULL){$this->invalidSnippets=array();}else{unset($this->invalidSnippets[$snippet]);}}function
  796. isControlInvalid($snippet=NULL){if($snippet===NULL){if(count($this->invalidSnippets)>0){return
  797. TRUE;}else{foreach($this->getComponents()as$component){if($component
  798. instanceof
  799. IRenderable&&$component->isControlInvalid()){return
  800. TRUE;}}return
  801. FALSE;}}else{return
  802. isset($this->invalidSnippets[NULL])||isset($this->invalidSnippets[$snippet]);}}function
  803. getSnippetId($name=NULL){return'snippet-'.$this->getUniqueId().'-'.$name;}}class
  804. AbortException
  805. extends
  806. Exception{}class
  807. ApplicationException
  808. extends
  809. Exception{function
  810. __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
  811. BadRequestException
  812. extends
  813. Exception{protected$defaultCode=404;function
  814. __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
  815. BadSignalException
  816. extends
  817. BadRequestException{protected$defaultCode=403;}class
  818. ForbiddenRequestException
  819. extends
  820. BadRequestException{protected$defaultCode=403;}class
  821. InvalidLinkException
  822. extends
  823. Exception{}class
  824. InvalidPresenterException
  825. extends
  826. InvalidLinkException{}class
  827. Link
  828. extends
  829. Object{private$component;private$destination;private$params;function
  830. __construct(PresenterComponent$component,$destination,array$params){$this->component=$component;$this->destination=$destination;$this->params=$params;}function
  831. getDestination(){return$this->destination;}function
  832. setParam($key,$value){$this->params[$key]=$value;return$this;}function
  833. getParam($key){return
  834. isset($this->params[$key])?$this->params[$key]:NULL;}function
  835. getParams(){return$this->params;}function
  836. __toString(){try{return$this->component->link($this->destination,$this->params);}catch(Exception$e){Debug::toStringException($e);}}}abstract
  837. class
  838. Presenter
  839. extends
  840. Control
  841. implements
  842. IPresenter{const
  843. PHASE_STARTUP=1;const
  844. PHASE_SIGNAL=3;const
  845. PHASE_RENDER=4;const
  846. PHASE_SHUTDOWN=5;const
  847. INVALID_LINK_SILENT=1;const
  848. INVALID_LINK_WARNING=2;const
  849. INVALID_LINK_EXCEPTION=3;const
  850. SIGNAL_KEY='do';const
  851. ACTION_KEY='action';const
  852. FLASH_KEY='_fid';public
  853. static$defaultAction='default';public
  854. static$invalidLinkMode;public$onShutdown;public$oldLayoutMode=TRUE;public$oldModuleMode=TRUE;private$request;private$response;private$phase;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
  855. function
  856. getRequest(){return$this->request;}final
  857. function
  858. getPresenter($need=TRUE){return$this;}final
  859. function
  860. getUniqueId(){return'';}function
  861. run(PresenterRequest$request){try{$this->phase=self::PHASE_STARTUP;$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();}if(method_exists($this,'beforePrepare')){$this->beforePrepare();trigger_error('beforePrepare() is deprecated; use createComponent{Name}() instead.',E_USER_WARNING);}if($this->tryCall('prepare'.$this->getView(),$this->params)){trigger_error('prepare'.ucfirst($this->getView()).'() is deprecated; use createComponent{Name}() instead.',E_USER_WARNING);}$this->phase=self::PHASE_SIGNAL;$this->processSignal();$this->phase=self::PHASE_RENDER;$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){}{$this->phase=self::PHASE_SHUTDOWN;if($this->isAjax())try{$hasPayload=(array)$this->payload;unset($hasPayload['state']);if($this->response
  862. instanceof
  863. RenderResponse&&($this->isControlInvalid()||$hasPayload)){SnippetHelper::$outputAllowed=FALSE;$this->response->send();$this->sendPayload();}elseif(!$this->response&&$hasPayload){$this->sendPayload();}}catch(AbortException$e){}if($this->hasFlashSession()){$this->getFlashSession()->setExp

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