Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor StripTags filter to implement FlterInterface #214

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading