This repository is archived as 2021-07-01 because phabricator is no longer maintained.
---
, (*1)
Phabricator PHP API (Conduit client)
This is a PHP based client for Phabricator API. Phabricator is an open source, software engineering platform, built in PHP, and it has a very nice API called Conduit.
For all available endpoint and method name, see the Conduit Application in the live Phabricator instance., (*2)
Basic useful feature list:, (*3)
- Fully implemented all current API endpoint
- Ability to make custom Client implementation
- Custom handler class for each endpoint
Installation
With composer
Run this command inside your project, (*4)
composer require zolli/phabricator-php-api
Or past this dependency into your composer.json manually, (*5)
{
"require": {
"zolli/phabricator-php-api": "2.0.*"
}
}
Documentation
Initialization
//Initialization the instance
$api = new \Phabricator\Phabricator('http://phabricator.example.com', 'cli-exmapletoken')
The API is now ready to use. This class uses magic method to proxy the calls to the suitable endpoint handler.
Phabricator methods should looks like this: project.query. In this package exploded into two parts., (*6)
The first is the endpoint (Project in this example) and the method (query);, (*7)
With this example the call is looks like this:, (*8)
$result = $api->Project('query', ['status' => 'status-open']);
In this example the /api/project.query API is called and the status argument is passed., (*9)
Using custom client
This API of this package is allows you to make custom API clients that run the request for you.
All client should implement the Phabricator\Client\ClientInterface interface., (*10)
Custom clients should be injected in two different way., (*11)
Injecting trough the constructor, (*12)
$myClient = \Vendor\Package\MyAwesomeApiClient();
$api = new \Phabricator\Phabricator('http://phabricator.example.com', 'cli-exmapletoken', $myClient);
Or you can use the Phabricator::setClient(ClientInterface $client) method., (*13)
$myClient = \Vendor\Package\MyAwesomeApiClient();
$api = new \Phabricator\Phabricator('http://phabricator.example.com', 'cli-exmapletoken');
$api->setClient($myClient);
Custom endpoint handlers
Handlers are various classes that handle the execution and post-processing of endpoint methods.
By default all API endpoint have handler, but only the default that no do any pre- or post-processing., (*14)
By example a custom handler can read and write files when using the file.upload or file.download method., (*15)
To achieve this create a class that implements the \Phabricator\Endpoints\EndpointInterface and extends the
\Phabricator\Endpoints\BaseEndpoint class and you good to go., (*16)
The BaseEndpoint provides a defaultExecutor() method that executed when an endpoint method
not has any specific executor., (*17)
When creating custom executor method this methods will be used when calling an endpoint method., (*18)
Look the BaseEndpoint and any endpoint handler for more information., (*19)
Suppose that you created and endpoint handler with this FQCN: \Vendor\Package\Hander\FileHander;
You can push this handler like this:, (*20)
Tha first argument is the endpoint name for this handler is listen and the second is the FQCN of the handler., (*21)
$api = new \Phabricator\Phabricator('http://phabricator.example.com', 'cli-exmapletoken');
$api->pushEndpointHandler('File', FileHandler::class);
Responses
The client is returning \Phabricator\Response\ConduitResponse as response. Look API documentation for
methods., (*22)
Upgrading
From 1.0.0
In the 2.0.0 release the API is changed significantly and the underlying API dramatically.
So, this release probably not compatible with components that created for 1.0.0, (*23)
Main API Differences:, (*24)
- The
\Phabricator\Phabricator constructor only take the baseUrl and the tokens as arguemnt
- Client registration in constructor is now optional
- Registering custom endpoint handler only require the handler Fully qualified class name, not instance
- Instead of
\stdClass responses now \Phabricator\Response\ConduitResponse objects.
- The
\Phabricator\Client\ClientInterface interface changed significantly.
- The arguments of endpoint handler methods (executors) changed.
- Now not using exceptions from global namespace, instead use
buildr/foundation package exceptions
- Clients not responsible for request data formatting.
API Documentation
The 2.0.0 release API documentation is available here: API Documentation, (*25)
Contribution
Project link, (*26)
For contribution guide and coding standard please visit our Coding Standard Repository, (*27)
Licensing
This project licensed under GNU - General Public License, version 3, (*28)
, (*29)