Jackalope\Helper::getBoolAttribute PHP Method

getBoolAttribute() public static method

The attribute can contain the string 'false' which is interpreted as false, everything else is true.
public static getBoolAttribute ( DOMElement $node, string $attribute ) : boolean
$node DOMElement to fetch from
$attribute string name to fetch
return boolean the value converted to bool
    public static function getBoolAttribute(DOMElement $node, $attribute)
    {
        if (!$node->hasAttribute($attribute)) {
            throw new RepositoryException("Expected attribute {$attribute} not found on " . $node->getNodePath());
        }
        return 'false' !== $node->getAttribute($attribute);
    }

Usage Example

Example #1
0
 protected function fromXML(DOMElement $node)
 {
     $this->declaringNodeType = $node->getAttribute('declaringNodeType');
     $this->name = $node->getAttribute('name');
     $this->isAutoCreated = Helper::getBoolAttribute($node, 'isAutoCreated');
     $this->isMandatory = Helper::getBoolAttribute($node, 'mandatory');
     $this->isProtected = Helper::getBoolAttribute($node, 'isProtected');
     $this->onParentVersion = \PHPCR\Version\OnParentVersionAction::valueFromName($node->getAttribute('onParentVersion'));
 }
All Usage Examples Of Jackalope\Helper::getBoolAttribute