Commit c9be42fa authored by Ludwig Ruderstaller's avatar Ludwig Ruderstaller
Browse files

Symfony Integration

parent 1e6d7885
Pipeline #18019 passed with stage
in 2 minutes and 20 seconds
<?php
/*
* This file is part of the CwdPowerDNS Client
*
* (c) 2018 cwd.at GmbH <office@cwd.at>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cwd\PowerDNSClient;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class CwdPowerDNSClient extends Bundle
{
}
\ No newline at end of file
<?php
/*
* This file is part of the CwdPowerDNS Client
*
* (c) 2018 cwd.at GmbH <office@cwd.at>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cwd\PowerDNSClient\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('cwd_power_dns_client');
$rootNode->children()
->variableNode('uri')->defaultValue('http://localhost')->end()
->variableNode('api_key')->defaultValue(null)->end()
->variableNode('default_server')->defaultValue('localhost')->end()
->end();
return $treeBuilder;
}
}
\ No newline at end of file
<?php
/*
* This file is part of the CwdPowerDNS Client
*
* (c) 2018 cwd.at GmbH <office@cwd.at>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cwd\PowerDNSClient\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class CwdPowerDNSClientExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('cwd_power_dns_client.uri', $config['uri']);
$container->setParameter('cwd_power_dns_client.api_key', $config['api_key']);
$container->setParameter('cwd_power_dns_client.default_server', $config['default_server']);
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);
$loader->load('services.yaml');
}
}
<?php
/*
* This file is part of the Cwd PowerDNS Client
*
* (c) 2018 cwd.at GmbH <office@cwd.at>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cwd\PowerDNSClient;
class PowerDNSClientFactory
{
static public function createClient(string $uri, string $apiKey, ?string $defaultServer = null): PowerDNSClient
{
$client = new Client($uri, $apiKey);
$pdns = new PowerDNSClient($client);
if ($defaultServer !== null) {
$pdns->setDefaultServerId($defaultServer);
}
return $pdns;
}
}
\ No newline at end of file
......@@ -5,4 +5,75 @@ cwdPowerDNS - Client
[![coverage report](https://gitlab.cwd.at/cwd/powerdns-client/badges/develop/coverage.svg)](https://gitlab.cwd.at/cwd/powerdns-client/commits/develop)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cwd/powerdns-client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/cwd/powerdns-client/?branch=master)
@ToDo - Write HowTo
Simple Usage:
-------------
```
$client = PowerDNSClientFactory::createClient('http://mydns.host.tld', 'YOUR_APIKEY_FROM_POWERDNS_CONFIG', 'localhost');
$servers = $client->servers()->all();
// Get all Zones:
$zones = $client->zones()->all();
// Create a new Zone:
$zone = (new Zone())
->setName('example.com.')
->setKind(Zone::KIND_MASTER)
->addRrset(
(new Zone\RRSet())->setName('www.example.com.')
->setType('A')
->setTtl(3600)
->addRecord(
(new Zone\Record())->setContent('127.0.0.1')
->setDisabled(false)
)
->addComment(
(new Zone\Comment())->setContent('Test Test')
->setAccount('Max Mustermann')
)
)
->addRrset((new Zone\RRSet())->setName('delete.example.com.')
->setType('A')
->setTtl(3600)
->addRecord(
(new Zone\Record())->setContent('127.0.0.1')
->setDisabled(false)
)
->addComment((new Zone\Comment())->setContent('test')->setAccount('Maxi'))
)
;
$zone = $client->zones()->create($zone);
```
Symfony Integration:
---------------------
In bundles.php:
```
return [
// ....
Cwd\PowerDNSClient\CwdPowerDNSClient::class => ['all' => true],
];
```
add Basic Config:
```
cwd_power_dns_client:
uri: 'http://mydns.host.tld'
api_key: 'YOUR_APIKEY_FROM_POWERDNS_CONFIG'
default_server: 'localhost'
```
Usage:
```
// From the Container
$client = $ontainer->get(PowerDNSClient::class);
// or via autowiring
public function __construct(PowerDNSClient $client)
{
// ....
}
```
services:
Cwd\PowerDNSClient\PowerDNSClientFactory: ~
Cwd\PowerDNSClient\PowerDNSClient:
public: true
factory: 'Cwd\PowerDNSClient\PowerDNSClientFactory:createClient'
arguments:
- '%cwd_power_dns_client.uri%'
- '%cwd_power_dns_client.api_key%'
- '%cwd_power_dns_client.default_server%'
\ No newline at end of file
{
"name": "cwd/powerdns-client",
"description": "",
"keywords": ["powerns", "api-client", "client", "dns", "bundle"],
"keywords": ["powerdns", "api-client", "client", "dns", "bundle"],
"type": "library",
"license": "MIT",
"authors": [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment