Source for file AppForm.php

Documentation is available at AppForm.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see http://nettephp.com
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    http://nettephp.com/license  Nette license
  15. 15:  * @link       http://nettephp.com
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Application
  18. 18:  */
  19. 19:  
  20. 20:  
  21. 21:  
  22. 22: require_once dirname(__FILE__'/../Forms/Form.php';
  23. 23:  
  24. 24: require_once dirname(__FILE__'/../Application/ISignalReceiver.php';
  25. 25:  
  26. 26:  
  27. 27:  
  28. 28: /**
  29. 29:  * Web form as presenter component.
  30. 30:  *
  31. 31:  * @author     David Grudl
  32. 32:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  33. 33:  * @package    Nette\Application
  34. 34:  *
  35. 35:  * @property-read Presenter $presenter 
  36. 36:  */
  37. 37: class AppForm extends Form implements ISignalReceiver
  38. 38: {
  39. 39:  
  40. 40:     /**
  41. 41:      * Application form constructor.
  42. 42:      */
  43. 43:     public function __construct(IComponentContainer $parent NULL$name NULL)
  44. 44:     {
  45. 45:         $this->monitor('Nette\Application\Presenter');
  46. 46:         parent::__construct($name$parent);
  47. 47:     }
  48. 48:  
  49. 49:  
  50. 50:  
  51. 51:     /**
  52. 52:      * @return void 
  53. 53:      */
  54. 54:     public function addTracker($name)
  55. 55:     {
  56. 56:     }
  57. 57:  
  58. 58:  
  59. 59:  
  60. 60:     /**
  61. 61:      * Returns the presenter where this component belongs to.
  62. 62:      * @param  bool   throw exception if presenter doesn't exist?
  63. 63:      * @return Presenter|NULL
  64. 64:      */
  65. 65:     public function getPresenter($need TRUE)
  66. 66:     {
  67. 67:         return $this->lookup('Nette\Application\Presenter'$need);
  68. 68:     }
  69. 69:  
  70. 70:  
  71. 71:  
  72. 72:     /**
  73. 73:      * This method will be called when the component (or component's parent)
  74. 74:      * becomes attached to a monitored object. Do not call this method yourself.
  75. 75:      * @param  IComponent 
  76. 76:      * @return void 
  77. 77:      */
  78. 78:     protected function attached($presenter)
  79. 79:     {
  80. 80:         if ($presenter instanceof Presenter{
  81. 81:             $this->setAction(new Link(
  82. 82:                 $presenter,
  83. 83:                 $this->lookupPath('Nette\Application\Presenter'self::NAME_SEPARATOR 'submit!',
  84. 84:                 array()
  85. 85:             ));
  86. 86:         }
  87. 87:     }
  88. 88:  
  89. 89:  
  90. 90:  
  91. 91:     /**
  92. 92:      * Detects form submission and loads PresenterRequest values.
  93. 93:      * @return void 
  94. 94:      */
  95. 95:     public function processHttpRequest($foo NULL)
  96. 96:     {
  97. 97:         $presenter $this->getPresenter();
  98. 98:  
  99. 99:         $this->submittedBy = FALSE;
  100. 100:         if (!$presenter->isSignalReceiver($this'submit')) return;
  101. 101:  
  102. 102:         $isPost strcasecmp($this->getMethod()'post'=== 0;
  103. 103:         $request $presenter->getRequest();
  104. 104:         if ($request->isMethod('forward'|| $request->isMethod('post'!== $isPostreturn;
  105. 105:  
  106. 106:         $this->submittedBy = TRUE;
  107. 107:         if ($isPost{
  108. 108:             $this->loadHttpData(Tools::arrayMergeTree($request->getPost()$request->getFiles()));
  109. 109:  
  110. 110:         else {
  111. 111:             $this->loadHttpData($request->getParams());
  112. 112:         }
  113. 113:     }
  114. 114:  
  115. 115:  
  116. 116:  
  117. 117:     /********************* interface ISignalReceiver ****************d*g**/
  118. 118:  
  119. 119:  
  120. 120:  
  121. 121:     /**
  122. 122:      * This method is called by presenter.
  123. 123:      * @param  string 
  124. 124:      * @return void 
  125. 125:      */
  126. 126:     public function signalReceived($signal)
  127. 127:     {
  128. 128:         if ($signal === 'submit'{
  129. 129:             $this->submit();
  130. 130:  
  131. 131:         else {
  132. 132:             throw new BadSignalException("There is no handler for signal '$signal' in '{$this->getClass()}'.");
  133. 133:         }
  134. 134:     }
  135. 135: