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 htmlentities filter #215

Merged
merged 2 commits into from
Jan 8, 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
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).

#### `Inflector`

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
gsteel marked this conversation as resolved.
Show resolved Hide resolved
`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/Module.php">
<UnusedClass>
<code><![CDATA[Module]]></code>
Expand Down Expand Up @@ -279,25 +240,4 @@
<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>
</files>
Loading
Loading