Download the PHP package kengineering/sonar-api-client without Composer
On this page you can find all versions of the php package kengineering/sonar-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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
Install the package via composer:
Requirements
Before making any requests, your application must have environment variables initialized. The client requires two specific variables in your .env
file:
Usage
The client provides two primary approaches for interacting with the Sonar API:
- Direct object interaction through classes in
Kengineering\Sonar\Objects\
for single operations - Batch operations using
Kengineering\Sonar\Request
for concurrent queries or mutations
Basic Queries
The client provides straightforward methods for retrieving data:
Complex Queries
For more complex data requirements, you can build queries that fetch related data in a single request:
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
Every query instance provides search capabilities through its search
property. You can apply various search filters:
Relation Searching
To search through related models, use reverseRelationSearch
. This method accepts the relation name and a callback to define search criteria:
Saving Objects
Objects can be created in Sonar in two ways. You can either set properties after instantiation or pass them through the constructor:
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()
:
Deleting Objects
Objects can be removed from Sonar using the delete()
method. The operation will throw an error if Sonar has restrictions preventing deletion:
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:
Named queries provide clearer access to results:
Batching Mutations
Mutations can be batched similarly to queries. Pass true
to the batch_request parameter of mutation operations to prepare them for batching:
Object Functions
Many objects provide helper functions to streamline common operations. These functions automatically fetch required related data if not already loaded:
Objects also include functions for managing relationships, which can be included in batch operations: