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