laminas / laminas-filter

Programmatically filter and normalize data and files
https://docs.laminas.dev/laminas-filter/
BSD 3-Clause "New" or "Revised" License
85 stars 35 forks source link

Filter for arithmetic operations #28

Open fgsl opened 3 years ago

fgsl commented 3 years ago

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

I created this filter for an application that converts values from APIs. It's useful for measure unit conversions and making adjustments. For example, an endpoint returns the amount of RAM requested by an user and you can add a security margin.

fgsl commented 3 years ago

https://github.com/laminas/laminas-filter/pull/29

fgsl commented 3 years ago

Hi, @froschdesign. Where can I put documentation about this?

Tell me if something like this is enough.

Some value is given in meters but I want the value in kilometers. Think that value is given by an API that has no option for conversions. You don't have access a database to define the query.

Considering changes from your comments, I write a sample below:

require 'vendor/autoload.php';

use Laminas\Filter\FiveOperations;

$filter = new FiveOperations((['operation' => FiveOperations::DIV, 'value' => 1000]);

$distanceInMeters = 15450; 

$distanceInKilometers = $filter->filter($distanceInMeters);

// $distanceInKilometers = 15.45