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

Iterating via objects #4

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Aura/Input/FieldCollection.php
Expand Up @@ -10,14 +10,17 @@
*/
namespace Aura\Input;

use ArrayIterator;
use IteratorAggregate;

/**
*
* A collection of fields.
*
* @package Aura.Input
*
*/
class FieldCollection
class FieldCollection implements IteratorAggregate
{
/**
*
Expand Down Expand Up @@ -92,4 +95,9 @@ public function getNames()
{
return array_keys($this->fields);
}

public function getIterator()
{
return new ArrayIterator($this->fields);
}
}
8 changes: 4 additions & 4 deletions src/Aura/Input/Form.php
Expand Up @@ -165,9 +165,9 @@ protected function getValue($name, $data)
$end = strpos($name, ']');
$sub = substr($name, $pos + 1, $end - $pos - 1)
. substr($name, $end + 1);

$value = isset($data[$key]) ? $data[$key] : null;
// recursively descend into the data
return $this->getValue($sub, $data[$key]);
return $this->getValue($sub, $value);
}

/**
Expand All @@ -183,7 +183,7 @@ protected function getValue($name, $data)
*/
public function getValues()
{
$data = [];
$data = array_fill_keys($this->fields->getNames(), '');
foreach ($this->values as $name => $value) {
$this->setValue($name, $value, $data);
}
Expand Down Expand Up @@ -230,4 +230,4 @@ protected function setValue($name, $value, &$data)
// recursively descend into the data
$this->setValue($sub, $value, $data[$key]);
}
}
}