/** * Loads HTTP data. * @return void */ public function loadHttpData() { $path = $this->getHtmlName(); // img_x or img['x'] $path = explode('[', strtr(str_replace(']', '', strpos($path, '[') === FALSE ? $path . '.x' : substr($path, 0, -2)), '.', '_')); $this->setValue(Nette\ArrayTools::get($this->getForm()->getHttpData(), $path) !== NULL); }
/** * Loads HTTP data. * @return void */ public function loadHttpData() { $path = explode('[', strtr(str_replace(array('[]', ']'), '', $this->getHtmlName()), '.', '_')); $this->setValue(Nette\ArrayTools::get($this->getForm()->getHttpData(), $path)); }
/** * Internal: receives submitted HTTP data. * @return array */ protected function receiveHttpData() { $httpRequest = $this->getHttpRequest(); if (strcasecmp($this->getMethod(), $httpRequest->getMethod())) { return; } if ($httpRequest->isMethod('post')) { $data = Nette\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; }
/** * 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 Nette\ArrayTools::mergeTree($request->getPost(), $request->getFiles()); } else { return $request->getParams(); } }
/** * 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."); } Nette\Debug::tryError(); $ini = parse_ini_file($file, TRUE); if (Nette\Debug::catchError($e)) { throw $e; } $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 = Nette\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 = Nette\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]; } }
/** * Returns uploaded file. * @param string key (or more keys) * @return HttpUploadedFile */ public final function getFile($key) { if ($this->files === NULL) { $this->initialize(); } $args = func_get_args(); return Nette\ArrayTools::get($this->files, $args); }
/** * Returns uploaded file. * @param string key (or more keys) * @return HttpUploadedFile */ final public function getFile($key) { $args = func_get_args(); return Nette\ArrayTools::get($this->files, $args); }
/** * Reads configuration from NEON file. * @param string file name * @return array * @throws \InvalidStateException */ public static function load($file) { if (!is_file($file) || !is_readable($file)) { throw new \FileNotFoundException("File '$file' is missing or is not readable."); } $neon = Neon::decode(file_get_contents($file)); $separator = trim(self::$sectionSeparator); $data = array(); foreach ($neon as $secName => $secData) { if ($secData === NULL) { // empty section $secData = array(); } if (is_array($secData)) { // process extends sections like [staging < production] $parts = $separator ? explode($separator, $secName) : 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 = Nette\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 = Nette\ArrayTools::mergeTree($secData, $cursor); } $cursor = $secData; } return $data; }