Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Allow form caching #4947

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
15 changes: 8 additions & 7 deletions library/Zend/Filter/FilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class FilterChain extends AbstractFilter implements Countable
*/
public function __construct($options = null)
{
$this->filters = new PriorityQueue();

if (null !== $options) {
$this->setOptions($options);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a BC break ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if you hadn't replaced every call to $this->filters with $this->getFilters(). :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I extended the class and that I try accessing $this->filters directly ?

class FilterChainExtension extends FilterChain
{
    public function __construct()
    {
        parent::__construct();
        $this->filters->getQueue(); // Fatal error
    }
}

Or in any other method for that matter, any call to $this->filters directly would trigger an error "access to non-object"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasCantonnet makes a good point; we should keep the instantiation within the constructor.

}
Expand Down Expand Up @@ -96,7 +94,7 @@ public function setOptions($options)
*/
public function count()
{
return count($this->filters);
return count($this->getFilters());
}

/**
Expand Down Expand Up @@ -156,7 +154,7 @@ public function attach($callback, $priority = self::DEFAULT_PRIORITY)
}
$callback = array($callback, 'filter');
}
$this->filters->insert($callback, $priority);
$this->getFilters()->insert($callback, $priority);
return $this;
}

Expand Down Expand Up @@ -190,7 +188,7 @@ public function attachByName($name, $options = array(), $priority = self::DEFAUL
*/
public function merge(FilterChain $filterChain)
{
foreach ($filterChain->filters->toArray(PriorityQueue::EXTR_BOTH) as $item) {
foreach ($filterChain->getFilters()->toArray(PriorityQueue::EXTR_BOTH) as $item) {
$this->attach($item['data'], $item['priority']);
}

Expand All @@ -204,6 +202,9 @@ public function merge(FilterChain $filterChain)
*/
public function getFilters()
{
if (null === $this->filters) {
$this->filters = new PriorityQueue();
}
return $this->filters;
}

Expand All @@ -217,7 +218,7 @@ public function getFilters()
*/
public function filter($value)
{
$chain = clone $this->filters;
$chain = clone $this->getFilters();

$valueFiltered = $value;
foreach ($chain as $filter) {
Expand All @@ -232,7 +233,7 @@ public function filter($value)
*/
public function __clone()
{
$this->filters = clone $this->filters;
$this->filters = clone $this->getFilters();
}

/**
Expand Down
14 changes: 9 additions & 5 deletions library/Zend/Form/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function add($elementOrFieldset, array $flags = array())
$order = $flags['priority'];
}

$this->iterator->insert($elementOrFieldset, $order);
$this->getIterator()->insert($elementOrFieldset, $order);
$this->byName[$name] = $elementOrFieldset;

if ($elementOrFieldset instanceof FieldsetInterface) {
Expand Down Expand Up @@ -235,7 +235,7 @@ public function remove($elementOrFieldset)
$entry = $this->byName[$elementOrFieldset];
unset($this->byName[$elementOrFieldset]);

$this->iterator->remove($entry);
$this->getIterator()->remove($entry);

if ($entry instanceof FieldsetInterface) {
unset($this->fieldsets[$elementOrFieldset]);
Expand Down Expand Up @@ -413,7 +413,7 @@ public function populateValues($data)
*/
public function count()
{
return $this->iterator->count();
return $this->getIterator()->count();
}

/**
Expand All @@ -423,6 +423,9 @@ public function count()
*/
public function getIterator()
{
if (null === $this->iterator) {
$this->iterator = new PriorityQueue();
}
return $this->iterator;
}

Expand Down Expand Up @@ -613,7 +616,8 @@ protected function extract()
*/
public function __clone()
{
$items = $this->iterator->toArray(PriorityQueue::EXTR_BOTH);
$iterator = $this->getIterator();
$items = $iterator->toArray(PriorityQueue::EXTR_BOTH);

$this->byName = array();
$this->elements = array();
Expand All @@ -624,7 +628,7 @@ public function __clone()
$elementOrFieldset = clone $item['data'];
$name = $elementOrFieldset->getName();

$this->iterator->insert($elementOrFieldset, $item['priority']);
$iterator->insert($elementOrFieldset, $item['priority']);
$this->byName[$name] = $elementOrFieldset;

if ($elementOrFieldset instanceof FieldsetInterface) {
Expand Down