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

Merge release 2.40.0 into 3.0.x #219

Merged
merged 39 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
773d73c
Update to latest PHP 8.1 syntax
samsonasik Nov 2, 2024
af7e298
Fix @param to be int as error is int
samsonasik Nov 2, 2024
d78eebc
Fix possibly false value on errorString parameter
samsonasik Nov 2, 2024
b7ae47f
Fix psalm mixed param override
samsonasik Nov 2, 2024
a7e47b5
regenerate psalm baseline
samsonasik Nov 2, 2024
f9894b7
Merge pull request #190 from samsonasik/update-to-php81-syntax
gsteel Nov 3, 2024
0606624
Update to latest PHPUnit 10 syntax
samsonasik Nov 4, 2024
56e3088
Regenerate psalm-baseline.xml
samsonasik Nov 4, 2024
391533b
Lock file maintenance
renovate[bot] Nov 4, 2024
e4a7fd0
Merge pull request #191 from samsonasik/update-to-latest-phpunit-syntax
gsteel Nov 4, 2024
cb7b293
Lock file maintenance
renovate[bot] Nov 11, 2024
2bca808
Apply one line per sentence style to md files
ramchale Nov 15, 2024
cc7715e
Lock file maintenance
renovate[bot] Nov 18, 2024
294a99c
Merge pull request #199 from ramchale/docs-one-line-per-sentence
gsteel Nov 19, 2024
70bcaad
Lock file maintenance
renovate[bot] Nov 25, 2024
07ca38d
Lock file maintenance
renovate[bot] Dec 2, 2024
37164ae
Deprecate legacy compression related adapters and filter
gsteel Dec 4, 2024
00d2e35
Merge pull request #203 from gsteel/v2/deprecate-compression-filters
gsteel Dec 4, 2024
ce73e75
Deprecate `FilterProviderInterface`
gsteel Dec 4, 2024
4a314bc
Deprecate legacy module manager affordances
gsteel Dec 4, 2024
38e4d81
Lock file maintenance
renovate[bot] Dec 9, 2024
ce84155
Merge pull request #206 from laminas/renovate/lock-file-maintenance
gsteel Dec 9, 2024
51e83ce
Lock file maintenance
renovate[bot] Dec 16, 2024
116f9f5
Filter Chain Deprecations
gsteel Dec 17, 2024
79c4e9a
`SeparatorToSeparator` Deprecations
gsteel Dec 17, 2024
b32782d
Merge pull request #210 from gsteel/v2/filter-chain-deprecations
gsteel Dec 18, 2024
4cde1b3
Merge pull request #211 from gsteel/v2/sep-to-sep-deprecations
gsteel Dec 18, 2024
bc22c88
Lock file maintenance
renovate[bot] Dec 23, 2024
e259649
Lock file maintenance
renovate[bot] Dec 30, 2024
cd015e4
StripTags filter deprecations
gsteel Jan 4, 2025
bdf5d8a
Lock file maintenance
renovate[bot] Jan 6, 2025
08b6721
Refactor RenameTest
ramchale Dec 21, 2024
1a4194e
Merge pull request #212 from ramchale/RenameTest
gsteel Jan 6, 2025
731e4d2
Merge pull request #217 from gsteel/v2/strip-tags-deprecations
gsteel Jan 6, 2025
f9e9083
Merge pull request #204 from gsteel/v2/deprecate-filter-provider-inte…
gsteel Jan 6, 2025
08aad80
Deprecate getters and setters in the `HtmlEntities` filter
gsteel Jan 6, 2025
9b32ba7
Merge pull request #218 from gsteel/v2/htmlentities-deprecations
gsteel Jan 6, 2025
c92d299
Merge remote-tracking branch 'upstream/3.0.x' into 2.40.x-merge-up-in…
gsteel Jan 6, 2025
84cb2a8
Refresh baseline and php deps post merge-up
gsteel Jan 6, 2025
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"laminas/laminas-coding-standard": "^3.0.1",
"laminas/laminas-diactoros": "^3.5",
"pear/archive_tar": "^1.5.0",
"pear/pear": "^1.10.15",
"phpunit/phpunit": "^10.5.38",
"pear/pear": "^1.10.16",
"phpunit/phpunit": "^10.5.40",
"psalm/plugin-phpunit": "^0.19.0",
"psr/http-factory": "^1.1.0",
"vimeo/psalm": "^5.26.1"
Expand Down
237 changes: 118 additions & 119 deletions composer.lock

Large diffs are not rendered by default.

122 changes: 43 additions & 79 deletions docs/book/v2/file.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# File Filters

