JQL builder is a supercharged PHP package that allows you to create Jira Query Language (JQL).
Requires PHP 8.0+
First, install devmoath/jql-builder
via the Composer package manager:
composer require devmoath/jql-builder
Then, interact with JQL builder:
$query = new Jql();
$query->where('project', 'PROJECT')->where('summary', '~', 'title');
echo $query; // 'project = "PROJECT" and summary ~ "title"'
This is how to generate query:
use JqlBuilder\Jql;
$builder = new Jql();
// Simple query
$query = $builder->where('project', 'MY PROJECT')->getQuery();
echo $query;
// 'project = "MY PROJECT"'
$builder = new Jql();
// Complex query
$query = $builder->where('project', 'MY PROJECT')
->where('status', ['New', 'Done'])
->orWhere('summary', '~', 'sub-issue for "TES-xxx"')
->orWhere('labels', 'support')
->when(false, fn (Jql $builder, mixed $value) => $builder->where('creator', 'admin'))
->when(true, fn (Jql $builder, mixed $value) => $builder->where('creator', 'guest'))
->orderBy('created', 'asc')
->getQuery();
echo $query;
// 'project = "MY PROJECT" and status in ("New", "Done") or summary ~ "sub-issue for \"TES-xxx\"" or labels = "support" and creator = "guest" order by created asc'
Also, you can add macro functions as well to encapsulate your logic:
use JqlBuilder\Jql;
$builder = new Jql();
$builder::macro('whereCustom', function (mixed $value) {
/*
* your code...
*/
/** @var Jql $this */
return $this->where('custom', $value);
});
$query = $builder->whereCustom('1')->getQuery();
echo $query;
// 'custom = "1"'
laravel facade support out of the box:
use JqlBuilder\Facades\Jql;
$query = Jql::where('summary', '=', 'value')->getQuery();
echo $query;
// 'summary = "value"'
Thank you for considering contributing to the JQL Builder! The contribution guide can be found in the CONTRIBUTING.
If you discover any security-related issues, please email moath.alhajrii@gmail.com instead of using the issue tracker.
JQL builder is an open-sourced software licensed under the MIT license.