Download the PHP package eftec/minilang without Composer

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

MiniLang

This library is used to store business logic in a simple and yet powerful definition.

A mini script language for PHP. It does three simple tasks.

  1. (optional) It set some initial values (INIT).
  2. It evaluates a logic expression (WHERE).
  3. If the expression (logic) is true then it executes the SET expression (SET), so we could change the value of a variable, call a function and task like that.
  4. (optional) If the expression (logic) is false then it executes the ELSE expression (INIT).

For example :

Packagist Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

Why we need a mini script?

Sometimes we need to execute arbitrary code in the basis of "if some value equals to, then we set or execute another code."

In PHP, we could do the next code.

However, this code is executed at runtime. What if we need to execute this code at some specific point?.

We could do the next code:

This solution works (and it only executes if we call the command eval). But it is verbose, prone to error, and it's dangerous.

Our library does the same but safe and clean.

Table of Content

Getting started

Installing it using composer:

composer requires eftec/minilang

Creating a new project

Another example:

Methods

Constructor

__construct(&$caller,&$dict,array $specialCom=[],$areaName=[],$serviceClass=null)

reset()

It reset the previous definitions but the variables, service and areas.

setCaller(&$caller)

Set a caller object. The caller object it could be a service class with method that they could be called inside the script.

setDict(&$dict)

Set a dictionary with the variables used by the system.

function separate($miniScript)

It sends an expression to the MiniLang, and it is decomposed in its parts. The script is not executed but parsed.

evalLogic($index)

It evaluates a logic. It returns true or false.

evalAllLogic($stopOnFound = true, $start = false)

evalSet($idx = 0, $position = 'set')

It sets a value or values. It does not consider if WHERE is true or not.

Fields

$throwError

Boolean.

$errorLog

Array of String. if $throwError is false then every error is stored here.

Example:

Definition

Sintaxis.

The syntaxis of the code is separated into four parts. INIT, WHERE (or when), SET (or THEN) and ELSE.

Example:

It says if field1=1 then we set field2 as 2.

Variables

A variable is defined by varname

Example: examples/examplevariable.php

Variables defined by a PHP Object

A variable could host a PHP object, and it is possible to call and to access the fields inside it.

varname.field

Example of code examples/examplevariable2.php

Variables defined by a PHP array

A variable could hold an associative/index array, and it is possible to read and to access the elements inside it.

Example:

Example of code examples/examplevariable_arr.php

Global variables

A global variable takes the values of the PHP ($GLOBAL), so it doesn't need to be defined or set inside the language

Note: For security purpose. global variables defined by PHP as "$_namevar" can't be read or modified. So if you want to protect a global variable, then you can rename it with an underscore as prefix.
Example: If you try to read the variable $_SERVER, then it will return the value of the variable $SERVER which it could be or not defined.

A global variable is defined by

$globalname

Example:

$globalname=30

Example Code: examples/exampleglobal.php

Literals

Type Example
Number 20
string "hello world", 'hello world'
stringp "my name is {{var}}"
function namefunction(arg,arg)

Examples

set var=20 and var2="hello" and var3="hello {{var}}" and var4=fn()

Reserved methods

Reserved word Explanation
null() null value
false() false value
true() true value
on() 1
param(var,'l1.l2.l3') Separates an array (var) into var['l1']['l2']['l3']
off() 0
undef() -1 (for undefined)
flip() (special value). It inverts a value ON<->OFF
Used as value=flip()
now() returns the current timestamp (integer)
timer() returns the current timestamp (integer)
interval() returns the interval (in seconds) between the last change and now. It uses the field dateLastChange or method dateLastChange() of the callback class
fullinterval() returns the interval (in seconds) between the start of the process and now. It uses the field dateInit or method dateInit() of the callback class
contains()/str_contains() returns true if the text is contained in another text.Example: str_contains(field1,'hi')
str_starts_with(), startwith() returns true if the text starts with another text
str_ends_with(),endwith() returns true if the text ends with another text.

Example: examples/examplereserved.php

Example Timer: examples/examplereservedtimer.php

init

This part of the expression allows setting a value. This expression is usually optional, and it could be omitted.

It is similar to SET, but it is executed before WHERE and no matter if WHERE is valid or not.

init counter=20 where variable1=20 set variable+counter

Code:

where

This part of the expression adds a condition to the statement.

We can also use "when."

where expression

or

when expression

It's possible to compare more than a condition at the same time by separating by "and" or "or."

where v1=10 and v2=20 or v3<50

Example

where variable1=20 and $variable2=variable3 or function(20)=40

where $field=20 and field2<>40 or field3=40 // sql syntax

where $field==20 && field2!=40 || field3=+40 // PHP syntax

where 1 // it always true

Logical expressions allowed

set

This part of the expression allows setting the value of a variable. It is possible to set more than one variable at the same time by separating by "," or "and."

We can also use the expression "set" or "then"

set expression

or

then expression

This part of the expression is only executed if WHERE is valid

Setting expressions allowed

We could set a variable using the next expressions:

This library does not allow complex instruction such as

Example:

set variable1=20 and $variable2=variable3 and function(20)=40

Code:

else

This optional part of the expression allows setting the value of a variable. It is possible to set more than one variable at the same time by separating by "," or "and".

This code is only evaluated if "where" returns false of if ELSE is called manually.

Example

else variable1=20 and $variable2=variable3 and function(20)=40

Loop

It is possible to create a loop using the space "loop"

To start a loop, you must write

And to end the loop, you must use

You can escape the loop using the operator "break" in the "set" or "else".

Note: Loops are only evaluated when you evaluate all the logic. It does not work with evalLogic() and evalLogic2()

Note: You can't add a condition to a loop, however you can skip a loop assigning an empty array

Example:

Compiling the logic into a PHP class

It is possible to create a class with the logic created in the language. The goal is to increase the performance of the code.

Creating the class

To generate the class, first we need to write the logic using the method separate2() instead of separate(). It will store the logic inside an array of the instance of the class. You could use the code directly, or you could save inside a class as follows:

It will save a new file called 📄 ExampleBasicClass.php (you can check the example 📁 [example/genclass/1.examplebasic.php]())

Using the class

With the class generated, you can use this new class instead of MiniLang. Since this class is already compiled, then it is blazing fast. However, if you need to change the logic, then you will need to compile it again. (you can check the example 📁 [example/genclass/2.examplebasic.php]() and 📁 [example/genclass/ExampleBasicClass.php]())

The class will look like:

Where each method evaluates a part of the expression.

Benchmark

examples/examplebenchmark.php

We call some operations 1000 times.

(reset+separate+evalAllLogic) x 1000

evalAllLogic x 1000

(reset+separate2+evalAllLogic2) x 1000

(evalAllLogic2) x 1000

PHP method of class x 1000

Documentation

Medium-Creating a new scripting language on PHP

To-do

Version


All versions of minilang with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-ctype Version *
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 eftec/minilang contains the following files

Loading the files please wait ....