/** * Expands %placeholders%. * @param mixed * @param array * @param bool * @return mixed * @throws InvalidArgumentException */ public static function expand($var, array $params, $recursive = FALSE) { if (is_array($var)) { $res = array(); foreach ($var as $key => $val) { $res[$key] = self::expand($val, $params, $recursive); } return $res; } elseif ($var instanceof NDIStatement) { return new NDIStatement(self::expand($var->entity, $params, $recursive), self::expand($var->arguments, $params, $recursive)); } elseif (!is_string($var)) { return $var; } $parts = preg_split('#%([\w.-]*)%#i', $var, -1, PREG_SPLIT_DELIM_CAPTURE); $res = ''; foreach ($parts as $n => $part) { if ($n % 2 === 0) { $res .= $part; } elseif ($part === '') { $res .= '%'; } elseif (isset($recursive[$part])) { throw new InvalidArgumentException('Circular reference detected for variables: ' . implode(', ', array_keys($recursive)) . '.'); } else { $val = NArrays::get($params, explode('.', $part)); if ($recursive) { $val = self::expand($val, $params, (is_array($recursive) ? $recursive : array()) + array($part => 1)); } if (strlen($part) + 2 === strlen($var)) { return $val; } if (!is_scalar($val)) { throw new InvalidArgumentException("Unable to concatenate non-scalar parameter '$part' into '$var'."); } $res .= $val; } } return $res; }
/** * Internal: returns submitted HTTP data or NULL when form was not submitted. * @return array|NULL */ 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 NArrays::mergeTree($request->getPost(), $request->getFiles()); } else { return $request->getParameters(); } }
/** * 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(NArrays::get($this->getForm()->getHttpData(), $path, NULL) !== NULL); }
/** * Loads HTTP data. * @return void */ public function loadHttpData() { $path = explode('[', strtr(str_replace(array('[]', ']'), '', $this->getHtmlName()), '.', '_')); $this->setValue(NArrays::get($this->getForm()->getHttpData(), $path, NULL)); }
/** * Returns uploaded file. * @param string key (or more keys) * @return NHttpUploadedFile */ final public function getFile($key) { $_args=func_get_args(); return NArrays::get($this->files, $_args, NULL); }
/** * Internal: returns submitted HTTP data or NULL when form was not submitted. * @return array|NULL */ protected function receiveHttpData() { $httpRequest = $this->getHttpRequest(); if (strcasecmp($this->getMethod(), $httpRequest->getMethod())) { return; } if ($httpRequest->isMethod('post')) { $data = NArrays::mergeTree($httpRequest->getPost(), $httpRequest->getFiles()); } else { $data = $httpRequest->getQuery(); if (!$data) { return; } } if ($tracker = $this->getComponent(self::TRACKER_ID, FALSE)) { if (!isset($data[self::TRACKER_ID]) || $data[self::TRACKER_ID] !== $tracker->getValue()) { return; } } return $data; }