/** * Return request parameter from query or post body */ public function getParameters() { if ($this->parameters === null) { $this->parameters = new ParameterBag($this->request->query->all()); if ($this->request->getMethod() !== Request::METHOD_GET) { $this->parameters->add($this->request->request->all()); } } return $this->parameters; }
public function testRemove() { $bag = new ParameterBag(array('foo' => 'bar')); $bag->add(array('bar' => 'bas')); $this->assertEquals(array('foo' => 'bar', 'bar' => 'bas'), $bag->all()); $bag->remove('bar'); $this->assertEquals(array('foo' => 'bar'), $bag->all()); }
/** * * @param String|Array $query * @return \Spore\HttpFoundation\Request * @throws \InvalidArgumentException */ public function setQuery($query) { if (is_string($query)) { parse_str($query, $query); } if (!is_array($query)) { throw new \InvalidArgumentException("Invalid argument"); } if (empty($this->query)) { $this->query = new ParameterBag($query); } else { $this->query->add($query); } return $this; }
/** * @param array $attributes * @param array $disk * @param array $database */ public function __construct(array $attributes = array(), array $disk = array(), array $database = array()) { $this->attributes = new ParameterBag($this->attributes_default); $this->disk = new ParameterBag($this->disk_default); $this->database = new ParameterBag($this->database_default); // Set all attributes $this->attributes->add($attributes); $this->disk->add($disk); $this->database->add($database); $version = is_null($this->attributes->get('version')) && $this->disk->get('is_valid') ? $this->disk->get('version') : $this->attributes->get('version'); $img = $this->attributes->get('img'); if (empty($img)) { $this->attributes->set('img', __PS_BASE_URI__ . 'img/questionmark.png'); } $this->attributes->set('version', $version); $this->attributes->set('type', $this->convertType($this->get('origin_filter_value'))); // Unfortunately, we can sometime have an array, and sometimes an object. // This is the first place where this value *always* exists $this->attributes->set('price', (array) $this->attributes->get('price')); }
protected function parseConnections($options, $defaultHost, $defaultPort) { if (isset($options['host']) || isset($options['port'])) { $options['connections'][] = $options; } elseif ($options['connection']) { $options['connections'][] = $options['connection']; } /** @var ParameterBag[] $toParse */ $toParse = []; if (isset($options['connections'])) { foreach ((array) $options['connections'] as $alias => $conn) { if (is_string($conn)) { $conn = ['host' => $conn]; } $conn += ['scheme' => 'tcp', 'host' => $defaultHost, 'port' => $defaultPort]; $conn = new ParameterBag($conn); if ($conn->has('password')) { $conn->set('pass', $conn->get('password')); $conn->remove('password'); } $conn->set('uri', Uri::fromParts($conn->all())); $toParse[] = $conn; } } elseif (isset($options['save_path'])) { foreach (explode(',', $options['save_path']) as $conn) { $uri = new Uri($conn); $connBag = new ParameterBag(); $connBag->set('uri', $uri); $connBag->add(parse_query($uri->getQuery())); $toParse[] = $connBag; } } $connections = []; foreach ($toParse as $conn) { /** @var Uri $uri */ $uri = $conn->get('uri'); $parts = explode(':', $uri->getUserInfo(), 2); $password = isset($parts[1]) ? $parts[1] : null; $connections[] = ['scheme' => $uri->getScheme(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'alias' => $conn->get('alias'), 'prefix' => $conn->get('prefix'), 'password' => $password, 'database' => $conn->get('database'), 'persistent' => $conn->get('persistent'), 'weight' => $conn->get('weight'), 'timeout' => $conn->get('timeout')]; } return $connections; }
protected function parseConnections($options, $defaultHost, $defaultPort, $defaultScheme = 'tcp') { if (isset($options['host']) || isset($options['port'])) { $options['connections'][] = $options; } elseif ($options['connection']) { $options['connections'][] = $options['connection']; } /** @var ParameterBag[] $toParse */ $toParse = []; if (isset($options['connections'])) { foreach ((array) $options['connections'] as $alias => $conn) { if (is_string($conn)) { $conn = ['host' => $conn]; } $conn += ['scheme' => $defaultScheme, 'host' => $defaultHost, 'port' => $defaultPort]; $conn = new ParameterBag($conn); if ($conn->has('password')) { $conn->set('pass', $conn->get('password')); $conn->remove('password'); } $conn->set('uri', Uri::fromParts($conn->all())); $toParse[] = $conn; } } else { $connections = isset($options['save_path']) ? (array) explode(',', $options['save_path']) : []; if (empty($connections)) { $connections[] = $defaultHost . ':' . $defaultPort; } foreach ($connections as $conn) { // Default scheme if not given so parse_url works correctly. if (!preg_match('~^\\w+://.+~', $conn)) { $conn = $defaultScheme . '://' . $conn; } $uri = new Uri($conn); $connBag = new ParameterBag(); $connBag->set('uri', $uri); $connBag->add(Psr7\parse_query($uri->getQuery())); $toParse[] = $connBag; } } $connections = []; foreach ($toParse as $conn) { /** @var Uri $uri */ $uri = $conn->get('uri'); $parts = explode(':', $uri->getUserInfo(), 2); $password = isset($parts[1]) ? $parts[1] : null; $connections[] = ['scheme' => $uri->getScheme(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'alias' => $conn->get('alias'), 'prefix' => $conn->get('prefix'), 'password' => $password, 'database' => $conn->get('database'), 'persistent' => $conn->get('persistent'), 'weight' => $conn->get('weight'), 'timeout' => $conn->get('timeout')]; } return $connections; }
public static function postSequence(Application $app, Request $request, $dataType, $dataTypeAccessHash, $recordId, $property) { /** @var Repository $repository */ $repository = self::getRepository($app, $dataType, $dataTypeAccessHash); $dataTypeDefinition = self::getDataTypeDefinition($app, $repository, $dataType, $dataTypeAccessHash); if ($repository && $dataTypeDefinition) { $items = array(); foreach ($request->request->getIterator() as $key => $value) { $split = explode('_', $key); if (count($split >= 3)) { if ($split[0] == 'item') { $nr = (int) $split[1]; $l = strlen('item_' . $nr); $property = substr($key, $l + 1); $items[$nr][$property] = $value; } } } $sequence = array(); if ($request->request->has('sequence')) { $types = $request->get('type'); $i = 0; foreach ($request->get('sequence') as $nr) { $item = $items[$nr]; $type = $types[$i]; $clippingDefinition = $dataTypeDefinition->getClippingDefinition($type); $bag = new ParameterBag(); $bag->add($item); $item = $app['form']->extractFormElementValuesFromPostRequest($bag, $clippingDefinition->getFormElementDefinitions(), array()); $sequence[] = array($type => $item); $i++; } } return $app->json(array('sequence' => $sequence)); } }
/** * Add an option for this event * * @param string $key * @param mixed $value */ public final function addOption($key, $value) { $this->options->add(array($key => $value)); }