PicoFeed\Filter\Attribute::filterIntegerAttribute PHP Méthode

filterIntegerAttribute() public méthode

Return true if the value is not integer (remove attributes that should have an integer value).
public filterIntegerAttribute ( string $tag, string $attribute, string $value ) : boolean
$tag string Tag name
$attribute string Attribute name
$value string Attribute value
Résultat boolean
    public function filterIntegerAttribute($tag, $attribute, $value)
    {
        if (in_array($attribute, $this->integer_attributes)) {
            return ctype_digit($value);
        }
        return true;
    }

Usage Example

 public function testFilterIntegerAttribute()
 {
     $filter = new Attribute(new Url('http://google.com'));
     $this->assertTrue($filter->filterIntegerAttribute('abbr', 'title', 'test'));
     $this->assertTrue($filter->filterIntegerAttribute('iframe', 'width', '0'));
     $this->assertTrue($filter->filterIntegerAttribute('iframe', 'width', '450'));
     $this->assertFalse($filter->filterIntegerAttribute('iframe', 'width', 'test'));
     $this->assertEquals(array('width' => '10', 'src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('width' => '10', 'src' => 'http://www.youtube.com/test')));
     $this->assertEquals(array('src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('width' => 'test', 'src' => 'http://www.youtube.com/test')));
 }