Skip to content

Commit

Permalink
Merge pull request #214 from marcelthole/refactor-striptags-filter
Browse files Browse the repository at this point in the history
Refactor StripTags filter to implement FlterInterface
  • Loading branch information
gsteel authored Jan 6, 2025
2 parents 8f75078 + c22c4ed commit 71e42cc
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 360 deletions.
11 changes: 11 additions & 0 deletions docs/book/v3/migration/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ The following methods have been removed:

The constructor now only accepts an associative array of [documented options](../standard-filters.md#stringtrim).

#### `StripTags`

The following methods have been removed:

- `getTagsAllowed`
- `setTagsAllowed`
- `getAttributesAllowed`
- `setAttributesAllowed`

The constructor now only accepts an associative array of [documented options](../standard-filters.md#striptags).

#### `ToNull`

The following methods have been removed:
Expand Down
25 changes: 13 additions & 12 deletions docs/book/v3/standard-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ The above will return `This contains`, with the rest being stripped.
example, this can be used to strip all markup except for links:

```php
$filter = new Laminas\Filter\StripTags(['allowTags' => 'a']);
$filter = new Laminas\Filter\StripTags(['allowTags' => ['a']]);

$input = "A text with <br/> a <a href='link.com'>link</a>";
print $filter->filter($input);
Expand All @@ -1205,8 +1205,8 @@ You can also strip all but an allowed set of attributes from a tag:

```php
$filter = new Laminas\Filter\StripTags([
'allowTags' => 'img',
'allowAttribs' => 'src',
'allowTags' => ['img'],
'allowAttribs' => ['src'],
]);

$input = "A text with <br/> a <img src='picture.com' width='100'>picture</img>";
Expand All @@ -1224,16 +1224,17 @@ will be an allowed tag, pointing to a list of allowed attributes for that
tag.

```php
$allowedElements = [
'img' => [
'src',
'width'
],
'a' => [
'href'
$filter = new Laminas\Filter\StripTags([
'allowTags' => [
'img' => [
'src',
'width'
],
'a' => [
'href'
]
]
];
$filter = new Laminas\Filter\StripTags($allowedElements);
]);

$input = "A text with <br/> a <img src='picture.com' width='100'>picture</img> click "
. "<a href='http://picture.com/laminas' id='hereId'>here</a>!";
Expand Down
31 changes: 0 additions & 31 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,29 +319,6 @@
<code><![CDATA[Module]]></code>
</UnusedClass>
</file>
<file src="src/StripTags.php">
<DeprecatedClass>
<code><![CDATA[AbstractFilter]]></code>
</DeprecatedClass>
<MixedArgument>
<code><![CDATA[$options['allowAttribs']]]></code>
<code><![CDATA[$options['allowTags']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$attribute]]></code>
<code><![CDATA[$element]]></code>
<code><![CDATA[$temp['allowAttribs']]]></code>
<code><![CDATA[$temp['allowComments']]]></code>
<code><![CDATA[$temp['allowTags']]]></code>
</MixedAssignment>
<PossiblyUndefinedVariable>
<code><![CDATA[$temp]]></code>
</PossiblyUndefinedVariable>
<RedundantConditionGivenDocblockType>
<code><![CDATA[is_array($options)]]></code>
<code><![CDATA[is_string($attribute)]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Word/SeparatorToCamelCase.php">
<MissingClosureParamType>
<code><![CDATA[$matches]]></code>
Expand Down Expand Up @@ -449,12 +426,4 @@
<code><![CDATA[$target]]></code>
</UnusedVariable>
</file>
<file src="test/StripTagsTest.php">
<MixedArgument>
<code><![CDATA[$filtered]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$filtered]]></code>
</MixedAssignment>
</file>
</files>
Loading

0 comments on commit 71e42cc

Please sign in to comment.