Skip to content

Commit

Permalink
Removed CloudFlare Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
SergkeiM committed Aug 23, 2024
1 parent b3bb91c commit 5dc19f7
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 324 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This package provides convenient access to the Cloudflare REST API using PHP.

* PHP >= 8.0
* Minimal API around the [Guzzle HTTP client](https://github.com/guzzle/guzzle)
* Light and fast thanks to lazy loading of API classes
* Extensively documented
* Laravel >= 9 support

## Quick install 🚀
Expand All @@ -46,7 +48,7 @@ composer require sergkeim/php-cloudflare-api

* Thanks to [Cloudflare](https://developers.cloudflare.com/api/) for the high quality API and documentation.
* Thanks to [KnpLabs](https://github.com/KnpLabs) for [php-github-api](https://github.com/KnpLabs/php-github-api) used as inspiration for this package.
* Thanks to [Graham Campbell](https://github.com/GrahamCampbell) for [Laravel-GitHub](https://github.com/GrahamCampbell/Laravel-GitHub), [Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager?tab=readme-ov-file) and [Laravel TestBench](https://github.com/GrahamCampbell/Laravel-TestBench).
* Thanks to [Graham Campbell](https://github.com/GrahamCampbell) for [Laravel TestBench](https://github.com/GrahamCampbell/Laravel-TestBench).

## License 📎

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"php": "^8.0",
"guzzlehttp/guzzle": "^7.9",
"illuminate/contracts": "^9.0 || ^10.0 || ^11.0",
"illuminate/support": "^9.0 || ^10.0 || ^11.0",
"graham-campbell/manager": "^5.1"
"illuminate/support": "^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6.17 || ^10.5.13",
Expand Down
36 changes: 1 addition & 35 deletions config/cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,5 @@

return [

/*
|--------------------------------------------------------------------------
| Default Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the connections below you wish to use as
| your default connection for all work. Of course, you may use many
| connections at once using the manager class.
|
*/

'default' => 'main',

/*
|--------------------------------------------------------------------------
| Cloudflare Connections
|--------------------------------------------------------------------------
|
| Here are each of the connections setup for your application. Example
| configuration has been included, but you may add as many connections as
| you would like.
|
*/

'connections' => [

'main' => [
'token' => 'your-token',
],

'secondary' => [
'token' => 'your-token',
],
],

'token' => 'your-token',
];
2 changes: 2 additions & 0 deletions docs/content/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ This package provides convenient access to the Cloudflare REST API using PHP.
::list
- PHP >= 8.0
- Minimal API around the [Guzzle HTTP client](https://github.com/guzzle/guzzle)
- Light and fast thanks to lazy loading of API classes
- Extensively documented
- Laravel >= 9 support [see Laravel Usage](/getting-started/laravel)
::

Expand Down
33 changes: 5 additions & 28 deletions docs/content/1.getting-started/4.laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,21 @@ php artisan vendor:publish

This will create a `config/cloudflare.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

There are two config options:

##### Default Connection Name

This option (`'default'`) is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is `'main'`.

##### Cloudflare Connections

This option (`'connections'`) is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like..

## Usage

##### CloudflareManager

`CloudflareManager` is bound to the ioc container as `'cloudflare'` and can be accessed using the `Facades\Cloudflare` facade.

This class implements the `ManagerInterface` by extending `AbstractManager`. The interface and abstract class are both part of [Graham Campbell - Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager) package, so you may want to go and checkout the docs for how to use the manager class over at [that repo](https://github.com/GrahamCampbell/Laravel-Manager#usage).

**Note**: that the connection class returned will always be an instance of `Cloudflare\Client`.
`Cloudflare\Client` is bound to the ioc container as `'cloudflare'` and can be accessed using the `Facades\Cloudflare` facade.

##### Facades\Cloudflare

This facade will dynamically pass static method calls to the `'cloudflare'` object in the ioc container which by default is the `CloudflareManager` class.
This facade will dynamically pass static method calls to the `'cloudflare'` object in the ioc container which by default is the `Cloudflare\Client` class.

##### CloudflareServiceProvider

This class contains no public methods of interest. This class should be added to the providers array in `config/app.php`. This class will setup ioc bindings.

Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is `main`. After you enter your `token` in the config file, it will just work:
Here you can see an example of just how simple this package is to use. Out of the box. After you enter your `token` in the config file, it will just work:

```php [php]
use Cloudflare\Facades\Cloudflare;
Expand All @@ -65,25 +51,16 @@ Cloudflare::accounts()->list();
Cloudflare::accounts()->details('ACCOUNT_ID');
```

The cloudflare manager will behave like it is a `Cloudflare\Client` class. If you want to call specific connections, you can do with the `connection` method:

```php [php]
use Cloudflare\Facades\Cloudflare;

// the secondary connection is the other example provided in the default config
Cloudflare::connection('secondary')->accounts()->members()->details('ACCOUNT_ID', 'MEMBER_ID');
```

If you prefer to use dependency injection over facades, then you can easily inject the manager like so:

```php [php]
use Cloudflare\CloudflareManager;
use Cloudflare\Client;

class Foo
{

public function __construct(
private CloudflareManager $cloudflare
private Client $cloudflare
) {

}
Expand Down
25 changes: 0 additions & 25 deletions src/CloudflareFactory.php

This file was deleted.

92 changes: 0 additions & 92 deletions src/CloudflareManager.php

This file was deleted.

49 changes: 6 additions & 43 deletions src/CloudflareServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,56 +44,21 @@ private function setupConfig(): void
*/
public function register(): void
{
$this->registerCloudflareFactory();
$this->registerManager();
$this->registerBindings();
$this->registerCloudflare();
}

/**
* Register the github factory class.
* Register the Cloudflare Client class.
*
* @return void
*/
private function registerCloudflareFactory(): void
private function registerCloudflare(): void
{
$this->app->singleton('cloudflare.factory', function (Container $app): CloudflareFactory {
return new CloudflareFactory();
$this->app->singleton('cloudflare', function (Container $app): Client {
return new Client(config('cloudflare.token'));
});

$this->app->alias('cloudflare.factory', CloudflareFactory::class);
}

/**
* Register the manager class.
*
* @return void
*/
private function registerManager(): void
{
$this->app->singleton('cloudflare', function (Container $app): CloudflareManager {
$config = $app['config'];
$factory = $app['cloudflare.factory'];

return new CloudflareManager($config, $factory);
});

$this->app->alias('cloudflare', CloudflareManager::class);
}

/**
* Register the bindings.
*
* @return void
*/
private function registerBindings(): void
{
$this->app->bind('cloudflare.connection', function (Container $app): Client {
$manager = $app['cloudflare'];

return $manager->connection();
});

$this->app->alias('cloudflare.connection', Client::class);
$this->app->alias('cloudflare', Client::class);
}

/**
Expand All @@ -104,9 +69,7 @@ private function registerBindings(): void
public function provides(): array
{
return [
'cloudflare.factory',
'cloudflare',
'cloudflare.connection',
];
}
}
27 changes: 0 additions & 27 deletions test/Tests/Laravel/CloudflareFactoryTest.php

This file was deleted.

Loading

0 comments on commit 5dc19f7

Please sign in to comment.