Zend Framework

Zend_Navigation_Page xml option "visible" only works with integers not booleans

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.10.6
  • Fix Version/s: 1.11.11
  • Component/s: Zend_Navigation
  • Labels:
    None

Description

When using a navigation xml config file the visible-option is not working as expected as it is not accepting booleans (true/false) as values.
This is accepted:

<visible>0</visible>

This is ignored:

<visible>false</visible>

"false" value is accepted in array configs to this is a little bit confusing and I do not see a reason for forcing integer values as it is actually a flag.

A possible quick fix would be in Zend/Navigation/Page.php on line 731:

$this->_visible = (bool) $visible;

and changing it to:

$this->_visible = (bool)(int) $visible;

but I am not sure if this is the right place to fix this. The problem here is that the string "false" is casted to boolean true.

  1. Page.php.patch
    13/Aug/11 2:43 PM
    0.5 kB
    Frank Brückner
  2. PageTest.php.patch
    13/Aug/11 2:43 PM
    0.6 kB
    Frank Brückner

Issue Links

Activity

Hide
Kai Uwe added a comment -

Hello Micha,

and changing it to:

$this->_visible = (bool)(int) $visible;

Bad idea:

<visible>true</visible>

becomes

false

My proposal for this problem:

public function setVisible($visible = true)
{
    if ('false' === strtolower($visible)) {
        $visible = false;
    }

    $this->_visible = (bool) $visible;
    return $this;
}

but I am not sure if this is the right place to fix this.
The documentation says:

Note: Return Type
Configuration data read into Zend_Config_Xml are always returned as strings. Conversion of data from strings to other types is left to developers to suit their particular needs.

http://framework.zend.com/manual/en/zend.config.adapters.xml.html

Show
Kai Uwe added a comment - Hello Micha,
and changing it to:
$this->_visible = (bool)(int) $visible;
Bad idea:
<visible>true</visible>
becomes
false
My proposal for this problem:
public function setVisible($visible = true)
{
    if ('false' === strtolower($visible)) {
        $visible = false;
    }

    $this->_visible = (bool) $visible;
    return $this;
}
but I am not sure if this is the right place to fix this. The documentation says:
Note: Return Type Configuration data read into Zend_Config_Xml are always returned as strings. Conversion of data from strings to other types is left to developers to suit their particular needs.
http://framework.zend.com/manual/en/zend.config.adapters.xml.html
Hide
Frank Brückner added a comment -

Fix and unit test added.

Show
Frank Brückner added a comment - Fix and unit test added.
Hide
Pádraic Brady added a comment -

Fixed in r24442 and ZF2 via PR. Thanks for the patch!!!

Show
Pádraic Brady added a comment - Fixed in r24442 and ZF2 via PR. Thanks for the patch!!!

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: