-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
219 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace YOCLIB\EPP\Connections; | ||
|
||
use YOCLIB\EPP\EPPConnection; | ||
use YOCLIB\EPP\EPPDocument; | ||
use YOCLIB\EPP\EPPDocumentHelper; | ||
|
||
abstract class EPPBaseConnection implements EPPConnection { | ||
|
||
public function readDocument(): EPPDocument{ | ||
$doc = EPPDocumentHelper::createEPPDocument(); | ||
$doc->loadXML($this->readXML()); | ||
return $doc; | ||
} | ||
|
||
public abstract function readXML(): ?string; | ||
|
||
public function writeDocument(EPPDocument $doc): void{ | ||
$this->writeXML($doc->saveXML()); | ||
} | ||
|
||
public abstract function writeXML(string $xml): void; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
namespace YOCLIB\EPP\Connections; | ||
|
||
use RuntimeException; | ||
use YOCLIB\EPP\EPPConnection; | ||
use YOCLIB\EPP\EPPRegistry; | ||
|
||
class EPPTCPConnection extends EPPBaseConnection implements EPPConnection { | ||
|
||
private $registry; | ||
private $socket; | ||
|
||
public function __construct(EPPRegistry $registry){ | ||
$this->registry = $registry; | ||
$this->open(); | ||
} | ||
|
||
/** | ||
* Decode bytes to 32-bit integer | ||
* @param string $data | ||
* @return int | ||
*/ | ||
private function decodeInteger(string $data): int{ | ||
return unpack('N',substr($data,0,4))[1] ?? -1; | ||
} | ||
|
||
/** | ||
* Encode 32-bit integer to bytes | ||
* @param int $integer | ||
* @return string | ||
*/ | ||
private function encodeInteger(int $integer): string{ | ||
return pack('N',$integer); | ||
} | ||
|
||
/** | ||
* Ensure if connection is not closed | ||
*/ | ||
private function ensureConnection(): void{ | ||
if($this->isClosed()){ | ||
throw new RuntimeException('Connection closed'); | ||
} | ||
} | ||
|
||
public function close(): bool{ | ||
$this->ensureConnection(); | ||
return fclose($this->socket); | ||
} | ||
|
||
/** | ||
* Check if connection is closed | ||
* @return bool | ||
*/ | ||
public function isClosed(): bool{ | ||
return !is_resource($this->socket); | ||
} | ||
|
||
public function open(): bool{ | ||
$host = $this->registry->getHost(); | ||
$hostname = parse_url($host,PHP_URL_SCHEME).'://'.parse_url($host,PHP_URL_HOST); | ||
$this->socket = fsockopen($hostname,$this->registry->getPort()); | ||
return $this->socket!==false; | ||
} | ||
|
||
public function readXML(): ?string{ | ||
$this->ensureConnection(); | ||
$length = $this->decodeInteger(fread($this->socket,4))-4; | ||
if($length<0){ | ||
return null; | ||
} | ||
return fread($this->socket,$length); | ||
} | ||
|
||
public function writeXML(string $xml): void{ | ||
$this->ensureConnection(); | ||
$length = strlen($xml)+4; | ||
fwrite($this->socket,$this->encodeInteger($length).$xml); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,20 @@ | ||
<?php | ||
namespace YOCLIB\EPP; | ||
|
||
/** | ||
* Class EPPConnection | ||
* @package YOCLIB\EPP | ||
*/ | ||
class EPPConnection{ | ||
interface EPPConnection{ | ||
|
||
// /** | ||
// * @var resource $resource | ||
// */ | ||
// private $resource; | ||
// | ||
// /** | ||
// * EPPConnection constructor. | ||
// * @param resource $resource | ||
// */ | ||
// public function __construct($resource){ | ||
// $this->resource = $resource; | ||
// } | ||
// | ||
// /** | ||
// * Close the connection | ||
// */ | ||
// public function close(){ | ||
// fclose($this->resource); | ||
// } | ||
// | ||
// /** | ||
// * Convert document elements | ||
// * @param EPPDocument|DOMDocument $doc | ||
// * @return EPPDocument|DOMDocument|null | ||
// */ | ||
// private function convertDOM($doc){ | ||
// return $this->convertElement($doc,$doc->documentElement); | ||
// } | ||
// | ||
// /** | ||
// * @param EPPDocument|DOMDocument $doc | ||
// * @param $element | ||
// * @return EPPDocument|DOMDocument|null | ||
// */ | ||
// private function convertElement($doc,$element){ | ||
// foreach($element->childNodes AS $childNode){ | ||
// if($childNode instanceof DOMElement){ | ||
// $this->convertElement($doc,$childNode); | ||
// } | ||
// } | ||
// return EPPSchemaHelper::convertElement($doc,$element); | ||
// } | ||
// | ||
// /** | ||
// * Decode bytes to 32-bit integer | ||
// * @param string $data | ||
// * @return int | ||
// */ | ||
// private function decodeInteger($data){ | ||
// $int = unpack('N',substr($data,0,4)); | ||
// return $int[1]; | ||
// } | ||
// | ||
// /** | ||
// * Encode 32-bit integer to bytes | ||
// * @param int $data | ||
// * @return string | ||
// */ | ||
// private function encodeInteger($data){ | ||
// $int = pack('N',intval($data)); | ||
// return $int; | ||
// } | ||
// | ||
// /** | ||
// * Ensure if connection is not closed | ||
// */ | ||
// private function ensureConnection(){ | ||
// if(!$this->isClosed()){ | ||
// throw new RuntimeException("Connection closed"); | ||
// } | ||
// } | ||
// | ||
// /** | ||
// * Check if connection is closed | ||
// * @return bool | ||
// */ | ||
// public function isClosed(){ | ||
// return is_resource($this->resource); | ||
// } | ||
// | ||
// /** | ||
// * Read DOM | ||
// * @return EPPDocument|DOMDocument|null | ||
// */ | ||
// public function readDOM(){ | ||
// $doc = new EPPDocument; | ||
// $xml = $this->readXML(); | ||
// $doc->loadXML($xml); | ||
// return $this->convertDOM($doc) ?? $doc; | ||
// } | ||
// | ||
// /** | ||
// * Read XML | ||
// * @return string|null | ||
// */ | ||
// public function readXML(){ | ||
// $this->ensureConnection(); | ||
// $length = $this->decodeInteger(fread($this->resource,4))-4; | ||
// if($length<0){ | ||
// return null; | ||
// } | ||
// return fread($this->resource,$length); | ||
// } | ||
// | ||
// /** | ||
// * Write DOM | ||
// * @param EPPDocument|DOMDocument $doc | ||
// */ | ||
// public function writeDOM($doc){ | ||
// $xml = $doc->saveXML(); | ||
// $this->writeXML($xml); | ||
// } | ||
// | ||
// /** | ||
// * Write XML | ||
// * @param string $xml | ||
// */ | ||
// public function writeXML($xml){ | ||
// $this->ensureConnection(); | ||
// $length = strlen($xml)+4; | ||
// fwrite($this->resource,$this->encodeInteger($length).$xml); | ||
// } | ||
public function close(): bool; | ||
|
||
public function isClosed(): bool; | ||
|
||
public function open(): bool; | ||
|
||
public function readDocument(): EPPDocument; | ||
|
||
public function readXML(): ?string; | ||
|
||
public function writeDocument(EPPDocument $doc): void; | ||
|
||
public function writeXML(string $xml); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
namespace YOCLIB\EPP; | ||
|
||
abstract class EPPRegistry{ | ||
|
||
private $host; | ||
private $port; | ||
|
||
public function __construct(string $host,int $port){ | ||
$this->host = $host; | ||
$this->port = $port; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getHost(): string{ | ||
return $this->host; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getPort(): int{ | ||
return $this->port; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
namespace YOCLIB\EPP\Registries; | ||
|
||
use YOCLIB\EPP\EPPRegistry; | ||
|
||
class EURID extends EPPRegistry { | ||
|
||
public function __construct(){ | ||
parent::__construct('ssl://epp.registry.eu',700); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
namespace YOCLIB\EPP\Registries; | ||
|
||
use YOCLIB\EPP\EPPRegistry; | ||
|
||
class EURIDTest extends EPPRegistry { | ||
|
||
public function __construct(){ | ||
parent::__construct('ssl://epp.tryout.registry.eu',700); | ||
} | ||
|
||
} |
Oops, something went wrong.