Download the PHP package hdgarau/logic-gate without Composer

On this page you can find all versions of the php package hdgarau/logic-gate. 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 logic-gate

logic-gate

Description:

With LogicGate you can define an evaluable-logic-tree then evaluate a value or filter an array. This could be useful when you need to do one or more complex filters. A LogicRoot object has one o more LogicGate (or any object that implements iEvaluable interface, even another LogicRoot object) objects. You can evaluate a single LogicGate object too.

Use:

LogicGate Operators

There are ford operators allowed:

Examples

//Using '!='
$gate1 = new LogicGate(4,LogicGate::OP_NOT . LogicGate::OP_EQ);
$gate1->test(1); //true
$gate1->test(4); //false

//Using '>' in a array
$gate2 = new LogicGate(18,LogicGate::OP_GT);
$arr_filtered = $gate2->filter([21,3,33]); // [0=>21,2=>33]

//Using a function
//the function must have two arguments:
// - the value to check
// - value of gate
$fx = function($val, $ref) { return $val->prop1 == $ref;};
$gate3 = new LogicGate(5,$fx);
$gate3->test((object)['prop1'=>5]); //true

How to use

Using 'add' methods

That is the best way for a healthy order and to do some branches with some different conditions.
You can add a LogicGate or a LogicGateRoot (or any class that implement iIsEvaluable)

Example

 //two-digit number greater than 45 or one-digit number greater than five       
        $gatesRoot = new LogicGatesRoot();
        $gatesRoot->addAND (new LogicGate('^\\d\\d$', LogicGate::OP_REGEX));
        $gatesRoot->addAND (new LogicGate(45, LogicGate::OP_GT));
        $gatesRoot->addOR(new LogicGate(5, LogicGate::OP_GT));
        $gatesRoot->addAND(new LogicGate('^\\d$', LogicGate::OP_REGEX));
        $gatesRoot->filter([11,8,178,88,97]); //[1=>8,3=>88,4=>97]

        $gatesRoot2 = new LogicGatesRoot();
        $gatesRoot2->addAND (new LogicGate('^8', LogicGate::OP_REGEX));
        $gatesRoot2->addAND ($gatesRoot);
        $gatesRoot2->filter([11,8,178,88,97]); //[1=>8,3=>88]

Using an array

If you have an array with conditions you can make the tree using it.
The keys are:

Example

 $fx = function ($el, $ref) { return $el %2 ==0;};
        $arr = [
            ['value' => '^\\d+$', 'next_gate' => 'AND'] ,
            ['operator' => $fx, 'value' => null, 'next_gate' => 'OR'] ,
            ['operator' => LogicGate::OP_GT, 'value' => 60, 'next_gate' => 'anything']
        ];
        $gate = new LogicGatesRoot($arr);
        $gate->test(61);//true
        $gate->test(6);//true
        $gate->test(57);//false

Using an string

the minimalist mode to make a complex tree is with a strong query.

The rules are:

Example


        //(~:"2$" OR ~:"comodin) AND (~:"1" OR =:"comodin21") AND !=:"comodin12"
        //(finish with two or contains "comodin") and (contains 1 OR is equal "comodin21")
        $lg = new LogicGatesRoot('(' . LogicGate::OP_REGEX . ':"2$" OR ' . LogicGate::OP_REGEX . ':"comodin") '.
            'AND (' . LogicGate::OP_REGEX . ':"1" OR ' . LogicGate::OP_EQ . ':"comodin23") AND '
            . LogicGate::OP_NOT .  LogicGate::OP_EQ . ':"comodin211"');

        $lg->test('comodin21'); //true
        $lg->test('comodin22'); //false
        $lg->test('comodin12'); //false
        $lg->test('comodin103'); //true
        $lg->test('12'); //true
        $lg->test('comodin211'); //false

Examples


All versions of logic-gate with dependencies

PHP Build Version
Package Version
Requires hdgarau/common Version ^1.0
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 hdgarau/logic-gate contains the following files

Loading the files please wait ....