libtek / laravel-jmespath
jmespath.php service provider for Laravel 5
Installs: 1 280
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 4
Open Issues: 0
Requires
- php: >=5.5.9
- illuminate/config: ~5.1
- illuminate/console: ~5.1
- illuminate/container: ~5.1
- illuminate/filesystem: ~5.1
- illuminate/support: ~5.1
- mtdowling/jmespath.php: ~2.2
This package is not auto-updated.
Last update: 2024-11-23 18:13:06 UTC
README
A Laravel 5 wrapper for use of the jmespath.php library. The jmespath.php library is an implementation of the JMESPath specification.
This package also provides Artisan commands to pre-compile and manage your JMESPath expressions.
Installation
Install through composer
$ composer require libtek/laravel-jmespath
Add Service Provider
In config/app.php
, add the service provider to the $providers
array:
'providers' => [ // ... Libtek\Jmes\JmesServiceProvider::class, ],
Add alias
In config/app.php
, add the facade to the $aliases
array:
'aliases' => [ // ... 'Jmes' => Libtek\Jmes\Facades\Jmes::class, ],
Publish the configuration file
If you'd like to modify the default configuration values or define expressions to pre-compile, publish the package config file:
php artisan vendor:publish --provider="Libtek\Jmes\JmesServiceProvider"
This will create a jmes.php
file in your config
directory.
Usage
With facade:
$result = Jmes::search($expression, $data);
Helper function:
$result = jmes($expression, $data);
Artisan commands
Two Artisan commands are available with the package:
jmes:compile
This compiles and caches JMESPath expressions. Expressions can be sourced in multiple ways:
-
Running the command with no options or arguments will look for expressions in the
jmes.php
config file:php artisan jmes:compile
-
Passing a single expression to the command:
php artisan jmes:compile 'foo.*.baz'
-
Setting the
-c
or--cli
option will prompt for expressions to be added manually:php artisan jmes:compile --cli Please enter a JMESPath expression: > foo.*.baz
jmes:clear
This will delete any previously compiled expressions:
php artisan jmes:clear
Pass -h
or --help
to either command to view its usage.