Beispiel #1
0
 /**
  * Internal: receives submitted HTTP data.
  * @return array
  */
 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();
     }
 }
Beispiel #2
0
 /**
  * Detects form submission and loads PresenterRequest values.
  * @return void
  */
 public function processHttpRequest($foo = NULL)
 {
     $presenter = $this->getPresenter();
     $this->submittedBy = FALSE;
     if (!$presenter->isSignalReceiver($this, 'submit')) {
         return;
     }
     $isPost = strcasecmp($this->getMethod(), 'post') === 0;
     $request = $presenter->getRequest();
     if ($request->isMethod('forward') || $request->isMethod('post') !== $isPost) {
         return;
     }
     $this->submittedBy = TRUE;
     if ($isPost) {
         $this->loadHttpData(ArrayTools::mergeTree($request->getPost(), $request->getFiles()));
     } else {
         $this->loadHttpData($request->getParams());
     }
 }
Beispiel #3
0
 /**
  * Reads configuration from INI file.
  * @param  string  file name
  * @param  string  section to load
  * @return array
  * @throws InvalidStateException
  */
 public static function load($file, $section = NULL)
 {
     if (!is_file($file) || !is_readable($file)) {
         throw new FileNotFoundException("File '{$file}' is missing or is not readable.");
     }
     Tools::tryError();
     $ini = parse_ini_file($file, TRUE);
     if (Tools::catchError($msg)) {
         throw new Exception($msg);
     }
     $separator = trim(self::$sectionSeparator);
     $data = array();
     foreach ($ini as $secName => $secData) {
         // is section?
         if (is_array($secData)) {
             if (substr($secName, -1) === self::$rawSection) {
                 $secName = substr($secName, 0, -1);
             } elseif (self::$keySeparator) {
                 // process key separators (key1> key2> key3)
                 $tmp = array();
                 foreach ($secData as $key => $val) {
                     $cursor =& $tmp;
                     foreach (explode(self::$keySeparator, $key) as $part) {
                         if (!isset($cursor[$part]) || is_array($cursor[$part])) {
                             $cursor =& $cursor[$part];
                         } else {
                             throw new InvalidStateException("Invalid key '{$key}' in section [{$secName}] in '{$file}'.");
                         }
                     }
                     $cursor = $val;
                 }
                 $secData = $tmp;
             }
             // process extends sections like [staging < production] (with special support for separator ':')
             $parts = $separator ? explode($separator, strtr($secName, ':', $separator)) : array($secName);
             if (count($parts) > 1) {
                 $parent = trim($parts[1]);
                 $cursor =& $data;
                 foreach (self::$keySeparator ? explode(self::$keySeparator, $parent) : array($parent) as $part) {
                     if (isset($cursor[$part]) && is_array($cursor[$part])) {
                         $cursor =& $cursor[$part];
                     } else {
                         throw new InvalidStateException("Missing parent section [{$parent}] in '{$file}'.");
                     }
                 }
                 $secData = ArrayTools::mergeTree($secData, $cursor);
             }
             $secName = trim($parts[0]);
             if ($secName === '') {
                 throw new InvalidStateException("Invalid empty section name in '{$file}'.");
             }
         }
         if (self::$keySeparator) {
             $cursor =& $data;
             foreach (explode(self::$keySeparator, $secName) as $part) {
                 if (!isset($cursor[$part]) || is_array($cursor[$part])) {
                     $cursor =& $cursor[$part];
                 } else {
                     throw new InvalidStateException("Invalid section [{$secName}] in '{$file}'.");
                 }
             }
         } else {
             $cursor =& $data[$secName];
         }
         if (is_array($secData) && is_array($cursor)) {
             $secData = ArrayTools::mergeTree($secData, $cursor);
         }
         $cursor = $secData;
     }
     if ($section === NULL) {
         return $data;
     } elseif (!isset($data[$section]) || !is_array($data[$section])) {
         throw new InvalidStateException("There is not section [{$section}] in '{$file}'.");
     } else {
         return $data[$section];
     }
 }
Beispiel #4
0
 /**
  * Internal: receives submitted HTTP data.
  * @return array
  */
 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;
 }
Beispiel #5
0
 /**
  * Detects form submission and loads HTTP values.
  * @param  Nette\Web\IHttpRequest  optional request object
  * @return void
  */
 public function processHttpRequest($httpRequest = NULL)
 {
     $this->submittedBy = FALSE;
     if ($httpRequest === NULL) {
         $httpRequest = $this->getHttpRequest();
     }
     $httpRequest->setEncoding($this->encoding);
     if (strcasecmp($this->getMethod(), 'post') === 0) {
         if (!$httpRequest->isMethod('post')) {
             return;
         }
         $data = ArrayTools::mergeTree($httpRequest->getPost(), $httpRequest->getFiles());
     } else {
         if (!$httpRequest->isMethod('get')) {
             return;
         }
         $data = $httpRequest->getQuery();
     }
     $tracker = $this->getComponent(self::TRACKER_ID, FALSE);
     if ($tracker) {
         if (!isset($data[self::TRACKER_ID]) || $data[self::TRACKER_ID] !== $tracker->getValue()) {
             return;
         }
     } else {
         if (!count($data)) {
             return;
         }
     }
     $this->submittedBy = TRUE;
     $this->loadHttpData($data);
     $this->submit();
 }