https://github.com/updevru/dkron-php-client
PHP Dkron API client
https://github.com/updevru/dkron-php-client
dkron php
Last synced: 6 months ago
JSON representation
PHP Dkron API client
- Host: GitHub
- URL: https://github.com/updevru/dkron-php-client
- Owner: updevru
- License: mit
- Created: 2022-07-08T13:11:42.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-19T11:16:02.000Z (over 1 year ago)
- Last Synced: 2025-11-11T19:22:20.629Z (8 months ago)
- Topics: dkron, php
- Language: PHP
- Homepage:
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dkron PHP Client
[](https://github.com/updevru/dkron-php-client/actions)
[](https://packagist.org/packages/updevru/dkron-php-client)
[](https://packagist.org/packages/updevru/dkron-php-client)
This is the PHP [Dkron](https://dkron.io) API client. This library allows using of the actual API version.
You can find more info in the [documentation](https://dkron.io/api/).
# Table of contents
* [Requirements](#requirements)
* [Installation](#installation)
* [Usage](#usage)
* [Testing](#testing)
## Requirements
* PHP 7.4 and above
* PHP's cURL support
* PHP's JSON support
* Any HTTP client compatible with PSR-18 (covered by the installation instructions).
* Any HTTP factories implementation compatible with PSR-17 (covered by the installation instructions).
* Any HTTP messages implementation compatible with PSR-7 (covered by the installation instructions).
## Installation
Install the library from the Packagist by executing this command:
```bash
composer require updevru/dkron-php-client
```
**Note:** API client uses php-http/curl-client and nyholm/psr7 as a PSR-18, PSR-17 and PSR-7 implementation.
You can replace those implementations during installation by installing this library with the implementation of your choice, like this:
```bash
composer require php-http/curl-client nyholm/psr7 updevru/dkron-php-client
```
## Usage
Firstly, you should initialize the Client.
```php
use Http\Client\Curl\Client;
use Nyholm\Psr7\Factory\Psr17Factory;
use Updevru\Dkron\ApiClient;
use Updevru\Dkron\Endpoint\EndpointCollection;
$client = new Updevru\Dkron\ApiClient(
new Updevru\Dkron\Endpoint\EndpointCollection(
[
[
'url' => 'http://localhost',
'login' => null,
'password' => null,
]
]
),
new Http\Client\Curl\Client(),
new Nyholm\Psr7\Factory\Psr17Factory(),
new Nyholm\Psr7\Factory\Psr17Factory()
);
$api = new \Updevru\Dkron\Api($client, new \Updevru\Dkron\Serializer\JMSSerializer());
```
If HTTP basic authorization is enabled, enter login and password.
Create new job:
```php
$newJob = new \Updevru\Dkron\Dto\JobDto();
$newJob->setName('test_job');
$newJob->setSchedule('*/2 * * * * *');
$newJob->setConcurrency(\Updevru\Dkron\Dto\JobDto::CONCURRENCY_FORBID);
$newJob->setExecutor('shell');
$newJob->setExecutorConfig(['command' => 'echo Hello']);
$api->jobs->createOrUpdateJob($newJob);
```
Run job manually:
```php
$api->jobs->runJob('test_job');
```
Show list executions:
```php
$jobs = $api->jobs->getJobs();
```
Disable job:
```php
$api->jobs->toggleJob('test_job');
```
Deleting job test_job:
```php
$api->jobs->deleteJob('test_job');
```
## Testing
Run unit tests:
```bash
composer tests
```
Demo working library:
```bash
php bin/test.php http://localhost:8080
```