laminas-filter also comes with a set of classes for filtering file contents, and
performing file operations such as renaming.
laminas-filter also comes with a set of classes for filtering file contents, and performing file operations such as renaming.

> ## $_FILES
>
> All file filter `filter()` implementations support either a file path string
> *or* a `$_FILES` array as the supplied argument. When a `$_FILES` array is
> passed in, the `tmp_name` is used for the file path.
> All file filter `filter()` implementations support either a file path string *or* a `$_FILES` array as the supplied argument.
> When a `$_FILES` array is passed in, the `tmp_name` is used for the file path.

## Encrypt and Decrypt

These filters allow encrypting and decrypting file contents, and are derived
from the `Laminas\Filter\Encrypt` and `Laminas\Filter\Decrypt` filters. Only file reading and
writing operations are performed by the filer; encryption and decryption operations
are performed by the parent classes.
These filters allow encrypting and decrypting file contents, and are derived from the `Laminas\Filter\Encrypt` and `Laminas\Filter\Decrypt` filters.
Only file reading and writing operations are performed by the filer; encryption and decryption operations are performed by the parent classes.

Usage:

Expand All @@ -33,8 +29,8 @@ $filter = new EncryptFileFilter([
$filter->filter($files['my-upload']);
```

In the above example, we pass options to our constructor in order to configure
the filter. We could instead use use setter methods to inject these options:
In the above example, we pass options to our constructor in order to configure the filter.
We could instead use use setter methods to inject these options:

```php
use Laminas\Filter\File\Encrypt as EncryptFileFilter;
Expand All @@ -55,8 +51,7 @@ for more information about options and adapters.

## Lowercase

`Laminas\Filter\File\Lowercase` can be used to convert all file contents to
lowercase.
`Laminas\Filter\File\Lowercase` can be used to convert all file contents to lowercase.

### Supported Options

Expand All @@ -78,13 +73,10 @@ $filter = new LowerCase();
$filter->filter($files['my-upload']);
```

This example converts the contents of an uploaded file to lowercase. After this
process, you can use the [Rename](#rename) or [RenameUpload](#renameupload)
filter to replace this file with your original file, or read directly from file.
But, don't forget, if you upload a file and send your `$_FILES` array to a
filter method, the `LowerCase` filter will only change the temporary file
(`tmp_name` index of array), not the original file. Let's check following
example:
This example converts the contents of an uploaded file to lowercase.
After this process, you can use the [Rename](#rename) or [RenameUpload](#renameupload) filter to replace this file with your original file, or read directly from file.
But, don't forget, if you upload a file and send your `$_FILES` array to a filter method, the `LowerCase` filter will only change the temporary file (`tmp_name` index of array), not the original file.
Let's check following example:

```php
use Laminas\Filter\File\LowerCase;
Expand All @@ -104,12 +96,9 @@ $renameFilter = new Rename([
$filename = $renameFilter->filter($file['tmp_name']);
```

With this example, the final, stored file on the server will have the lowercased
content.
With this example, the final, stored file on the server will have the lowercased content.

If you want to use a specific encoding when converting file content, you should
specify the encoding when instantiating the `LowerCase` filter, or use the
`setEncoding` method to change it.
If you want to use a specific encoding when converting file content, you should specify the encoding when instantiating the `LowerCase` filter, or use the `setEncoding` method to change it.

```php
use Laminas\Filter\File\LowerCase;
Expand All @@ -136,21 +125,16 @@ for more information about encoding and its exceptions.

The following set of options are supported:

- `target` (string; default: `*`): Target filename or directory; the new name
of the source file.
- `source` (string; default: `*`): Source filename or directory which will be
renamed. Used to match the filtered file with an options set.
- `target` (string; default: `*`): Target filename or directory; the new name of the source file.
- `source` (string; default: `*`): Source filename or directory which will be renamed.
Used to match the filtered file with an options set.
- `overwrite` (boolean; default: `false`): Shall existing files be overwritten?
If the file is unable to be moved into the target path, a
`Laminas\Filter\Exception\RuntimeException` will be thrown.
- `randomize` (boolean; default: `false`): Shall target files have a random
postfix attached? The random postfix will generated with `uniqid('_')` after
the file name and before the extension. For example, `file.txt` might be
randomized to `file_4b3403665fea6.txt`.
- If the file is unable to be moved into the target path, a `Laminas\Filter\Exception\RuntimeException` will be thrown.
- `randomize` (boolean; default: `false`): Shall target files have a random postfix attached? The random postfix will generated with `uniqid('_')` after the file name and before the extension.
For example, `file.txt` might be randomized to `file_4b3403665fea6.txt`.

An array of option sets is also supported, where a single `Rename` filter
instance can filter several files using different options. The options used for
the filtered file will be matched from the `source` option in the options set.
An array of option sets is also supported, where a single `Rename` filter instance can filter several files using different options.
The options used for the filtered file will be matched from the `source` option in the options set.

### Usage Examples

Expand Down Expand Up @@ -224,40 +208,28 @@ The following set of options are supported:

- `target` (string; default: `*`): Target directory or full filename path.
- `overwrite` (boolean; default: `false`): Shall existing files be overwritten?
If the file is unable to be moved into the target path, a
`Laminas\Filter\Exception\RuntimeException` will be thrown.
- `randomize` (boolean; default: `false`): Shall target files have a random
postfix attached? The random postfix will generated with `uniqid('_')` after
the file name and before the extension. For example, `file.txt` might be
randomized to `file_4b3403665fea6.txt`.
- `use_upload_name` (boolean; default: `false`): When true, this filter will
use `$_FILES['name']` as the target filename. Otherwise, the default `target`
rules and the `$_FILES['tmp_name']` will be used.
- `use_upload_extension` (boolean; default: `false`): When true, the uploaded
file will maintains its original extension if not specified. For example, if
the uploaded file is `file.txt` and the target is `mynewfile`, the upload
will be renamed to `mynewfile.txt`.
If the file is unable to be moved into the target path, a `Laminas\Filter\Exception\RuntimeException` will be thrown.
- `randomize` (boolean; default: `false`): Shall target files have a random postfix attached? The random postfix will generated with `uniqid('_')` after the file name and before the extension.
For example, `file.txt` might be randomized to `file_4b3403665fea6.txt`.
- `use_upload_name` (boolean; default: `false`): When true, this filter will use `$_FILES['name']` as the target filename.
Otherwise, the default `target` rules and the `$_FILES['tmp_name']` will be used.
- `use_upload_extension` (boolean; default: `false`): When true, the uploaded file will maintains its original extension if not specified.
For example, if the uploaded file is `file.txt` and the target is `mynewfile`, the upload will be renamed to `mynewfile.txt`.
- `stream_factory` (`Psr\Http\Message\StreamFactoryInterface`; default: `null`):
Required when passing a [PSR-7 UploadedFileInterface](https://www.php-fig.org/psr/psr-7/#36-psrhttpmessageuploadedfileinterface)
to the filter; used to create a new stream representing the renamed file.
(Since 2.9.0)
- `upload_file_factory` (`Psr\Http\Message\UploadedFileFactoryInterface`; default:
`null`): Required when passing a [PSR-7 UploadedFileInterface](https://www.php-fig.org/psr/psr-7/#36-psrhttpmessageuploadedfileinterface)
to the filter; used to create a new uploaded file representation of the
renamed file. (Since 2.9.0)
Required when passing a [PSR-7 UploadedFileInterface](https://www.php-fig.org/psr/psr-7/#36-psrhttpmessageuploadedfileinterface) to the filter; used to create a new stream representing the renamed file.
(Since 2.9.0)
- `upload_file_factory` (`Psr\Http\Message\UploadedFileFactoryInterface`; default: `null`): Required when passing a [PSR-7 UploadedFileInterface](https://www.php-fig.org/psr/psr-7/#36-psrhttpmessageuploadedfileinterface) to the filter; used to create a new uploaded file representation of the renamed file.
(Since 2.9.0)

> ### Using the upload Name is unsafe
>
> Be **very** careful when using the `use_upload_name` option. For instance,
> extremely bad things could happen if you were to allow uploaded `.php` files
> (or other CGI files) to be moved into the `DocumentRoot`.
> Be **very** careful when using the `use_upload_name` option.
> For instance, extremely bad things could happen if you were to allow uploaded `.php` files (or other CGI files) to be moved into the `DocumentRoot`.
>
> It is generally a better idea to supply an internal filename to avoid
> security risks.
> It is generally a better idea to supply an internal filename to avoid security risks.

`RenameUpload` does not support an array of options like the`Rename` filter.
When filtering HTML5 file uploads with the `multiple` attribute set, all files
will be filtered with the same option settings.
When filtering HTML5 file uploads with the `multiple` attribute set, all files will be filtered with the same option settings.

### Usage Examples

Expand Down Expand Up @@ -343,23 +315,16 @@ foreach ($request->getUploadedFiles() as $uploadedFile) {

> ### PSR-7 Support
>
> PSR-7/PSR-17 support has only been available since 2.9.0, and requires a valid
> [psr/http-factory-implementation](https://packagist.org/providers/psr/http-factory-implementation)
> in your application, as it relies on the stream and uploaded file factories in
> order to produce the final `UploadedFileInterface` artifact representing the
> filtered file.
> PSR-7/PSR-17 support has only been available since 2.9.0, and requires a valid [psr/http-factory-implementation](https://packagist.org/providers/psr/http-factory-implementation) in your application, as it relies on the stream and uploaded file factories in order to produce the final `UploadedFileInterface` artifact representing the filtered file.
>
> PSR-17 itself requires PHP 7, so your application will need to be running on
> PHP 7 in order to use this feature.
> PSR-17 itself requires PHP 7, so your application will need to be running on PHP 7 in order to use this feature.
>
> [laminas/laminas-diactoros 2.0](https://docs.laminas.dev/laminas-diactoros/)
> provides a PSR-17 implementation, but requires PHP 7.1. If you are still on
> PHP 7.0, either upgrade, or find a compatible psr/http-factory-implementation.
> [laminas/laminas-diactoros 2.0](https://docs.laminas.dev/laminas-diactoros/) provides a PSR-17 implementation, but requires PHP 7.1.
> If you are still on PHP 7.0, either upgrade, or find a compatible psr/http-factory-implementation.

## Uppercase

`Laminas\Filter\File\Uppercase` can be used to convert all file contents to
uppercase.
`Laminas\Filter\File\Uppercase` can be used to convert all file contents to uppercase.

### Supported Options

Expand All @@ -381,5 +346,4 @@ $filter = new UpperCase();
$filter->filter($files['my-upload']);
```

See the documentation on the [`LowerCase`](#lowercase) filter, above, for more
information.
See the documentation on the [`LowerCase`](#lowercase) filter, above, for more information.
37 changes: 16 additions & 21 deletions docs/book/v2/filter-chains.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Filter Chains

Often, multiple filters should be applied to some value in a particular order.
For example, a login form accepts a username that should be lowercase and
contain only alphabetic characters.
For example, a login form accepts a username that should be lowercase and contain only alphabetic characters.

`Laminas\Filter\FilterChain` provides a simple method by which filters may be
chained together. The following code illustrates how to chain together two
filters for the submitted username and fulfill the above requirements:
`Laminas\Filter\FilterChain` provides a simple method by which filters may be chained together.
The following code illustrates how to chain together two filters for the submitted username and fulfill the above requirements:

```php
// Create a filter chain and add filters to the chain
Expand All @@ -19,21 +17,18 @@ $filterChain
$username = $filterChain->filter($_POST['username']);
```

Filters are run in the order they are added to the filter chain. In the above
example, the username is first removed of any non-alphabetic characters, and
then any uppercase characters are converted to lowercase.
Filters are run in the order they are added to the filter chain.
In the above example, the username is first removed of any non-alphabetic characters, and then any uppercase characters are converted to lowercase.

Any object that implements `Laminas\Filter\FilterInterface` may be used in a
filter chain.
Any object that implements `Laminas\Filter\FilterInterface` may be used in a filter chain.

## Setting Filter Chain Order

For each filter added to the `FilterChain`, you can set a priority to define
the chain order. Higher values indicate higher priority (execute first), while
lower and/or negative values indicate lower priority (execute last). The default value is `1000`.
For each filter added to the `FilterChain`, you can set a priority to define the chain order.
Higher values indicate higher priority (execute first), while lower and/or negative values indicate lower priority (execute last).
The default value is `1000`.

In the following example, any uppercase characters are converted to lowercase
before any non-alphabetic characters are removed.
In the following example, any uppercase characters are converted to lowercase before any non-alphabetic characters are removed.

```php
// Create a filter chain and add filters to the chain
Expand All @@ -45,13 +40,13 @@ $filterChain

## Using the Plugin Manager

A `FilterPluginManager` is attached to every `FilterChain` instance. Every filter
that is used in a `FilterChain` must be known to the `FilterPluginManager`.
A `FilterPluginManager` is attached to every `FilterChain` instance.
Every filter that is used in a `FilterChain` must be known to the `FilterPluginManager`.

To add a filter to the `FilterChain`, use the `attachByName()` method. The
first parameter is the name of the filter within the `FilterPluginManager`. The
second parameter takes any options for creating the filter instance. The third
parameter is the priority.
To add a filter to the `FilterChain`, use the `attachByName()` method.
The first parameter is the name of the filter within the `FilterPluginManager`.
The second parameter takes any options for creating the filter instance.
The third parameter is the priority.

```php
// Create a filter chain and add filters to the chain
Expand Down
Loading
Loading