setProto( $urlData["scheme"] ); if ( isset( $urlData["host"] ) ) $dwWebUrl->setHost($urlData["host"]); if ( isset( $urlData["path"] ) ) { $dwWebUrl->setBaseUri( $urlData["path"] ); } if ( isset( $urlData["query"] ) && ! empty( $urlData["query"] ) ) { parse_str($urlData["query"], $output ); foreach( $output as $key => $value ) { $dwWebUrl->set($key, $value); } } return $dwWebUrl; } // array( "HTTPS" => on, "HTTP_HOST" => "domain.com", "REQUEST_URI" = "/index?key=value&keyB=values" ) // TODO: for bakuba aligne : /* public static fromDwHttpRequest( DwHttpRequest $dwHttpRequest = null ) : self { $dwWebUrl = null; if ( is_null( $dwHttpRequest ) ) $dwWebUrl=new DwWebUrl(); else $dwWebUrl= new DwWebUrl( $dwHttpRequest->getRqtHttps() ? "https" : "http" ,$dwHttpRequest->getSrvPort()->getPort() ,$dwHttpRequest->getRqtHost() ); return $dwWebUrl; } */ // public static fromApache2Request( array $server = null ) : self { $dwWebUrl = null; if ( is_null( $server ) ) $dwWebUrl=new DwWebUrl(); else { $port=null; $hostWithPort = explode( ":" ,$server["HTTP_HOST"] ); if ( isset($hostWithPort[1]) ) $port=intval($hostWithPort[1]); $host = $hostWithPort[0]; if ( isset( $server['HTTPS'] ) && ! empty($server['HTTPS']) ) { $proto = "https"; isnull( $port ) and $port = 443; } else { $proto = "http"; isnull( $port ) and $port = 80; } $uri = isset($server["REQUEST_URI"]) ? explode( "?", $server["REQUEST_URI"] )[0] : "/"; $dwWebUrl= new DwWebUrl( $proto ,$port ,$host ,$uri ); } return $dwWebUrl; } public function __construct( string $proto = null ,int $port = null, string $host = null, string $uri = null ) { $this->setProto(); $this->setPort(); $this->setHost(); $this->setBaseUri(); if ( ! is_null( $proto ) ) $this->setProto( $proto ); if ( ! is_null( $port ) ) $this->setPort( $port ); if ( ! is_null( $host ) ) $this->setHost( $host ); if ( ! is_null( $uri ) ) $this->setBaseUri( $uri ); } public function setProto( string $proto = "https" ) : void { $this->proto = $proto; } public function getPort() : int { return $this->port; } public function setPort( int $port = 80 ) { $this->port = $port; } public function getProto() : string { return $this->proto; } public function setHost( string $host = "darkweb.fr" ) : void { $this->host = $host; } public function getHost() : string { return $this->host; } public function setBaseUri( $baseUri = "/" ) :void { $this->baseUri = $baseUri; } public function changeType($type) : void { $this->baseUri = explode( ".", $this->baseUri )[0].".".$type; } public function set( $key, $value ) : void { $this->params[ "".$key ] = $value; } public function getParams( ) : array { return $this->params; } public function unset( $key ) : void { unset($this->params[ "".$key ]); } public function getUrl() { $notPortPrint=false; if ( is_null($this->port) ) $notPortPrint=true; else { if ( $this->proto == "https" && $this->port==443 ) $notPortPrint=true; elseif ( $this->proto == "http" && $this->port==80 ) $notPortPrint=true; } if ( $notPortPrint) $url = "{$this->proto}://{$this->host}{$this->baseUri}"; else $url = "{$this->proto}://{$this->host}:{$this->port}{$this->baseUri}"; return $url; } public function getUrlQuery() : string { $urlQuery = ""; if ( !empty($this->params )) foreach( $this->params as $key => $value ) if ( empty($urlQuery) ) $urlQuery="?{$key}={$value}"; else $urlQuery.= "&{$key}={$value}"; return $urlQuery; } public function toString() : string { return $this->getUrl().$this->getUrlQuery(); } public function __toString() : string { return $this->toString(); } public function __destruct() { //$this->log->trace( "." ); //parent::__destruct(); foreach( $this as $key => $toDestruct ) if ( isset( $this->$key ) ) unset( $this->$key ); } public function getClassName( bool $fqcn=null ) : string { return self::getStaticClassName( $fqcn ); } public static function getStaticClassName( bool $fqcn=null ) : string { return __CLASS__; } }