/** * @inheritdoc */ public function transform(ParameterBag $item) { foreach ($item->keys() as $key) { if (!in_array($key, $this->fields)) { $item->remove($key); } } }
public function it_sets_found_object_as_request_parameter(ParamConverter $paramConverter, TranslatableMetadata $translatableMetadata, Request $request, ParameterBag $attributes, TranslatableRepository $translatableRepository, \stdClass $object) { $paramConverter->getClass()->willReturn('TranslatableEntity'); $paramConverter->getName()->willReturn('object'); $translatableMetadata->hasTranslatableProperties()->willReturn(true); $request->getLocale()->willReturn('some_locale'); $request->attributes = $attributes; $attributes->keys()->willReturn(array('translatableProperty')); $attributes->get('translatableProperty')->willReturn('translationValue'); $translatableMetadata->getTranslatableProperties()->willReturn(array('translations' => array('translatableProperty' => 'translationField'))); $translatableRepository->findTranslatableOneBy(array('translatableProperty' => 'translationValue'), null, 'some_locale')->willReturn($object); $attributes->set('object', $object)->shouldBeCalled(); $this->apply($request, $paramConverter); }
/** * Return the file path to current layout, try to create it if not exists. * * @param Layout $layout * * @return string the file path * * @throws RendererException */ protected function getLayoutFile(Layout $layout) { $layoutfile = $layout->getPath(); if (null === $layoutfile && 0 < $this->manageableExt->count()) { $adapter = null; if (null !== $this->defaultAdapter && null !== ($adapter = $this->rendererAdapters->get($this->defaultAdapter))) { $extensions = $adapter->getManagedFileExtensions(); } else { $extensions = $this->manageableExt->keys(); } if (0 === count($extensions)) { throw new RendererException('Declared adapter(s) (count:' . $this->rendererAdapters->count() . ') is/are not able to manage ' . 'any file extensions at moment.'); } $layoutfile = StringUtils::toPath($layout->getLabel(), array('extension' => reset($extensions))); $layout->setPath($layoutfile); } return $layoutfile; }
/** * Try to compute and guess a valid filename for $object: * - on success return string which is the right filename with its extension * - on fail return false. * * @param RenderableInterface $object * @param string $mode * @return string|boolean string if successfully found a valid file name, else false */ private function getTemplateFile(RenderableInterface $object, $mode = null) { $tmpStorage = $this->templateFile; $template = $this->getTemplatePath($object); foreach ($this->manageableExt->keys() as $ext) { $this->templateFile = $template . (null !== $mode ? '.' . $mode : '') . $ext; if ($this->isValidTemplateFile($this->templateFile)) { $filename = $this->templateFile; $this->templateFile = $tmpStorage; return $filename; } } if ($parentClassname = get_parent_class($object)) { $parent = new \ReflectionClass($parentClassname); if (!$parent->isAbstract()) { return $this->getTemplateFile(new $parentClassname(), $mode, null); } } return false; }
public function testKeys() { $bag = new ParameterBag(array('foo' => 'bar')); $this->assertEquals(array('foo'), $bag->keys()); }
/** * @inheritdoc */ public function transform(ParameterBag $item) { $keys = $this->field ? [$this->field] : $item->keys(); $this->replace($item, $keys); }
/** * @param Node $node * @param ParameterBag $parameters * * @return \Guzzle\Http\Message\Response * * @throws \UnexpectedValueException when trying to update zero parameters * or any prohibited parameters */ public function updateNode(Node $node, ParameterBag $parameters) { $allowableParamKeys = array('name', 'accessIPv4', 'accessIPv6'); $requestedParamKeys = $parameters->keys(); if (0 == sizeof($requestedParamKeys)) { throw new \UnexpectedValueException(sprintf('Expected values for any of the following properties, but got none: "%s".', implode(', ', $allowableParamKeys))); } $permittedKeys = array_intersect($requestedParamKeys, $allowableParamKeys); $prohibitedKeys = array_diff($requestedParamKeys, $permittedKeys); if (sizeof($prohibitedKeys)) { throw new \UnexpectedValueException(sprintf('Expected values for any of the following properties "%s". ' . 'The following requested properties are not allowed: "%s".', implode(', ', $allowableParamKeys), implode(', ', $prohibitedKeys))); } $updates = array(); foreach ($permittedKeys as $k) { $updates[$k] = $parameters->get($k); } $response = $this->toServer($node)->update($updates); # It would be nice to have an updateNodeFromServer so that the caller # gets the updates (which $server now has) for their Node. For now, just # send some more API requests... $nodes = $this->listNodes($node->getId()); # and update the few properties that might have changed $node->setName($nodes[0]->getName()); $node->setPublicIps($nodes[0]->getPublicIps()); $node->setState($nodes[0]->getState()); $node->setExtra($nodes[0]->getExtra()); return $response; }