Skip to content

Commit

Permalink
Revert changes to documentation
Browse files Browse the repository at this point in the history
Instead of altering docs for the v2 series, new docs must be created and amended for the v3 series

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed May 17, 2023
1 parent d48c2be commit 7c7e4aa
Show file tree
Hide file tree
Showing 4 changed files with 582 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/book/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,50 @@ performing file operations such as renaming.
> *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.

Usage:

```php
use Laminas\Filter\File\Encrypt as EncryptFileFilter;
use Laminas\Http\PhpEnvironment\Request;

$request = new Request();
$files = $request->getFiles();
// i.e. $files['my-upload']['tmp_name'] === '/tmp/php5Wx0aJ'

$filter = new EncryptFileFilter([
'adapter' => 'BlockCipher',
'key' => '--our-super-secret-key--',
]);
$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:

```php
use Laminas\Filter\File\Encrypt as EncryptFileFilter;
use Laminas\Http\PhpEnvironment\Request;

$request = new Request();
$files = $request->getFiles();
// i.e. $files['my-upload']['tmp_name'] === '/tmp/php5Wx0aJ'

$filter = new EncryptFileFilter();
$filter->setAdapter('BlockCipher');
$filter->setKey('--our-super-secret-key--');
$filter->filter($files['my-upload']);
```

Check the [Encrypt and Decrypt filter documentation](/laminas-filter/standard-filters/#encrypt-and-decrypt)
for more information about options and adapters.

## Lowercase

`Laminas\Filter\File\Lowercase` can be used to convert all file contents to
Expand Down
48 changes: 48 additions & 0 deletions docs/book/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,54 @@ echo $strtolower('I LOVE Laminas!'); // i love laminas!
$laminaslove = $strtolower('I LOVE Laminas!');
```

## Using the StaticFilter

If it is inconvenient to load a given filter class and create an instance of the
filter, you can use `StaticFilter` with its `execute()` method as an alternative
invocation style. The first argument of this method is a data input value, that
you would pass to the `filter()` method. The second argument is a string, which
corresponds to the basename of the filter class, relative to the `Laminas\Filter`
namespace. The `execute()` method automatically loads the class, creates an
instance, and applies the `filter()` method to the data input.

```php
echo StaticFilter::execute('&', 'HtmlEntities');
```

You can also pass an array of constructor arguments, if they are needed for the
filter class:

```php
echo StaticFilter::execute(
'"',
'HtmlEntities',
['quotestyle' => ENT_QUOTES]
);
```

The static usage can be convenient for invoking a filter ad hoc, but if you have
the need to run a filter for multiple inputs, it’s more efficient to follow the
first example above, creating an instance of the filter object and calling its
`filter()` method.

Also, the `FilterChain` class allows you to instantiate and run multiple filter
and validator classes on demand to process sets of input data. See the
[FilterChain](filter-chains.md) chapter for more details.

You can set and receive the `FilterPluginManager` for the `StaticFilter` to
amend the standard filter classes.

```php
$pluginManager = StaticFilter::getPluginManager()->setInvokableClass(
'myNewFilter',
'MyCustom\Filter\MyNewFilter'
);

StaticFilter::setPluginManager(new MyFilterPluginManager());
```

This is useful when adding custom filters to be used by the `StaticFilter`.

## Double filtering

When using two filters in succession, you have to keep in mind that it is
Expand Down
Loading

0 comments on commit 7c7e4aa

Please sign in to comment.