11<?php
2- /**
3- * Created by PhpStorm.
4- * User: martinha
5- * Date: 10/04/2019
6- * Time: 09:17
7- */
2+ /** @noinspection PhpMissingReturnTypeInspection */
83
94namespace Metaregistrar \EPP ;
105
6+ use DomElement ;
7+ use DOMException ;
8+
119/**
12- * Class atEppWithdrawRequest works only as adapter in order to map a atEppResponse.
1310 *
11+ 1412 * @package Metaregistrar\EPP
13+ *
1514 */
1615class atEppWithdrawRequest extends eppRequest
1716{
1817 /**
19- * atEppWithdrawRequest constructor.
20- * @param $arguments
21- *
22- * @throws \atEppException
18+ * @throws DOMException
2319 */
24- public function __construct ($ arguments )
20+ public function __construct (eppDomain $ domain , bool $ zoneDelete = false )
2521 {
26- $ this ->validateArguments ($ arguments );
2722 parent ::__construct ();
23+
24+ $ domainZd = $ this ->createElement ('domain:zd ' );
25+ $ domainZd ->setAttribute ('value ' , intval ($ zoneDelete ));
26+
27+ $ domainWithdraw = $ this ->createElement ('domain:withdraw ' );
28+ $ domainWithdraw ->setAttribute ('xmlns:domain ' , atEppConstants::namespaceAtExtDomain);
29+ $ domainWithdraw ->setAttribute ('xsi:schemaLocation ' , atEppConstants::schemaLocationAtExtDomain);
30+ $ domainWithdraw ->appendChild ($ this ->createElement ('domain:name ' , $ domain ->getDomainname ()));
31+ $ domainWithdraw ->appendChild ($ domainZd );
32+
33+ $ withdraw = $ this ->createElement ('withdraw ' );
34+ $ withdraw ->appendChild ($ domainWithdraw );
35+
36+ $ this ->getCommand ()->appendChild ($ withdraw );
37+ $ this ->addSessionId ();
2838 }
2939
30- protected function validateArguments ($ arguments )
40+ /**
41+ * Needs to be overwritten, because relation of extension and command is inverted in withdraw command.
42+ *
43+ * @return DomElement
44+ * @throws DOMException
45+ */
46+ public function getExtension ()
3147 {
32- if (! key_exists ('domain_name ' , $ arguments ) || ! key_exists ('zone_deletion ' , $ arguments ))
33- {
34- throw new \atEppException (
35- 'atEppWithdrawRequest requires two arguments domain_name:string and zone_deletion:boolean. ' );
48+ if (!$ this ->extension ) {
49+ #
50+ # If it's not there, then create extension structure
51+ #
52+ $ this ->extension = $ this ->createElement ('extension ' );
53+ $ this ->getEpp ()->appendChild ($ this ->extension );
3654 }
55+ return $ this ->extension ;
56+ }
57+
58+
59+ /**
60+ * Get the command element of the epp structure.
61+ * Needs to be overwritten, because relation of extension and command is inverted in withdraw command.
62+ *
63+ * @return DomElement
64+ * @throws DOMException
65+ */
66+ protected function getCommand () {
67+ if (!$ this ->command ) {
68+ #
69+ # If it's not there, then create command structure
70+ #
71+ $ this ->command = $ this ->createElement ('command ' );
72+ $ this ->command ->setAttribute ('xmlns ' , atEppConstants::namespaceAtExt);
73+ $ this ->command ->setAttribute ('xsi:schemaLocation ' , atEppConstants::schemaLocationAtExt);
74+ $ this ->getExtension ()->appendChild ($ this ->command );
75+ }
76+ return $ this ->command ;
77+ }
78+
79+ /**
80+ * Get the epp element of the epp structure
81+ * Overwrite necessary because error occurs if 'xmlns:xsi' attribute is not supplied.
82+ *
83+ * @return DomElement
84+ */
85+ public function getEpp () {
86+ parent ::getEpp ()->setAttribute ('xmlns:xsi ' , atEppConstants::w3SchemaLocation);
87+ return $ this ->epp ;
3788 }
3889}
0 commit comments