Skip to content

A filtering implementation for verifying correct data and performing typical modifications to strings.

License

Notifications You must be signed in to change notification settings

jncarver/filter-strings-php

 
 

Repository files navigation

filter-strings-php

Build Status Scrutinizer Code Quality Coverage Status

Latest Stable Version Latest Unstable Version License

Total Downloads Daily Downloads Monthly Downloads

A filtering implementation for verifying the contents of strings and some common formats of strings.

Requirements

Requires PHP 7.0 or newer and uses composer to install further PHP dependencies. See the composer specification for more details.

Installation

filter-strings-php can be installed for use in your project using composer. The recommended way of using this library in your project is to add a composer.json file to your project. The following contents would add filter-strings-php as a dependency:

composer require traderinteractive/filter-strings

Functionality

Strings::filter

This filter verifies that the argument is a string. The second parameter can be set to true to allow null values through without an error (they will stay null and not get converted to false). The last parameters specify the length bounds of the string. The default bounds are 1+, so an empty string fails by default.

The following checks that $value is a non-empty string.

\TraderInteractive\Filter\Strings::filter($value);

Strings::concat

This filter concatenates the given $value, $prefix and $suffix and returns the resulting string.

$value = \TraderInteractive\Filter\Strings::concat('middle', 'begining_', '_end');
assert($value === 'begining_middle_end');

Strings::translate

This filter will accept a string value and return its translated value found in the given $valueMap.

$value = \TraderInteractive\Filter\Strings::translate('active', ['inactive' => 'X', 'active' => 'A']);
assert($value === 'A');

Strings::explode

This filter is essentially a wrapper around the built-in explode method with the value first in order to work with the Filterer. It also defaults to using , as a delimiter. For example:

$value = \TraderInteractive\Filter\Strings::explode('abc,def,ghi');
assert($value === ['abc', 'def', 'ghi']);

Url::filter

This filter verifies that the argument is a URL string according to RFC2396. The second parameter can be set to true to allow null values through without an error (they will stay null and not get converted to false).

The following checks that $value is a URL.

\TraderInteractive\Filter\Url::filter($value);

Email::filter

This filter verifies that the argument is an email.

The following checks that $value is an email.

\TraderInteractive\Filter\Email::filter($value);

Contact

Developers may be contacted at:

Project Build

With a checkout of the code get Composer in your PATH and run:

./vendor/bin/phpcs
./vendor/bin/phpunit

For more information on our build process, read through out our Contribution Guidelines.

About

A filtering implementation for verifying correct data and performing typical modifications to strings.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%