PHPackages                             kengineering/sonar-api-client - 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. [API Development](/categories/api)
4. /
5. kengineering/sonar-api-client

ActiveLibrary[API Development](/categories/api)

kengineering/sonar-api-client
=============================

Sonar API client

v1.2.3(6mo ago)13.2k↓81%3MITPHPPHP ^8.0

Since Jan 23Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/kengeneering/sonar-api-client)[ Packagist](https://packagist.org/packages/kengineering/sonar-api-client)[ RSS](/packages/kengineering-sonar-api-client/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (4)Versions (21)Used By (0)

PHP Sonar API Client
====================

[](#php-sonar-api-client)

An object-oriented client for Sonar ISP management software's API. This client enables you to interact with Sonar's GraphQL API using PHP objects, supporting both individual and concurrent operations through queries and mutations.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require kengineering/sonar-api-client
```

Requirements
------------

[](#requirements)

Before making any requests, your application must have environment variables initialized. The client requires two specific variables in your `.env` file:

```
SONAR_URL="your_sonar_url"
SONAR_KEY="your_api_key"
```

Usage
-----

[](#usage)

The client provides two primary approaches for interacting with the Sonar API:

1. Direct object interaction through classes in `Kengineering\Sonar\Objects\` for single operations
2. Batch operations using `Kengineering\Sonar\Request` for concurrent queries or mutations

### Basic Queries

[](#basic-queries)

The client provides straightforward methods for retrieving data:

```
// Get all accounts (paginated)
$accounts = Accounts::get();

// Get first account
$first_account = Accounts::first();
```

### Complex Queries

[](#complex-queries)

For more complex data requirements, you can build queries that fetch related data in a single request:

```
// Get accounts with addresses
$accounts_with_addresses = Accounts::query()->addToChild(Address::class);

// Get accounts with status and type
$accounts_with_details = Accounts::query()
    ->addToChild(AccountStatus::class)
    ->addToParent(AccountType::class);
```

The query structure follows Sonar's GraphQL schema as a node tree. Use `addToParent()` to query related parent objects, `addToChild()` for child objects, and `end()` when you need to traverse multiple relationship layers.

Searching In Queries
--------------------

[](#searching-in-queries)

Every query instance provides search capabilities through its `search` property. You can apply various search filters:

```
$account = Account::query()->search->intSearch('id', 12321);

$account = Account::query()
    ->search->stringSearch('name', 'John')
    ->search->intSearch('age', 25);
```

### Relation Searching

[](#relation-searching)

To search through related models, use `reverseRelationSearch`. This method accepts the relation name and a callback to define search criteria:

```
$account = Account::query()
    ->addToChild(AccountStatus::class)
    ->reverseRelationSearch('account_status', function(Search $search) {
        $search->stringSearch('name', 'active');
    });
```

### Saving Objects

[](#saving-objects)

Objects can be created in Sonar in two ways. You can either set properties after instantiation or pass them through the constructor:

```
$account = new Account;
$account->name = 'name';
$account->save();

$account = new Account(['name' => 'name']);
$account->save();
```

### Updating Objects

[](#updating-objects)

When updating existing objects, the client automatically determines the operation type based on the object's state. Simply modify the properties and call `save()`:

```
$account = Account::first();
$account->name = 'name';
$account->save();
```

### Deleting Objects

[](#deleting-objects)

Objects can be removed from Sonar using the `delete()` method. The operation will throw an error if Sonar has restrictions preventing deletion:

```
$account = Account::first();
$account->delete();
```

### Batching Queries

[](#batching-queries)

For scenarios requiring multiple queries in a single request, use the Request class. Results are returned in the same order as the queries, or by name if specified:

```
$request = new Request('query');

$request->addOperations([
    Account::query(),
    AccountStatus::query()
]);

$results = $request->get();
$accounts = $results[0];
$accountStatuses = $results[1];
```

Named queries provide clearer access to results:

```
$request = new Request('query');

$request->addOperations([
    'accounts' => Account::query(),
    'account_statuses' => AccountStatus::query()
]);

$results = $request->get();
$accounts = $results['accounts'];
$accountStatuses = $results['account_statuses'];
```

### Batching Mutations

[](#batching-mutations)

Mutations can be batched similarly to queries. Pass `true` to the batch\_request parameter of mutation operations to prepare them for batching:

```
$request = new Request('mutation');

$request->addOperations([
    $account->save(true),
    $account_status->delete(true)
]);
```

### Object Functions

[](#object-functions)

Many objects provide helper functions to streamline common operations. These functions automatically fetch required related data if not already loaded:

```
$account = Account::first();
$serviceable_address = $account->serviceableAddress();
```

Objects also include functions for managing relationships, which can be included in batch operations:

```
$account = Account::first();
$service = Service::first();

$account->addService($service);
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance66

Regular maintenance activity

Popularity23

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~60 days

Total

20

Last Release

196d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2473f47a48ea7d4cbfe1b8b1b2e7879176344653e5fd2f2e95923486469d3632?d=identicon)[kengineering](/maintainers/kengineering)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kengineering-sonar-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/kengineering-sonar-api-client/health.svg)](https://phpackages.com/packages/kengineering-sonar-api-client)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

668535.6k5](/packages/netflie-whatsapp-cloud-api)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.7k1](/packages/jasara-php-amzn-selling-partner-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
