File modules/util/Url.class.php

Last commit: Fri Sep 18 22:48:46 2020 +0200	Jan Dankert	Refactoring: Every project has 1 publishing target.
1 <?php 2 3 namespace util; 4 5 class Url { 6 7 public $scheme; 8 public $host; 9 public $port; 10 public $user; 11 public $pass; 12 public $path; 13 public $query; 14 public $fragment; 15 16 function __construct( $url = null ) { 17 18 if ( !empty($url) ) 19 $this->parseUrl($url); 20 } 21 22 23 public function parseUrl( $url ) { 24 foreach ( parse_url($url) as $key=>$value ) 25 $this->$key = $value; 26 } 27 28 29 public function __toString() 30 { 31 $scheme = !empty($this->scheme) ? $this->scheme . '://' : ''; 32 33 if ( empty($scheme) ) 34 $scheme = 'file:/'; 35 36 $host = !empty($this->host ) ? $this->host : ''; 37 $port = !empty($this->port ) ? ':' . $this->port : ''; 38 $user = !empty($this->user ) ? $this->user : ''; 39 $pass = !empty($this->pass ) ? ':' . $this->pass : ''; 40 $pass = ($user || $pass) ? "$pass@" : ''; 41 $path = !empty($this->path ) ? $this->path : ''; 42 $query = !empty($this->query ) ? '?' . $this->query : ''; 43 $fragment = !empty($this->fragment) ? '#' . $this->fragment : ''; 44 45 return "$scheme$user$pass$host$port$path$query$fragment"; 46 } 47 48 }
Download modules/util/Url.class.php
History Fri, 18 Sep 2020 22:48:46 +0200 Jan Dankert Refactoring: Every project has 1 publishing target.