- substr: documentation ( source)
- var_dump: documentation ( source)
- strpos: documentation ( source)
- explode: documentation ( source)
<?php
class NewEraProxy {
private $proxy_full_url;
private $proxy_protocol;
private $proxy_ssl;
private $proxy_name;
private $proxy_port;
/** Constructor */
public function __construct($proxy_full_url) {
$this->update_object($proxy_full_url);
}
/** Object updater */
public function update_object($proxy_full_url) {
$this->proxy_full_url = $proxy_full_url;
$this->proxy_ssl = ((strpos($this->proxy_full_url, 'ssl') === 0) ? true : false);
$this->proxy_protocol = ($this->proxy_ssl ? 'ssl' : 'tcp');
// Grab other parameters
if(false !== ($tmp = strpos($proxy_full_url, '://')))
$proxy_full_url = substr($proxy_full_url, $tmp + 3);
$proxy_full_url = explode(':', $proxy_full_url);
// Host, Port, Path
$this->proxy_name = $proxy_full_url[0];
$this->proxy_port = (int)(isset($proxy_full_url[1]) ? $proxy_full_url[1] : ($this->proxy_ssl ? '443' : '80'));
}
/** Getter for the private properties */
public function __get($var) {
$var = 'proxy_'.$var;
if(isset($this->{$var}))
return $this->{$var};
}
}
$newEraProxy = new NewEraProxy('tcp://127.0.0.1:8080');
var_dump($newEraProxy);
var_dump($newEraProxy->full_url);
var_dump($newEraProxy->protocol);
var_dump($newEraProxy->ssl);
var_dump($newEraProxy->name);
var_dump($newEraProxy->port);
var_dump($newEraProxy->non_existent_property);