PHPackages                             smuuf/primi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. smuuf/primi

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

smuuf/primi
===========

A scripting language written in PHP &amp; executable within PHP.

0.4(6y ago)13273.7k↓23.6%16[2 PRs](https://github.com/smuuf/primi/pulls)MITPHPPHP &gt;=7.1

Since Oct 23Pushed 1y ago4 watchersCompare

[ Source](https://github.com/smuuf/primi)[ Packagist](https://packagist.org/packages/smuuf/primi)[ RSS](/packages/smuuf-primi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (31)Used By (0)

 [![Primi](https://raw.githubusercontent.com/smuuf/primi/master/res/art/logo-sml.png)](https://raw.githubusercontent.com/smuuf/primi/master/res/art/logo-sml.png)

Primi
=====

[](#primi)

A scripting language ***written in PHP*** &amp; ***interpreted in PHP***.

 Primi is meant for PHP developers who want to **allow their clients to write their own custom logic**. Primi allows you *(the developer)* to **execute untrusted code** *(provided simply as a string)* inside a sandbox, safely separated from its surroundings.

---

Code ClimatePackagist[![Maintainability](https://camo.githubusercontent.com/2bd1439cbfed6e2745f7e1e61a600b762b237be5b12f15bb773f8ca305f12f78/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62633364393436653332636333303832306363392f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/smuuf/primi/maintainability) [![Test Coverage](https://camo.githubusercontent.com/1ec349aa712e499ca2a8e19d38b586b9ca382b685891684932388f9cd11bcef9/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62633364393436653332636333303832306363392f746573745f636f766572616765)](https://codeclimate.com/github/smuuf/primi/test_coverage)[![Latest Stable Version](https://camo.githubusercontent.com/61e8c4b714754eeee4bd920ec63d59b42a1cdbc053b73712e01c557815ecf9ab/68747470733a2f2f706f7365722e707567782e6f72672f736d7575662f7072696d692f762f737461626c65)](https://packagist.org/packages/smuuf/primi) [![License](https://camo.githubusercontent.com/cfbc18333fea6095b35f7dcf36f55662a8aacc86d9d2831381618fe18180e6bd/68747470733a2f2f706f7365722e707567782e6f72672f736d7575662f7072696d692f6c6963656e7365)](https://packagist.org/packages/smuuf/primi) [![Total Downloads](https://camo.githubusercontent.com/b54f6e462e147aee58152705d65bd37224cc6d465f40fb058809534e781a23cb/68747470733a2f2f706f7365722e707567782e6f72672f736d7575662f7072696d692f646f776e6c6f616473)](https://packagist.org/packages/smuuf/primi)---

Quick access
============

[](#quick-access)

- [Language reference (syntax help)](/docs/language_reference.md)

Rationale
=========

[](#rationale)

Primi *- as things sometimes go in life -* began as an answer to a practical problem: I needed some general-purpose *(ie. not too much domain-specific)* scripting language that my other app's users could use to write their simple custom logic. I needed some universally usable and **primi**tive scripting thing, with familiar syntax *(`PHP-like` x `C-like` x `JS-like`)* and one that could be safely executed inside pure PHP environment *(no external depedencies on v8js, v8 and whatnot - meaning Javascript is out of the game...)*.

***Thus, Primi was (mostly as an experiment) created.***

Installation
============

[](#installation)

You can either use *Primi* as a **[standalone package](#a-standalone-installation)** `(a)` - for its development, making contributions, debugging it, or to just play with it. Or you can use *Primi* **[in your own projects](#b-as-a-library)** `(b)` by installing it as a Composer dependency.

#### You'll want either one of these:

[](#youll-want-either-one-of-these)

- `git clone https://github.com/smuuf/primi.git` *(standalone use)*
- `composer require smuuf/primi` *(using Primi as a library in your own project)*

a) Standalone installation
--------------------------

[](#a-standalone-installation)

1. Clone this repo.
    - `git clone https://github.com/smuuf/primi.git`
2. Install Composer dependencies.
    - `composer install`
3. Run something with Primi CLI.
    - `chmod +x ./primi && ./primi -s -c "a = 1 + 2 / 3;"`

### Convenient installation Oneliner™:

[](#convenient-installation-oneliner)

```
git clone https://github.com/smuuf/primi.git && cd primi && composer install && chmod +x ./primi && ./primi -s -c "msg = 'Primi works.';"

```

### Extra stuff:

[](#extra-stuff)

- **Register Primi's CLI executable** for current user so typing `primi` will behave like a binary *(otherwise you'd need to write `./primi` and would have to be in the right directory)*:

    ```
    ./bin/registerbin

    ```

    *Note: This will add an alias in .bashrc for current user.*
- **Run tests** *(tests are located inside `./tests/` directory)*:

    ```
    ./bin/test

    ```
- **Rebuild parser** *(when you modify Primi's grammar definitions, you will want to rebuild the parser to reflect the changes)*:

    ```
    ./bin/buildparser

    ```

b) Using Primi as a library
---------------------------

[](#b-using-primi-as-a-library)

1. First, install [Primi Composer package](https://packagist.org/packages/smuuf/primi): `composer require smuuf/primi`
2. Then use it like this:

```
