PHPackages                             lmnt/philo-cli - 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. [CLI &amp; Console](/categories/cli)
4. /
5. lmnt/philo-cli

ActiveLibrary[CLI &amp; Console](/categories/cli)

lmnt/philo-cli
==============

Wrangle data from your terminal using extensible &amp; expressive philo syntax

18PHPCI failing

Since Jun 3Pushed 5y ago1 watchersCompare

[ Source](https://github.com/lmnt-dev/philo-cli)[ Packagist](https://packagist.org/packages/lmnt/philo-cli)[ RSS](/packages/lmnt-philo-cli/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

⍎ ρhilo-cli
===========

[](#-ρhilo-cli)

Wrangle data from your terminal using extensible &amp; expressive philo syntax

Requires PHP 7.4+

Install globally
----------------

[](#install-globally)

If you're not using `cgr` for global installs, consider adopting it:

```
composer global require consolidation/cgr
```

Then install philo globally via `cgr`:

```
cgr --stability dev lmnt/philo-cli
```

Interactive mode
----------------

[](#interactive-mode)

Use the repl to experiment:

```
> philo
```

### Predicates &amp; Types

[](#predicates--types)

Let's define a few types:

```
⏂ > $Age = all(is_int, gt(0), lt(150))
⏂ > $Person = ['name' => is_string, 'age' => $Age, 'website' => maybe(is_url)]
⏂ > $Contacts = every($Person)
```

We can make some assertions now:

```
⏂ > is($Person, ['name' => 'bob', 'age' => 50])
=> true
⏂ > is($Person, ['name' => 'bob', 'age' => 50, 'extra' => 1])
=> true
⏂ > is(strict($Person), ['name' => 'bob', 'age' => 50, 'extra' => 1])
=> false
⏂ > is($Person, ['name' => 'bob', 'age' => -1])
=> false
⏂ > is($Person, ['name' => 'bob', 'age' => 50, 'website' => 'google.com'])
=> false
⏂ > is($Person, ['name' => 'bob', 'age' => 50, 'website' => 'http://google.com'])
=> true
⏂ > is($Contacts, [['name' => 'bob', 'age' => 50]])
=> true
⏂ > is($Contacts, [['name' => 'bob', 'age' => 50], 'barb'])
=> false
```

On built-in types as well:

```
⏂ > $x = new \ArrayObject()
⏂ > is(\ArrayObject::class, $x)
=> true
⏂ > is(\Countable::class, $x)
=> true
```

Get back to your terminal via `ctrl + c` or by typing `exit`.

### Loading data

[](#loading-data)

Load data into philo from a local file or a URL.

Let's restart the repl with some json from a public endpoint:

```
> philo http://data.cdc.gov/data.json
```

Examine the datasource:

```
⏂ > $x
```

What are the keywords for the last 3 entries?

```
⏂ > pipe(to_array(pluck('keyword')), slice(-3))($x['dataset'])
```

Non-interactive mode
--------------------

[](#non-interactive-mode)

Pipe data in:

```
> echo '[{"a":1,"b":3},{"a":2,"b":4}]' | philo 'to_array(pluck(a), true)'
[{"a":1},{"a":2}]
```

Or send via input redirection:

```
> curl https://newton.now.sh/factor/x^2-1 > /tmp/math
> cat /tmp/math
{"operation":"factor","expression":"x^2-1","result":"(x - 1) (x + 1)"}
> philo 'pipe(to_array(values), spread(fn($a, $b, $c) => [$c, $b, $a]))'
