Skip to content

Commit cabf1c8

Browse files
authored
Add dependency injection for all objects relying on ObjectSpec (#82)
* Add dependency injection for all objects relying on ObjectSpec (command frames and client) * Changed ObjectSpec to be non-static class * Removed NASK's ObjectSpec methods to better facilitate new ObjectSpec * Modified examples to use new ObjectSpec way of doing things * Removed unnecessary php-version dependent tests due to non-static ObjectSpec * Added HTTPClient connection example * Moved COZA extension example to Extension subdir in examples * Added documentation in README.md * Added recent changes to CHANGELOG.md
1 parent f93b782 commit cabf1c8

File tree

87 files changed

+691
-2361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+691
-2361
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@
77
- Updated code documentation (more contributions welcome)
88
- Increased testing coverage
99
- More detailed examples of using this library
10+
- All frame objects now accept ObjectSpec as dependency in order to fix static ObjectSpec problems (eg inability to have custom namespaces). This isn't breaking since without ObjectSpec being passed, default one is used
1011

1112
### Added
1213

1314
- DNSSec dsData support in Domain classes ( @johnny-bit)
1415
- Introduced `HTTPClient` allowing EPP communication over HTTP(S) (@johnny-bit)
1516
- `AbstractClient` class and `ClientInterface` interface for ease of creating `Client` replacements(@johnny-bit)
16-
- NASK Extension - a full Polish domain registry support
17+
- NASK Extension - a full Polish domain registry support (@johnny-bit)
18+
- Dependency injection for ObjectSpec (especially useful for registrars not following EPP namespaces, like NASK) (@johnny-bit)
19+
- Nominet `release` extension for domains (@greenmato)
20+
- nic.it extensions (@bessone)
1721

1822
### Fixed
1923

2024
- RFC5733 compatibility enhancements (added `extension` to voice and fax) for Contact calls(@johnny-bit)
2125
- Removed coverage checks from non-testable classes
2226
- Incorrect file permissions (execute bit) on source files
27+
- `verify_peer_name` logic (@domainregistrar)
28+
- Testing issues (@bessone)
2329

2430
## 1.0.0 - 2018-12-23
2531

README.md

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ Features
4545
* [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/) & [PSR-4](http://www.php-fig.org/psr/psr-4/)
4646
* notice and warning free (find them, and I'll fix it!)
4747
* high-level usage (Plug & Play)
48-
* simplified client (auto login/logout, auto inject clTRID)
48+
* simplified client for socket and http(s) connections (auto login/logout, auto inject clTRID)
4949
* SSL (+local-cert)
5050
* XPath like setter to simplify the creation of complex XML structures
5151
* XML based responses for direct traversal via XPath
5252
* [RFC 5730](http://tools.ietf.org/html/rfc5730), [RFC 5731](http://tools.ietf.org/html/rfc5731), [RFC 5732](http://tools.ietf.org/html/rfc5732), [RFC 5733](http://tools.ietf.org/html/rfc5733), [RFC 5734](http://tools.ietf.org/html/rfc5734) & [RFC 3915](http://tools.ietf.org/html/rfc3915)
53+
* DNSSEC support [RFC 5910](http://tools.ietf.org/html/rfc5910)
5354

5455

5556
Install
@@ -119,7 +120,7 @@ require 'vendor/autoload.php';
119120

120121
use AfriCC\EPP\Frame\Command\Create\Host as CreateHost;
121122

122-
$frame = new CreateHost;
123+
$frame = new CreateHost();
123124
$frame->setHost('ns1.example.com');
124125
$frame->setHost('ns2.example.com');
125126
$frame->addAddr('8.8.8.8');
@@ -141,7 +142,7 @@ Method which will return an assoc array.
141142
use AfriCC\EPP\Frame\Command\Check\Domain as DomainCheck;
142143
use AfriCC\EPP\Frame\Response;
143144

144-
$frame = new DomainCheck;
145+
$frame = new DomainCheck();
145146
$frame->addDomain('example.org');
146147
$frame->addDomain('example.net');
147148
$frame->addDomain('example.com');
@@ -170,12 +171,95 @@ foreach ($data['chkData']['cd'] as $cd) {
170171
printf('Domain: %s, available: %d' . PHP_EOL, $cd['name'], $cd['@name']['avail']);
171172
}
172173
```
174+
### Custom ObjectSpec
173175

176+
If registrar you're working with uses custom namespace names (eg NASK) you can
177+
use custom ObjectSpec. Clients always use specified ObjectSpec when decoding
178+
responses from EPP server.
179+
180+
You can use this feature as follows:
181+
182+
```php
183+
use AfriCC\EPP\HTTPClient as EPPClient;
184+
use \AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
185+
use AfriCC\EPP\Frame\Command\Poll;
186+
187+
$objectSpec = new NASKObjectSpec();
188+
$config = [
189+
'host' => 'https://app.registrar.tld',
190+
'username' => 'user',
191+
'password' => 'pass',
192+
'services' => $objectSpec->services,
193+
'serviceExtensions' => $objectSpec->serviceExtensions,
194+
];
195+
196+
$epp_client = new EPPClient($config, $objectSpec);
197+
198+
$frame = new Poll($epp_client->getObjectSpec());
199+
```
200+
201+
or you can create frames with custom ObjectSpec:
202+
203+
```php
204+
use AfriCC\EPP\Extension\NASK\Update\Future as UpdateFuture;
205+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
206+
207+
$frame = new UpdateFuture(new NASKObjectSpec());
208+
$frame->setFuture('example7.pl');
209+
$frame->changeRegistrant('mak21');
210+
$frame->changeAuthInfo('2fooBAR');
211+
echo $frame;
212+
```
213+
214+
You can also create different clients with different ObjectSpec and then you can
215+
use `getObjectSpec` method when creating any request frame:
216+
217+
```php
218+
use AfriCC\EPP\ObjectSpec as DefaultObjectSpec;
219+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
220+
use AfriCC\EPP\Client as EPPClient;
221+
use AfriCC\EPP\HTTPClient as HTTPEPPClient;
222+
use AfriCC\EPP\Frame\Command\Poll;
223+
224+
//...
225+
$nask_objectspec = new NASKObjectSpec();
226+
$default_objectspec = new DefaultObjectSpec();
227+
228+
$nask_client = new HTTPEPPClient($nask_config, $nask_objectspec);
229+
$http_client = new HTTPEPPClient($http_config, $default_objectspec);
230+
$socket_client = new EPPClient($socket_config, $default_objectspec);
231+
$nask_socket_client = new EPPClient($nask_socket_config, $nask_objectspec);
232+
233+
$nask_poll = new Poll($nask_client->getObjectSpec());
234+
$default_poll = new Poll($socket_client->getObjectSpec());
235+
```
236+
237+
You can also change Client's objectSpec on the fly via `setObjectSpec` method:
238+
239+
```php
240+
use AfriCC\EPP\ObjectSpec as DefaultObjectSpec;
241+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
242+
use AfriCC\EPP\Client as EPPClient;
243+
244+
//...
245+
$nask_objectspec = new NASKObjectSpec();
246+
$default_objectspec = new DefaultObjectSpec();
247+
248+
$variable_client = new EPPClient($socket_config, $default_objectspec);
249+
250+
//calls to getObjectSpec will return default objectSpec and responses
251+
//will be parsed using default ObjectSpec
252+
253+
$variable_client->setObjectSpec($nask_objectspec);
254+
255+
//calls to getObjectSpec will return NASK objectSpec and responses
256+
//will be parsed using NASK ObjectSpec
257+
258+
```
174259

175260
Future
176261
------
177262

178-
* objectspec on login needs to be smarter (no global/static object, auto-injecter)
179263
* stricter response parsing
180264
* stricter request validation
181265
* make it server capable (in conjunction with apache mod_epp)
@@ -201,4 +285,3 @@ License
201285
php-epp2 is released under the GPLv3 License. See the bundled
202286
[LICENSE](https://github.com/AfriCC/php-epp2/blob/master/LICENSE) file for
203287
details.
204-

examples/Connection/http_connect.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
// debug
4+
error_reporting(E_ALL);
5+
ini_set('display_errors', true);
6+
7+
chdir(__DIR__);
8+
9+
require '../../vendor/autoload.php';
10+
11+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
12+
use AfriCC\EPP\Frame\Command\Poll;
13+
use AfriCC\EPP\HTTPClient as EPPClient;
14+
15+
$objectSpec = new NASKObjectSpec();
16+
$config = [
17+
'debug' => true,
18+
'host' => 'https://app.registrar.tld',
19+
'username' => 'user',
20+
'password' => 'pass',
21+
'services' => $objectSpec->services,
22+
'serviceExtensions' => $objectSpec->serviceExtensions,
23+
//'ssl' => true, //ssl forced to true by using "https" protocol
24+
'ca_cert' => 'ca.crt',
25+
'local_cert' => 'client.crt',
26+
'pk_cert' => 'client.key',
27+
];
28+
29+
$epp_client = new EPPClient($config, $objectSpec);
30+
31+
try {
32+
$greeting = $epp_client->connect();
33+
34+
echo $greeting;
35+
36+
$frame = new Poll($epp_client->getObjectSpec()); //use epp client default objectspec
37+
$frame->request();
38+
39+
$response = $epp_client->request($frame);
40+
41+
while ($response->success() && $response->code() !== 1300) { // 1300 = result successful, no more mesages
42+
43+
echo 'Epp Poll message ID: ';
44+
echo $response->queueId();
45+
echo "\n";
46+
echo 'Epp Poll Message: ';
47+
echo $response->queueMessage();
48+
49+
$ackFrame = new Poll($epp_client->getObjectSpec());
50+
$ackFrame->ack($response->queueId());
51+
$ackResponse = $epp_client->request($ackFrame);
52+
if (!$ackResponse->success()) {
53+
echo "Couldn't ACK poll message\n";
54+
break; // no ack!
55+
}
56+
$response = $client->request($frame); //reuse already existing poll request frame
57+
}
58+
} catch (Exception $e) {
59+
echo $e->getMessage() . PHP_EOL;
60+
unset($epp_client);
61+
exit(1);
62+
}
63+
64+
$epp_client->close();

examples/connect.php renamed to examples/Connection/socket_connect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
chdir(__DIR__);
88

9-
require '../vendor/autoload.php';
9+
require '../../vendor/autoload.php';
1010

1111
use AfriCC\EPP\Client as EPPClient;
1212

examples/extension.php renamed to examples/Extension/COZA/contact_info.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
chdir(__DIR__);
88

9-
require '../vendor/autoload.php';
9+
require '../../../vendor/autoload.php';
1010

1111
use AfriCC\EPP\Extension\COZA\Info\CozaContact as CozaContactInfoExtension;
12-
use AfriCC\EPP\Extension\COZA\Update\CozaContact as CozaContactUpdateExtension;
1312

1413
$frame = new CozaContactInfoExtension();
1514
$frame->setId('MyContact');
@@ -24,10 +23,3 @@
2423
$frame->setAuthInfo('password');
2524
$frame->requestDomainListing();
2625
echo $frame;
27-
28-
echo PHP_EOL;
29-
30-
$frame = new CozaContactUpdateExtension();
31-
$frame->setId('MyContact');
32-
$frame->cancelPendingAction();
33-
echo $frame;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
// debug
4+
error_reporting(E_ALL);
5+
ini_set('display_errors', true);
6+
7+
chdir(__DIR__);
8+
9+
require '../../../vendor/autoload.php';
10+
11+
use AfriCC\EPP\Extension\COZA\Update\CozaContact as CozaContactUpdateExtension;
12+
13+
$frame = new CozaContactUpdateExtension();
14+
$frame->setId('MyContact');
15+
$frame->cancelPendingAction();
16+
echo $frame;

examples/Extension/NASK/check_future.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
require './_autoload.php';
1010
use AfriCC\EPP\Extension\NASK\Check\Future as CheckFuture;
11-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
11+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new CheckFuture();
13+
$frame = new CheckFuture(new NASKObjectSpec());
1614
$frame->addFuture('ala.pl');
1715
$frame->addFuture('ela.com.pl');
1816
$frame->addFuture('ola.org');

examples/Extension/NASK/create_future.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
require './_autoload.php';
1010
use AfriCC\EPP\Extension\NASK\Create\Future as CreateFuture;
11-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
11+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new CreateFuture();
13+
$frame = new CreateFuture(new NASKObjectSpec());
1614
$frame->setFuture('example.pl');
1715
$frame->setPeriod('3y');
1816
$frame->setRegistrant('jd1234');

examples/Extension/NASK/delete_future.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
require './_autoload.php';
1010
use AfriCC\EPP\Extension\NASK\Delete\Future as DeleteFuture;
11-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
11+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new DeleteFuture();
13+
$frame = new DeleteFuture(new NASKObjectSpec());
1614
$frame->setFuture('futuretest.pl');
1715
echo $frame;

examples/Extension/NASK/info_future.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
require './_autoload.php';
1010
use AfriCC\EPP\Extension\NASK\Info\Future as InfoFuture;
11-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
11+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new InfoFuture();
13+
$frame = new InfoFuture(new NASKObjectSpec());
1614
$frame->setFuture('example.pl');
1715
$frame->setAuthInfo('2fooBAR');
1816
echo $frame;

examples/Extension/NASK/renew_future.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
chdir(__DIR__);
88

99
require './_autoload.php';
10-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
10+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1111
use AfriCC\EPP\Extension\NASK\Renew\Future as RenewFuture;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new RenewFuture();
13+
$frame = new RenewFuture(new NASKObjectSpec());
1614
$frame->setFuture('example.pl');
1715
$frame->setCurrentExpirationDate('2010-10-30');
1816
$frame->setPeriod('3y');

examples/Extension/NASK/report_basic.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
chdir(__DIR__);
88

99
require './_autoload.php';
10-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
10+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1111
use AfriCC\EPP\Extension\NASK\Report;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new Report();
13+
$frame = new Report(new NASKObjectSpec());
1614
$frame->setOffset(0);
1715
$frame->setLimit(50);
1816
echo $frame;

examples/Extension/NASK/report_cancel.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
chdir(__DIR__);
88

99
require './_autoload.php';
10-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
10+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1111
use AfriCC\EPP\Extension\NASK\Report\Cancel as ReportCancel;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new ReportCancel();
13+
$frame = new ReportCancel(new NASKObjectSpec());
1614
$frame->setReportId('e264a95d-0ba0-40f1-a0e0-97407fd5cdbe');
1715
$frame->setOffset(0);
1816
$frame->setLimit(50);

examples/Extension/NASK/report_contact.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
chdir(__DIR__);
88

99
require './_autoload.php';
10-
use AfriCC\EPP\Extension\NASK\ObjectSpec;
10+
use AfriCC\EPP\Extension\NASK\ObjectSpec as NASKObjectSpec;
1111
use AfriCC\EPP\Extension\NASK\Report\Contact as ReportContact;
1212

13-
ObjectSpec::overwriteParent();
14-
15-
$frame = new ReportContact();
13+
$frame = new ReportContact(new NASKObjectSpec());
1614
$frame->setContactId('k13');
1715
$frame->setOffset(0);
1816
$frame->setLimit(50);

0 commit comments

Comments
 (0)