Permalink
Browse files

Fix FormManager creators priorities handling

  • Loading branch information...
everzet committed Nov 26, 2012
1 parent fc868bf commit 18c8f0ba68bfc88ecd6cedc93e3c915a685f2bbd
Showing with 6 additions and 10 deletions.
  1. +5 −9 Form/FormManager.php
  2. +1 −1 spec/Form/FormManager.php
View
@@ -7,11 +7,12 @@
class FormManager
{
private $request;
- private $creators = array();
+ private $creators;
public function __construct(Request $request)
{
- $this->request = $request;
+ $this->creators = new \SplPriorityQueue;

This comment has been minimized.

Show comment Hide comment
@gquemener

gquemener Nov 26, 2012

Contributor

Sweeet

@gquemener

gquemener Nov 26, 2012

Contributor

Sweeet

+ $this->request = $request;
}
public function createObjectForm($object, $purpose = null, array $options = array())
@@ -38,16 +39,11 @@ public function createBoundObjectForm($object, $purpose = null, array $options =
public function registerCreator(FormCreatorInterface $creator, $priority = 0)
{
- if (isset($this->creators[$priority])) {
- return $this->registerCreator($creator, ++$priority);
- }
- $this->creators[$priority] = $creator;
+ $this->creators->insert($creator, $priority);
}
public function getCreators()
{
- krsort($this->creators);
-
- return $this->creators;
+ return array_values(iterator_to_array($this->creators));
}
}
@@ -29,7 +29,7 @@ function it_should_be_able_to_register_creators()
function it_should_be_able_to_register_creators_orderly($creator1, $creator2, $creator3)
{
- $this->getCreators()->shouldReturn(array(3 => $creator2, 2 => $creator1, 1 => $creator3));
+ $this->getCreators()->shouldReturn(array($creator2, $creator1, $creator3));
}
/**

0 comments on commit 18c8f0b

Please sign in to comment.