/loader.php
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
- <?php //netteloader=IComponent
- /**
- * Nette Framework
- *
- * Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)
- *
- * This source file is subject to the "Nette license" that is bundled
- * with this package in the file license.txt, and/or GPL license.
- *
- * For more information please see http://nettephp.com
- *
- * @copyright Copyright (c) 2004, 2010 David Grudl
- * @license http://nettephp.com/license Nette license
- * @link http://nettephp.com
- * @category Nette
- * @package Nette
- */
- if(version_compare(PHP_VERSION,'5.2.0','<')){throw
- new
- Exception('Nette Framework requires PHP 5.2.0 or newer.');}@set_magic_quotes_runtime(FALSE);function
- callback($callback,$m=NULL){return($m===NULL&&$callback
- instanceof
- Callback)?$callback:new
- Callback($callback,$m);}if(!function_exists('dump')){function
- dump($var){foreach(func_get_args()as$arg)Debug::dump($arg);return$var;}}interface
- IComponent{const
- NAME_SEPARATOR='-';function
- getName();function
- getParent();function
- setParent(IComponentContainer$parent=NULL,$name=NULL);}interface
- IComponentContainer
- extends
- IComponent{function
- addComponent(IComponent$component,$name);function
- removeComponent(IComponent$component);function
- getComponent($name);function
- getComponents($deep=FALSE,$filterType=NULL);}interface
- INamingContainer
- extends
- IComponentContainer{}interface
- ISignalReceiver{function
- signalReceived($signal);}interface
- IStatePersistent{function
- loadState(array$params);function
- saveState(array&$params);}interface
- IRenderable{function
- invalidateControl();function
- isControlInvalid();}interface
- IPartiallyRenderable
- extends
- IRenderable{}interface
- IPresenter{function
- run(PresenterRequest$request);}interface
- IPresenterLoader{function
- getPresenterClass(&$name);}interface
- IPresenterResponse{function
- send();}interface
- IRouter{const
- ONE_WAY=1;const
- SECURED=2;function
- match(IHttpRequest$httpRequest);function
- constructUrl(PresenterRequest$appRequest,IHttpRequest$httpRequest);}interface
- ICollection
- extends
- Countable,IteratorAggregate{function
- append($item);function
- remove($item);function
- clear();function
- contains($item);}interface
- IList
- extends
- ICollection,ArrayAccess{function
- indexOf($item);function
- insertAt($index,$item);}interface
- ICacheStorage{function
- read($key);function
- write($key,$data,array$dependencies);function
- remove($key);function
- clean(array$conds);}interface
- IMap
- extends
- ICollection,ArrayAccess{function
- add($key,$value);function
- search($item);function
- getKeys();}interface
- ISet
- extends
- ICollection{}interface
- IConfigAdapter{static
- function
- load($file,$section=NULL);static
- function
- save($config,$file,$section=NULL);}interface
- IFormControl{function
- loadHttpData();function
- setValue($value);function
- getValue();function
- getRules();function
- getErrors();function
- isDisabled();function
- translate($s,$count=NULL);}interface
- ISubmitterControl
- extends
- IFormControl{function
- isSubmittedBy();function
- getValidationScope();}interface
- IFormRenderer{function
- render(Form$form);}interface
- IDebuggable{function
- getPanels();}interface
- IServiceLocator{function
- addService($name,$service,$singleton=TRUE,array$options=NULL);function
- getService($name,array$options=NULL);function
- removeService($name);function
- hasService($name);}interface
- ITranslator{function
- translate($message,$count=NULL);}interface
- IMailer{function
- send(Mail$mail);}interface
- IAnnotation{function
- __construct(array$values);}interface
- IAuthenticator{const
- USERNAME='username';const
- PASSWORD='password';const
- IDENTITY_NOT_FOUND=1;const
- INVALID_CREDENTIAL=2;const
- FAILURE=3;const
- NOT_APPROVED=4;function
- authenticate(array$credentials);}interface
- IAuthorizator{const
- ALL=NULL;const
- ALLOW=TRUE;const
- DENY=FALSE;function
- isAllowed($role=self::ALL,$resource=self::ALL,$privilege=self::ALL);}interface
- IIdentity{function
- getName();function
- getRoles();}interface
- IPermissionAssertion{function
- assert(Permission$acl,$roleId,$resourceId,$privilege);}interface
- IResource{function
- getResourceId();}interface
- IRole{function
- getRoleId();}interface
- ITemplate{function
- render();}interface
- IFileTemplate
- extends
- ITemplate{function
- setFile($file);function
- getFile();}interface
- IHttpRequest{const
- GET='GET',POST='POST',HEAD='HEAD',PUT='PUT',DELETE='DELETE';function
- getUri();function
- getQuery($key=NULL,$default=NULL);function
- getPost($key=NULL,$default=NULL);function
- getPostRaw();function
- getFile($key);function
- getFiles();function
- getCookie($key,$default=NULL);function
- getCookies();function
- getMethod();function
- isMethod($method);function
- getHeader($header,$default=NULL);function
- getHeaders();function
- isSecured();function
- isAjax();function
- getRemoteAddress();function
- getRemoteHost();}interface
- IHttpResponse{const
- PERMANENT=2116333333;const
- BROWSER=0;const
- 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
- setCode($code);function
- getCode();function
- setHeader($name,$value);function
- addHeader($name,$value);function
- setContentType($type,$charset=NULL);function
- redirect($url,$code=self::S302_FOUND);function
- setExpiration($seconds);function
- isSent();function
- getHeaders();function
- setCookie($name,$value,$expire,$path=NULL,$domain=NULL,$secure=NULL);function
- deleteCookie($name,$path=NULL,$domain=NULL,$secure=NULL);}interface
- IUser{function
- authenticate($username,$password,$extra=NULL);function
- signOut($clearIdentity=FALSE);function
- isAuthenticated();function
- getIdentity();function
- setAuthenticationHandler(IAuthenticator$handler);function
- getAuthenticationHandler();function
- setNamespace($namespace);function
- getNamespace();function
- getRoles();function
- isInRole($role);function
- isAllowed();function
- setAuthorizationHandler(IAuthorizator$handler);function
- getAuthorizationHandler();}class
- ArgumentOutOfRangeException
- extends
- InvalidArgumentException{}class
- InvalidStateException
- extends
- RuntimeException{function
- __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
- NotImplementedException
- extends
- LogicException{}class
- NotSupportedException
- extends
- LogicException{}class
- DeprecatedException
- extends
- NotSupportedException{}class
- MemberAccessException
- extends
- LogicException{}class
- IOException
- extends
- RuntimeException{}class
- FileNotFoundException
- extends
- IOException{}class
- DirectoryNotFoundException
- extends
- IOException{}class
- FatalErrorException
- extends
- Exception{private$severity;function
- __construct($message,$code,$severity,$file,$line,$context){parent::__construct($message,$code);$this->severity=$severity;$this->file=$file;$this->line=$line;$this->context=$context;}function
- getSeverity(){return$this->severity;}}final
- class
- Framework{const
- NAME='Nette Framework';const
- VERSION='0.9.3';const
- REVISION='cc750ea released on 2010-01-28';const
- PACKAGE='PHP 5.2';final
- function
- __construct(){throw
- new
- LogicException("Cannot instantiate static class ".get_class($this));}static
- function
- compareVersion($version){return
- version_compare($version,self::VERSION);}static
- function
- 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
- function
- fixNamespace(&$class){if($a=strrpos($class,'\\')){$class=substr($class,$a+1);}}}abstract
- class
- Object{function
- getClass(){trigger_error(__METHOD__.'() is deprecated; use getReflection()->getName() instead.',E_USER_WARNING);return
- get_class($this);}function
- getReflection(){return
- new
- ClassReflection($this);}function
- __call($name,$args){return
- ObjectMixin::call($this,$name,$args);}static
- function
- __callStatic($name,$args){$class=get_called_class();throw
- new
- MemberAccessException("Call to undefined static method $class::$name().");}static
- function
- extensionMethod($name,$callback=NULL){if(strpos($name,'::')===FALSE){$class=get_called_class();}else{list($class,$name)=explode('::',$name);}$class=new
- ClassReflection($class);if($callback===NULL){return$class->getExtensionMethod($name);}else{$class->setExtensionMethod($name,$callback);}}function&__get($name){return
- ObjectMixin::get($this,$name);}function
- __set($name,$value){return
- ObjectMixin::set($this,$name,$value);}function
- __isset($name){return
- ObjectMixin::has($this,$name);}function
- __unset($name){throw
- new
- MemberAccessException("Cannot unset the property {$this->reflection->name}::\$$name.");}}final
- class
- ObjectMixin{private
- static$methods;final
- function
- __construct(){throw
- new
- LogicException("Cannot instantiate static class ".get_class($this));}static
- function
- call($_this,$name,$args){$class=new
- ClassReflection($_this);if($name===''){throw
- new
- MemberAccessException("Call to class '$class->name' method without name.");}if($class->hasEventProperty($name)){if(is_array($list=$_this->$name)||$list
- instanceof
- Traversable){foreach($list
- as$handler){callback($handler)->invokeArgs($args);}}return
- NULL;}if($cb=$class->getExtensionMethod($name)){array_unshift($args,$_this);return$cb->invokeArgs($args);}throw
- new
- MemberAccessException("Call to undefined method $class->name::$name().");}static
- function&get($_this,$name){$class=get_class($_this);if($name===''){throw
- new
- 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
- new
- MemberAccessException("Cannot read an undeclared property $class::\$$name.");}static
- function
- set($_this,$name,$value){$class=get_class($_this);if($name===''){throw
- new
- 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
- new
- MemberAccessException("Cannot assign to a read-only property $class::\$$name.");}}$name=func_get_arg(1);throw
- new
- MemberAccessException("Cannot assign to an undeclared property $class::\$$name.");}static
- function
- has($_this,$name){if($name===''){return
- 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
- isset(self::$methods[$class]['get'.$name])||isset(self::$methods[$class]['is'.$name]);}}final
- class
- Callback
- extends
- Object{private$cb;public
- static$fix520;public
- static$checkImmediately=FALSE;function
- __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
- new
- InvalidArgumentException("Invalid callback.");}}function
- __invoke(){if(!is_callable($this->cb)){throw
- new
- InvalidStateException("Callback '$this' is not callable.");}$args=func_get_args();return
- call_user_func_array($this->cb,$args);}function
- invoke(){if(!is_callable($this->cb)){throw
- new
- InvalidStateException("Callback '$this' is not callable.");}$args=func_get_args();return
- call_user_func_array($this->cb,$args);}function
- invokeArgs(array$args){if(!is_callable($this->cb)){throw
- new
- InvalidStateException("Callback '$this' is not callable.");}return
- call_user_func_array($this->cb,$args);}function
- isCallable(){return
- is_callable($this->cb);}function
- getNative(){return$this->cb;}function
- __toString(){is_callable($this->cb,TRUE,$textual);return$textual;}}Callback::$fix520=version_compare(PHP_VERSION,'5.2.2','<');final
- class
- LimitedScope{private
- static$vars;final
- function
- __construct(){throw
- new
- LogicException("Cannot instantiate static class ".get_class($this));}static
- function
- evaluate(){if(func_num_args()>1){extract(func_get_arg(1));}return
- eval('?>'.func_get_arg(0));}static
- function
- load(){if(func_num_args()>1){extract(func_get_arg(1));}return include func_get_arg(0);}}abstract
- class
- AutoLoader
- extends
- Object{static
- private$loaders=array();public
- static$count=0;final
- static
- function
- load($type){foreach(func_get_args()as$type){if(!class_exists($type)){throw
- new
- InvalidStateException("Unable to load class or interface '$type'.");}}}final
- static
- function
- getLoaders(){return
- array_values(self::$loaders);}function
- register(){if(!function_exists('spl_autoload_register')){throw
- new
- RuntimeException('spl_autoload does not exist in this PHP installation.');}spl_autoload_register(array($this,'tryLoad'));self::$loaders[spl_object_hash($this)]=$this;}function
- unregister(){unset(self::$loaders[spl_object_hash($this)]);return
- spl_autoload_unregister(array($this,'tryLoad'));}abstract
- function
- tryLoad($type);}final
- class
- Annotations{public
- static$useReflection;static
- function
- 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
- function
- get(Reflector$r,$name){trigger_error(__METHOD__.'() is deprecated; use getReflection()->getAnnotation() instead.',E_USER_WARNING);$cache=AnnotationsParser::getAll($r);return
- isset($cache[$name])?end($cache[$name]):NULL;}static
- function
- 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
- array();}}}abstract
- class
- Component
- extends
- Object
- implements
- IComponent{private$parent;private$name;private$monitors=array();function
- __construct(IComponentContainer$parent=NULL,$name=NULL){if($parent!==NULL){$parent->addComponent($this,$name);}elseif(is_string($name)){$this->name=$name;}}function
- 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
- 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
- new
- InvalidStateException("Component '$this->name' is not attached to '$type'.");}return$this->monitors[$type][0];}function
- lookupPath($type,$need=TRUE){Framework::fixNamespace($type);$this->lookup($type,$need);return$this->monitors[$type][2];}function
- 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
- unmonitor($type){Framework::fixNamespace($type);unset($this->monitors[$type]);}protected
- function
- attached($obj){}protected
- function
- detached($obj){}final
- function
- getName(){return$this->name;}final
- function
- getParent(){return$this->parent;}function
- 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
- new
- 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
- function
- validateParent(IComponentContainer$parent){}private
- function
- refreshMonitors($depth,&$missing=NULL,&$listeners=array()){if($this
- instanceof
- IComponentContainer){foreach($this->getComponents()as$component){if($component
- instanceof
- Component){$component->refreshMonitors($depth+1,$missing,$listeners);}}}if($missing===NULL){foreach($this->monitors
- 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
- 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
- as$item){$item[0]->$method($item[1]);}}}function
- __clone(){if($this->parent===NULL){return;}elseif($this->parent
- instanceof
- ComponentContainer){$this->parent=$this->parent->_isCloning();if($this->parent===NULL){$this->refreshMonitors(0);}}else{$this->parent=NULL;$this->refreshMonitors(0);}}final
- function
- __wakeup(){throw
- new
- NotImplementedException;}}class
- ComponentContainer
- extends
- Component
- implements
- IComponentContainer{private$components=array();private$cloning;function
- addComponent(IComponent$component,$name,$insertBefore=NULL){if($name===NULL){$name=$component->getName();}if(is_int($name)){$name=(string)$name;}elseif(!is_string($name)){throw
- new
- InvalidArgumentException("Component name must be integer or string, ".gettype($name)." given.");}elseif(!preg_match('#^[a-zA-Z0-9_]+$#',$name)){throw
- new
- InvalidArgumentException("Component name must be non-empty alphanumeric string, '$name' given.");}if(isset($this->components[$name])){throw
- new
- InvalidStateException("Component with name '$name' already exists.");}$obj=$this;do{if($obj===$component){throw
- new
- 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
- 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
- removeComponent(IComponent$component){$name=$component->getName();if(!isset($this->components[$name])||$this->components[$name]!==$component){throw
- new
- InvalidArgumentException("Component named '$name' is not located in this container.");}unset($this->components[$name]);$component->setParent(NULL);}final
- function
- getComponent($name,$need=TRUE){if(is_int($name)){$name=(string)$name;}elseif(!is_string($name)){throw
- new
- InvalidArgumentException("Component name must be integer or string, ".gettype($name)." given.");}else{$a=strpos($name,self::NAME_SEPARATOR);if($a!==FALSE){$ext=(string)substr($name,$a+1);$name=substr($name,0,$a);}if($name===''){throw
- new
- InvalidArgumentException("Component or subcomponent name must not be empty string.");}}if(!isset($this->components[$name])){$component=$this->createComponent($name);if($component
- instanceof
- 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
- IComponentContainer){return$this->components[$name]->getComponent($ext,$need);}elseif($need){throw
- new
- InvalidArgumentException("Component with name '$name' is not container and cannot have '$ext' component.");}}elseif($need){throw
- new
- InvalidArgumentException("Component with name '$name' does not exist.");}}protected
- function
- 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
- function
- getComponents($deep=FALSE,$filterType=NULL){$iterator=new
- RecursiveComponentIterator($this->components);if($deep){$deep=$deep>0?RecursiveIteratorIterator::SELF_FIRST:RecursiveIteratorIterator::CHILD_FIRST;$iterator=new
- RecursiveIteratorIterator($iterator,$deep);}if($filterType){Framework::fixNamespace($filterType);$iterator=new
- InstanceFilterIterator($iterator,$filterType);}return$iterator;}protected
- function
- validateChildComponent(IComponent$child){}function
- __clone(){if($this->components){$oldMyself=reset($this->components)->getParent();$oldMyself->cloning=$this;foreach($this->components
- as$name=>$component){$this->components[$name]=clone$component;}$oldMyself->cloning=NULL;}parent::__clone();}function
- _isCloning(){return$this->cloning;}}class
- RecursiveComponentIterator
- extends
- RecursiveArrayIterator
- implements
- Countable{function
- hasChildren(){return$this->current()instanceof
- IComponentContainer;}function
- getChildren(){return$this->current()->getComponents();}function
- count(){return
- iterator_count($this);}}class
- FormContainer
- extends
- ComponentContainer
- implements
- ArrayAccess,INamingContainer{public$onValidate;protected$currentGroup;protected$valid;function
- setDefaults($values,$erase=FALSE){$form=$this->getForm(FALSE);if(!$form||!$form->isAnchored()||!$form->isSubmitted()){$this->setValues($values,$erase);}return$this;}function
- setValues($values,$erase=FALSE){if($values
- instanceof
- Traversable){$values=iterator_to_array($values);}elseif(!is_array($values)){throw
- new
- InvalidArgumentException("Values must be an array, ".gettype($values)." given.");}$cursor=&$values;$iterator=$this->getComponents(TRUE);foreach($iterator
- as$name=>$control){$sub=$iterator->getSubIterator();if(!isset($sub->cursor)){$sub->cursor=&$cursor;}if($control
- instanceof
- IFormControl){if((is_array($sub->cursor)||$sub->cursor
- instanceof
- ArrayAccess)&&array_key_exists($name,$sub->cursor)){$control->setValue($sub->cursor[$name]);}elseif($erase){$control->setValue(NULL);}}if($control
- instanceof
- INamingContainer){if((is_array($sub->cursor)||$sub->cursor
- instanceof
- ArrayAccess)&&isset($sub->cursor[$name])){$cursor=&$sub->cursor[$name];}else{unset($cursor);$cursor=NULL;}}}return$this;}function
- getValues(){$values=array();$cursor=&$values;$iterator=$this->getComponents(TRUE);foreach($iterator
- as$name=>$control){$sub=$iterator->getSubIterator();if(!isset($sub->cursor)){$sub->cursor=&$cursor;}if($control
- instanceof
- IFormControl&&!$control->isDisabled()&&!($control
- instanceof
- ISubmitterControl)){$sub->cursor[$name]=$control->getValue();}if($control
- instanceof
- INamingContainer){$cursor=&$sub->cursor[$name];$cursor=array();}}return$values;}function
- isValid(){if($this->valid===NULL){$this->validate();}return$this->valid;}function
- validate(){$this->valid=TRUE;$this->onValidate($this);foreach($this->getControls()as$control){if(!$control->getRules()->validate()){$this->valid=FALSE;}}}function
- setCurrentGroup(FormGroup$group=NULL){$this->currentGroup=$group;return$this;}function
- addComponent(IComponent$component,$name,$insertBefore=NULL){parent::addComponent($component,$name,$insertBefore);if($this->currentGroup!==NULL&&$component
- instanceof
- IFormControl){$this->currentGroup->add($component);}}function
- getControls(){return$this->getComponents(TRUE,'Nette\Forms\IFormControl');}function
- getForm($need=TRUE){return$this->lookup('Nette\Forms\Form',$need);}function
- addText($name,$label=NULL,$cols=NULL,$maxLength=NULL){return$this[$name]=new
- TextInput($label,$cols,$maxLength);}function
- addPassword($name,$label=NULL,$cols=NULL,$maxLength=NULL){$control=new
- TextInput($label,$cols,$maxLength);$control->setPasswordMode(TRUE);$this->addComponent($control,$name);return$control;}function
- addTextArea($name,$label=NULL,$cols=40,$rows=10){return$this[$name]=new
- TextArea($label,$cols,$rows);}function
- addFile($name,$label=NULL){return$this[$name]=new
- FileUpload($label);}function
- addHidden($name){return$this[$name]=new
- HiddenField;}function
- addCheckbox($name,$caption){return$this[$name]=new
- Checkbox($caption);}function
- addRadioList($name,$label=NULL,array$items=NULL){return$this[$name]=new
- RadioList($label,$items);}function
- addSelect($name,$label=NULL,array$items=NULL,$size=NULL){return$this[$name]=new
- SelectBox($label,$items,$size);}function
- addMultiSelect($name,$label=NULL,array$items=NULL,$size=NULL){return$this[$name]=new
- MultiSelectBox($label,$items,$size);}function
- addSubmit($name,$caption){return$this[$name]=new
- SubmitButton($caption);}function
- addButton($name,$caption){return$this[$name]=new
- Button($caption);}function
- addImage($name,$src=NULL,$alt=NULL){return$this[$name]=new
- ImageButton($src,$alt);}function
- addContainer($name){$control=new
- FormContainer;$control->currentGroup=$this->currentGroup;return$this[$name]=$control;}final
- function
- offsetSet($name,$component){$this->addComponent($component,$name);}final
- function
- offsetGet($name){return$this->getComponent($name,TRUE);}final
- function
- offsetExists($name){return$this->getComponent($name,FALSE)!==NULL;}final
- function
- offsetUnset($name){$component=$this->getComponent($name,FALSE);if($component!==NULL){$this->removeComponent($component);}}final
- function
- __clone(){throw
- new
- NotImplementedException('Form cloning is not supported yet.');}}class
- Form
- extends
- FormContainer{const
- EQUAL=':equal';const
- IS_IN=':equal';const
- FILLED=':filled';const
- VALID=':valid';const
- SUBMITTED=':submitted';const
- MIN_LENGTH=':minLength';const
- MAX_LENGTH=':maxLength';const
- LENGTH=':length';const
- EMAIL=':email';const
- URL=':url';const
- REGEXP=':regexp';const
- INTEGER=':integer';const
- NUMERIC=':integer';const
- FLOAT=':float';const
- RANGE=':range';const
- MAX_FILE_SIZE=':fileSize';const
- MIME_TYPE=':mimeType';const
- SCRIPT='Nette\Forms\InstantClientScript::javascript';const
- GET='get';const
- POST='post';const
- TRACKER_ID='_form_';const
- 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
- __construct($name=NULL){$this->element=Html::el('form');$this->element->action='';$this->element->method=self::POST;$this->monitor(__CLASS__);if($name!==NULL){$tracker=new
- HiddenField($name);$tracker->unmonitor(__CLASS__);$this[self::TRACKER_ID]=$tracker;}parent::__construct(NULL,$name);}protected
- function
- attached($obj){if($obj
- instanceof
- self){throw
- new
- InvalidStateException('Nested forms are forbidden.');}}final
- function
- getForm($need=TRUE){return$this;}function
- setAction($url){$this->element->action=$url;return$this;}function
- getAction(){return$this->element->action;}function
- setMethod($method){if($this->httpData!==NULL){throw
- new
- InvalidStateException(__METHOD__.'() must be called until the form is empty.');}$this->element->method=strtolower($method);return$this;}function
- getMethod(){return$this->element->method;}function
- addTracker(){throw
- new
- DeprecatedException(__METHOD__.'() is deprecated; pass form name to the constructor.');}function
- 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
- HiddenField($token);$this[self::PROTECTOR_ID]->addRule(':equal',empty($message)?'Security token did not match. Possible CSRF attack.':$message,$token);}function
- addGroup($caption=NULL,$setAsCurrent=TRUE){$group=new
- 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
- removeGroup($name){if(is_string($name)&&isset($this->groups[$name])){$group=$this->groups[$name];}elseif($name
- instanceof
- FormGroup&&in_array($name,$this->groups,TRUE)){$group=$name;$name=array_search($group,$this->groups,TRUE);}else{throw
- new
- InvalidArgumentException("Group not found in form '$this->name'");}foreach($group->getControls()as$control){$this->removeComponent($control);}unset($this->groups[$name]);}function
- getGroups(){return$this->groups;}function
- getGroup($name){return
- isset($this->groups[$name])?$this->groups[$name]:NULL;}function
- setEncoding($value){$this->encoding=empty($value)?'UTF-8':strtoupper($value);if($this->encoding!=='UTF-8'&&!extension_loaded('mbstring')){throw
- new
- Exception("The PHP extension 'mbstring' is required for this encoding but is not loaded.");}return$this;}final
- function
- getEncoding(){return$this->encoding;}function
- setTranslator(ITranslator$translator=NULL){$this->translator=$translator;return$this;}final
- function
- getTranslator(){return$this->translator;}function
- isAnchored(){return
- TRUE;}final
- function
- isSubmitted(){if($this->submittedBy===NULL){$this->getHttpData();$this->submittedBy=!empty($this->httpData);}return$this->submittedBy;}function
- setSubmittedBy(ISubmitterControl$by=NULL){$this->submittedBy=$by===NULL?FALSE:$by;return$this;}final
- function
- getHttpData(){if($this->httpData===NULL){if(!$this->isAnchored()){throw
- new
- InvalidStateException('Form is not anchored and therefore can not determine whether it was submitted.');}$this->httpData=(array)$this->receiveHttpData();}return$this->httpData;}function
- fireEvents(){if(!$this->isSubmitted()){return;}elseif($this->submittedBy
- instanceof
- 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
- function
- 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
- processHttpRequest(){trigger_error(__METHOD__.'() is deprecated; use fireEvents() instead.',E_USER_WARNING);$this->fireEvents();}function
- getValues(){$values=parent::getValues();unset($values[self::TRACKER_ID],$values[self::PROTECTOR_ID]);return$values;}function
- addError($message){$this->valid=FALSE;if($message!==NULL&&!in_array($message,$this->errors,TRUE)){$this->errors[]=$message;}}function
- getErrors(){return$this->errors;}function
- hasErrors(){return(bool)$this->getErrors();}function
- cleanErrors(){$this->errors=array();$this->valid=NULL;}function
- getElementPrototype(){return$this->element;}function
- setRenderer(IFormRenderer$renderer){$this->renderer=$renderer;return$this;}final
- function
- getRenderer(){if($this->renderer===NULL){$this->renderer=new
- ConventionalRenderer;}return$this->renderer;}function
- 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
- mb_convert_encoding($s,'HTML-ENTITIES','UTF-8');}else{echo$s;}}function
- __toString(){try{if(strcmp($this->encoding,'UTF-8')){return
- 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
- function
- getHttpRequest(){return
- class_exists('Environment')?Environment::getHttpRequest():new
- HttpRequest;}protected
- function
- getSession(){return
- Environment::getSession();}}class
- AppForm
- extends
- Form
- implements
- ISignalReceiver{function
- __construct(IComponentContainer$parent=NULL,$name=NULL){parent::__construct();$this->monitor('Nette\Application\Presenter');if($parent!==NULL){$parent->addComponent($this,$name);}}function
- getPresenter($need=TRUE){return$this->lookup('Nette\Application\Presenter',$need);}protected
- function
- attached($presenter){if($presenter
- instanceof
- Presenter){$this->setAction(new
- 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
- isAnchored(){return(bool)$this->getPresenter(FALSE);}protected
- function
- 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
- ArrayTools::mergeTree($request->getPost(),$request->getFiles());}else{return$request->getParams();}}function
- signalReceived($signal){if($signal==='submit'){$this->fireEvents();}else{throw
- new
- BadSignalException("There is no handler for signal '$signal' in {$this->reflection->name}.");}}}class
- Application
- extends
- Object{public
- 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
- 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
- new
- ApplicationException('Too many loops detected in application life cycle.');}if(!$request){$this->onStartup($this);$router=$this->getRouter();if($router
- instanceof
- MultiRouter&&!count($router)){$router[]=new
- SimpleRouter(array('presenter'=>'Default','action'=>'default'));}$request=$router->match($httpRequest);if(!($request
- instanceof
- PresenterRequest)){$request=NULL;throw
- new
- BadRequestException('No route for HTTP request.');}if(strcasecmp($request->getPresenterName(),$this->errorPresenter)===0){throw
- new
- 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
- new
- BadRequestException($e->getMessage(),404,$e);}$request->freeze();$this->presenter=new$class;$response=$this->presenter->run($request);if($response
- instanceof
- ForwardingResponse){$request=$response->getRequest();continue;}elseif($response
- instanceof
- 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
- ApplicationException('An error occured while executing error-presenter',0,$e);}if(!$httpResponse->isSent()){$httpResponse->setCode($e
- instanceof
- BadRequestException?$e->getCode():500);}if(!$repeatedError&&$this->errorPresenter){$repeatedError=TRUE;$request=new
- PresenterRequest($this->errorPresenter,PresenterRequest::FORWARD,array('exception'=>$e));}else{echo"<meta name='robots' content='noindex'>\n\n";if($e
- instanceof
- 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
- function
- getRequests(){return$this->requests;}final
- function
- getPresenter(){return$this->presenter;}final
- function
- getServiceLocator(){if($this->serviceLocator===NULL){$this->serviceLocator=new
- ServiceLocator(Environment::getServiceLocator());foreach($this->defaultServices
- as$name=>$service){if(!$this->serviceLocator->hasService($name)){$this->serviceLocator->addService($name,$service);}}}return$this->serviceLocator;}final
- function
- getService($name,array$options=NULL){return$this->getServiceLocator()->getService($name,$options);}function
- getRouter(){return$this->getServiceLocator()->getService('Nette\Application\IRouter');}function
- setRouter(IRouter$router){$this->getServiceLocator()->addService('Nette\Application\IRouter',$router);return$this;}function
- getPresenterLoader(){return$this->getServiceLocator()->getService('Nette\Application\IPresenterLoader');}static
- function
- createPresenterLoader(){return
- new
- PresenterLoader(Environment::getVariable('appDir'));}function
- 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
- 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
- ForwardingResponse($request));}}protected
- function
- getHttpRequest(){return
- Environment::getHttpRequest();}protected
- function
- getHttpResponse(){return
- Environment::getHttpResponse();}protected
- function
- getSession($namespace=NULL){return
- Environment::getSession($namespace);}}abstract
- class
- PresenterComponent
- extends
- ComponentContainer
- implements
- ISignalReceiver,IStatePersistent,ArrayAccess{protected$params=array();function
- __construct(IComponentContainer$parent=NULL,$name=NULL){$this->monitor('Nette\Application\Presenter');parent::__construct($parent,$name);}function
- getPresenter($need=TRUE){return$this->lookup('Nette\Application\Presenter',$need);}function
- getUniqueId(){return$this->lookupPath('Nette\Application\Presenter',TRUE);}protected
- function
- attached($presenter){if($presenter
- instanceof
- Presenter){$this->loadState($presenter->popGlobalParams($this->getUniqueId()));}}protected
- function
- 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
- TRUE;}}return
- FALSE;}function
- getReflection(){return
- new
- PresenterComponentReflection($this);}function
- 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
- 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
- instanceof$meta['since']){$val=$this->$nm;}else{continue;}if(is_object($val)){throw
- new
- 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
- function
- 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
- function
- getParamId($name){$uid=$this->getUniqueId();return$uid===''?$name:$uid.self::NAME_SEPARATOR.$name;}static
- function
- getPersistentParams(){$rc=new
- 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
- signalReceived($signal){if(!$this->tryCall($this->formatSignalMethod($signal),$this->params)){throw
- new
- BadSignalException("There is no handler for signal '$signal' in {$this->reflection->name} class.");}}function
- formatSignalMethod($signal){return$signal==NULL?NULL:'handle'.$signal;}function
- 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
- lazyLink($destination,$args=array()){if(!is_array($args)){$args=func_get_args();array_shift($args);}return
- new
- Link($this,$destination,$args);}function
- ajaxLink($destination,$args=array()){throw
- new
- DeprecatedException(__METHOD__.'() is deprecated.');}function
- 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
- function
- offsetSet($name,$component){$this->addComponent($component,$name);}final
- function
- offsetGet($name){return$this->getComponent($name,TRUE);}final
- function
- offsetExists($name){return$this->getComponent($name,FALSE)!==NULL;}final
- function
- offsetUnset($name){$component=$this->getComponent($name,FALSE);if($component!==NULL){$this->removeComponent($component);}}}abstract
- class
- Control
- extends
- PresenterComponent
- implements
- IPartiallyRenderable{private$template;private$invalidSnippets=array();final
- function
- getTemplate(){if($this->template===NULL){$value=$this->createTemplate();if(!($value
- instanceof
- ITemplate||$value===NULL)){$class=get_class($value);throw
- new
- UnexpectedValueException("Object returned by {$this->reflection->name}::createTemplate() must be instance of Nette\\Templates\\ITemplate, '$class' given.");}$this->template=$value;}return$this->template;}protected
- function
- createTemplate(){$template=new
- 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
- templatePrepareFilters($template){$template->registerFilter(new
- LatteFilter);}function
- getWidget($name){return$this->getComponent($name);}function
- 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
- invalidateControl($snippet=NULL){$this->invalidSnippets[$snippet]=TRUE;}function
- validateControl($snippet=NULL){if($snippet===NULL){$this->invalidSnippets=array();}else{unset($this->invalidSnippets[$snippet]);}}function
- isControlInvalid($snippet=NULL){if($snippet===NULL){if(count($this->invalidSnippets)>0){return
- TRUE;}else{foreach($this->getComponents()as$component){if($component
- instanceof
- IRenderable&&$component->isControlInvalid()){return
- TRUE;}}return
- FALSE;}}else{return
- isset($this->invalidSnippets[NULL])||isset($this->invalidSnippets[$snippet]);}}function
- getSnippetId($name=NULL){return'snippet-'.$this->getUniqueId().'-'.$name;}}class
- AbortException
- extends
- Exception{}class
- ApplicationException
- extends
- Exception{function
- __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
- BadRequestException
- extends
- Exception{protected$defaultCode=404;function
- __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
- BadSignalException
- extends
- BadRequestException{protected$defaultCode=403;}class
- ForbiddenRequestException
- extends
- BadRequestException{protected$defaultCode=403;}class
- InvalidLinkException
- extends
- Exception{}class
- InvalidPresenterException
- extends
- InvalidLinkException{}class
- Link
- extends
- Object{private$component;private$destination;private$params;function
- __construct(PresenterComponent$component,$destination,array$params){$this->component=$component;$this->destination=$destination;$this->params=$params;}function
- getDestination(){return$this->destination;}function
- setParam($key,$value){$this->params[$key]=$value;return$this;}function
- getParam($key){return
- isset($this->params[$key])?$this->params[$key]:NULL;}function
- getParams(){return$this->params;}function
- __toString(){try{return$this->component->link($this->destination,$this->params);}catch(Exception$e){Debug::toStringException($e);}}}abstract
- class
- Presenter
- extends
- Control
- implements
- IPresenter{const
- PHASE_STARTUP=1;const
- PHASE_SIGNAL=3;const
- PHASE_RENDER=4;const
- PHASE_SHUTDOWN=5;const
- INVALID_LINK_SILENT=1;const
- INVALID_LINK_WARNING=2;const
- INVALID_LINK_EXCEPTION=3;const
- SIGNAL_KEY='do';const
- ACTION_KEY='action';const
- FLASH_KEY='_fid';public
- static$defaultAction='default';public
- 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
- function
- getRequest(){return$this->request;}final
- function
- getPresenter($need=TRUE){return$this;}final
- function
- getUniqueId(){return'';}function
- 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
- instanceof
- 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