Skip to content

Commit

Permalink
Refactor HtmlEntities filter to implement FlterInterface
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Thole <[email protected]>
  • Loading branch information
marcelthole committed Jan 7, 2025
1 parent 8c66c54 commit 7bea300
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 366 deletions.
15 changes: 15 additions & 0 deletions docs/book/v3/migration/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ The following methods have been removed:

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

#### `HtmlEntities`

The following methods have been removed:

- `getQuoteStyle`
- `setQuoteStyle`
- `getEncoding`
- `setEncoding`
- `getCharSet`
- `setCharSet`
- `getDoubleQuote`
- `setDoubleQuote`

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

#### `MonthSelect`

The following methods have been removed:
Expand Down
50 changes: 3 additions & 47 deletions docs/book/v3/standard-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,24 +635,17 @@ entity equivalents when possible.
The following options are supported for `Laminas\Filter\HtmlEntities`:

- `quotestyle`: Equivalent to the PHP `htmlentities()` native function parameter
`quote_style`. This allows you to define what will be done with 'single' and
`flags`. This allows you to define what will be done with 'single' and
"double" quotes. The following constants are accepted: `ENT_COMPAT`,
`ENT_QUOTES`, and `ENT_NOQUOTES`, with the default being `ENT_COMPAT`.
- `charset`: Equivalent to the PHP `htmlentities()` native function parameter
`charset`. This defines the character set to be used in filtering. Unlike the
- `encoding`: Equivalent to the PHP `htmlentities()` native function parameter
`encoding`. This defines the character set to be used in filtering. Unlike the
PHP native function, the default is 'UTF-8'. See the [PHP htmlentities
manual](http://php.net/htmlentities) for a list of supported character sets.

This option can also be set via the `$options` parameter as a Traversable
object or array. The option key will be accepted as either `charset` or
`encoding`.
- `doublequote`: Equivalent to the PHP `htmlentities()` native function
parameter `double_encode`. If set to `false`, existing HTML entities will not
be encoded. The default is to convert everything (`true`).

This option must be set via the `$options` parameter or the
`setDoubleEncode()` method.

### Basic Usage

```php
Expand Down Expand Up @@ -696,43 +689,6 @@ print $filter->filter($input);
The above example returns `A 'single' and "double"`. Notice that neither
"double" or 'single' quotes are altered.

### Helper Methods

To change or retrieve the `quotestyle` after instantiation, the two methods
`setQuoteStyle()` and `getQuoteStyle()` may be used respectively.
`setQuoteStyle()` accepts one parameter, `$quoteStyle`, which accepts one of the
constants `ENT_COMPAT`, `ENT_QUOTES`, or `ENT_NOQUOTES`.

```php
$filter = new Laminas\Filter\HtmlEntities();

$filter->setQuoteStyle(ENT_QUOTES);
print $filter->getQuoteStyle(ENT_QUOTES);
```

To change or retrieve the `charset` after instantiation, the two methods
`setCharSet()` and `getCharSet()` may be used respectively. `setCharSet()`
accepts one parameter, `$charSet`. See the [PHP htmlentities manual
page](http://php.net/htmlentities) for a list of supported character sets.

```php
$filter = new Laminas\Filter\HtmlEntities();

$filter->setQuoteStyle(ENT_QUOTES);
print $filter->getQuoteStyle(ENT_QUOTES);
```

To change or retrieve the `doublequote` option after instantiation, the two methods
`setDoubleQuote()` and `getDoubleQuote()` may be used respectively. `setDoubleQuote()` accepts one
boolean parameter, `$doubleQuote`.

```php
$filter = new Laminas\Filter\HtmlEntities();

$filter->setQuoteStyle(ENT_QUOTES);
print $filter->getQuoteStyle(ENT_QUOTES);
```

## ToFloat

`Laminas\Filter\ToFloat` allows you to transform a scalar value into a float.
Expand Down
60 changes: 0 additions & 60 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,45 +179,6 @@
<code><![CDATA[(bool) $flag]]></code>
</RedundantCastGivenDocblockType>
</file>
<file src="src/HtmlEntities.php">
<DeprecatedClass>
<code><![CDATA[AbstractFilter]]></code>
</DeprecatedClass>
<DeprecatedMethod>
<code><![CDATA[getDoubleQuote]]></code>
<code><![CDATA[getDoubleQuote]]></code>
<code><![CDATA[getEncoding]]></code>
<code><![CDATA[getEncoding]]></code>
<code><![CDATA[getEncoding]]></code>
<code><![CDATA[getEncoding]]></code>
<code><![CDATA[getQuoteStyle]]></code>
<code><![CDATA[getQuoteStyle]]></code>
<code><![CDATA[setDoubleQuote]]></code>
<code><![CDATA[setEncoding]]></code>
<code><![CDATA[setEncoding]]></code>
<code><![CDATA[setQuoteStyle]]></code>
</DeprecatedMethod>
<DocblockTypeContradiction>
<code><![CDATA[is_array($options)]]></code>
</DocblockTypeContradiction>
<MixedArgument>
<code><![CDATA[$options['doublequote']]]></code>
<code><![CDATA[$options['encoding']]]></code>
<code><![CDATA[$options['quotestyle']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$options['encoding']]]></code>
<code><![CDATA[$temp['charset']]]></code>
<code><![CDATA[$temp['quotestyle']]]></code>
</MixedAssignment>
<PossiblyUndefinedVariable>
<code><![CDATA[$temp]]></code>
</PossiblyUndefinedVariable>
<RedundantCastGivenDocblockType>
<code><![CDATA[(bool) $doubleQuote]]></code>
<code><![CDATA[(string) $value]]></code>
</RedundantCastGivenDocblockType>
</file>
<file src="src/Inflector.php">
<ArgumentTypeCoercion>
<code><![CDATA[$options['pluginManager']]]></code>
Expand Down Expand Up @@ -372,27 +333,6 @@
<code><![CDATA[setService]]></code>
</DeprecatedMethod>
</file>
<file src="test/HtmlEntitiesTest.php">
<DeprecatedMethod>
<code><![CDATA[getCharSet]]></code>
<code><![CDATA[getCharSet]]></code>
<code><![CDATA[getDoubleQuote]]></code>
<code><![CDATA[getDoubleQuote]]></code>
<code><![CDATA[getEncoding]]></code>
<code><![CDATA[getQuoteStyle]]></code>
<code><![CDATA[getQuoteStyle]]></code>
<code><![CDATA[getQuoteStyle]]></code>
<code><![CDATA[setCharSet]]></code>
<code><![CDATA[setCharSet]]></code>
<code><![CDATA[setDoubleQuote]]></code>
<code><![CDATA[setDoubleQuote]]></code>
<code><![CDATA[setQuoteStyle]]></code>
<code><![CDATA[setQuoteStyle]]></code>
<code><![CDATA[setQuoteStyle]]></code>
<code><![CDATA[setQuoteStyle]]></code>
<code><![CDATA[setQuoteStyle]]></code>
</DeprecatedMethod>
</file>
<file src="test/InflectorTest.php">
<DocblockTypeContradiction>
<code><![CDATA[assertNull]]></code>
Expand Down
Loading

0 comments on commit 7bea300

Please sign in to comment.