Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set values anytime, typos,... #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 6 additions & 44 deletions src/Kdyby/Replicator/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class Container extends Nette\Forms\Container
/** @var array */
private $created = array();

/** @var \Nette\Http\IRequest */
private $httpRequest;

/** @var array */
private $httpPost;

Expand Down Expand Up @@ -162,11 +159,9 @@ private function getFirstControlName()


/**
* @param string $name
*
* @return \Nette\Forms\Container
*/
protected function createContainer($name)
protected function createContainer()
{
$class = $this->containerClass;
return new $class();
Expand Down Expand Up @@ -209,7 +204,7 @@ public function createOne($name = NULL)
$name = $names ? max($names) + 1 : 0;
}

// Container is overriden, therefore every request for getComponent($name, FALSE) would return container
// Container is overridden, therefore every request for getComponent($name, FALSE) would return container
if (isset($this->created[$name])) {
throw new Nette\InvalidArgumentException("Container with name '$name' already exists.");
}
Expand All @@ -227,11 +222,9 @@ public function createOne($name = NULL)
*/
public function setValues($values, $erase = FALSE, $onlyDisabled = FALSE)
{
if (!$this->form->isAnchored() || !$this->form->isSubmitted()) {
foreach ($values as $name => $value) {
if ((is_array($value) || $value instanceof \Traversable) && !$this->getComponent($name, FALSE)) {
$this->createOne($name);
}
foreach ($values as $name => $value) {
if ((is_array($value) || $value instanceof \Traversable) && !$this->getComponent($name, FALSE)) {
$this->createOne($name);
}
}

Expand All @@ -250,11 +243,7 @@ protected function loadHttpData()
return;
}

foreach ((array) $this->getHttpData() as $name => $value) {
if ((is_array($value) || $value instanceof \Traversable) && !$this->getComponent($name, FALSE)) {
$this->createOne($name);
}
}
$this->setValues((array) $this->getHttpData());
}


Expand Down Expand Up @@ -310,33 +299,6 @@ private function getHttpData()



/**
* @internal
* @param \Nette\Application\Request $request
* @return Container
*/
public function setRequest(Nette\Application\Request $request)
{
$this->httpRequest = $request;
return $this;
}



/**
* @return \Nette\Application\Request
*/
private function getRequest()
{
if ($this->httpRequest !== NULL) {
return $this->httpRequest;
}

return $this->httpRequest = $this->getForm()->getPresenter()->getRequest();
}



/**
* @param \Nette\Forms\Container $container
* @param boolean $cleanUpGroups
Expand Down