Download the PHP package mertyildiran/filter without Composer

On this page you can find all versions of the php package mertyildiran/filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package filter

Filter

Aims to help make filtering input to your Eloquent models easier.

Simplifies code like this:

class Address extends Model {
    public function setPostcodeAttribute($value) {
        $this->attributes['postcode'] = strtoupper(trim($value));
    }

    public function setCityAttribute($value) {
        $this->attributes['city'] = trim($value);
    }

    public function getCityAttribute($value) {
        return strtoupper($value);
    }
}

Into this:

class Address extends Model {
    use Filter\HasFilters

    protected $input = [
        'postcode' => 'upper|trim',
        'city' => 'trim'
    ];

    protected $output = [
        'city' => 'upper'
    ];
}

Can also be used standalone:

$clean = Filter::filter(['city' => 'London'], ['city' => 'trim|upper']);

Installation

Installable via composer:

"bcalik/filter": "dev-master",

Laravel 4

To use the model trait and service for Laravel 4, add the following lines to config/app.php:

'providers' => array(
    // ...
    'Filter\FilterServiceProvider',

'aliases' => array(
    // ...
    'Filter' => 'Filter\Facades\Filter',

Usage

Examples below use the Facade style (Filter::filter()) for brevity - standalone users should expand this to $filter->filter().

The standalone class is similar to Laravel's validator component:

$filtered = Filter::filter(['name' => 'Ross'], ['name' => 'trim']);
$value = Filter::filterOne('Ross', 'trim');

Rules are also constructed similarly to Validator:

Filter::filterOne('test', 'trim|upper');
Filter::filterOne('test...', 'rtrim:.');
Filter::filterOne('test', ['trim', 'upper']);

Filters are run sequentially from left to right. Arguments are parsed by str_getcsv - e.g. to trim commas use trim:",".

Registering filters

A filter is a callable that accepts the input string and an array of arguments:

Filter::registerFilter('slugify', function($str, array $args) {
    return preg_replace('/[^a-z0-9]+/', '-', strtolower($str));
});

Other callable values are classes that define an __invoke method and function names. For example, Zend Framework's filters all implement __invoke, so 'Zend\I18n\Filter\Alnum' is a valid callable.

Filters can be unregistered using Filter::unregisterFilter('slugify').

Default filters

By default the following filters are registered:

trim        trim($str)
trim:|,/    trim($str, '|/');
ltrim       ltrim($str)
ltrim:|,/   ltrim($str, '|/');
rtrim       rtrim($str)
rtrim:|,/   rtrim($str, '|/');
upper       strtoupper($str)
lower       strtolower($str)
capfirst    ucfirst($str)
lowerfirst  lcfirst($str)
slug        Str::slug($str)
null        empty($str) ? null : $str

Laravel 4

A trait, HasFilters is available that modifies getAttribute (accessor) and setAttribute (mutator) to apply filters to the input or output value.

These filter rules are specified in properties on the model, $input and $output for mutators and accessors respectively.

class Address extends Model {
    use Filter\HasFilters;

    public $fillable = ['line1', 'line2', 'line3', 'city', 'postcode'];
    public $input = [
        'line1' => 'trim',
        'line2' => 'trim',
        'line3' => 'trim',
        'city' => 'trim',
        'postcode' => 'upper|trim',
    ];
    public $output = [
        'city' => 'upper', // Uppercase only for display
    ];
}

The filter instance is available using App::make('filter'), or via the facade Filter depending on your setup in config/app.php.

Call chain

You can still write your own accessors or mutators which will be applied as well as any filters that have been set. The following chains happen:

You should not need to modify your mutators (they should still store the value in $this->attributes[$name].

License

Released under the MIT license.


All versions of filter with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version 4.2.*
illuminate/container Version 4.2.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mertyildiran/filter contains the following files

Loading the files please wait ....