1 | <?php |
||
13 | class SMWDIUri extends SMWDataItem { |
||
|
|||
14 | |||
15 | /** |
||
16 | * URI scheme such as "html" or "mailto". |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $m_scheme; |
||
20 | /** |
||
21 | * "Hierpart" of the URI (usually some authority and path). |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $m_hierpart; |
||
25 | /** |
||
26 | * Query part of the URI. |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $m_query; |
||
30 | /** |
||
31 | * Fragment part of the URI. |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $m_fragment; |
||
35 | |||
36 | /** |
||
37 | * Initialise a URI by providing its scheme (e.g. "html"), 'hierpart' |
||
38 | * following "scheme:" (e.g. "//[email protected]/path), query (e.g. |
||
39 | * "q=Search+term", and fragment (e.g. "section-one"). The complete URI |
||
40 | * with these examples would be |
||
41 | * http://[email protected]/path?q=Search+term#section-one |
||
42 | * @param $scheme string for the scheme |
||
43 | * @param $hierpart string for the "hierpart" |
||
44 | * @param $query string for the query |
||
45 | * @param $fragment string for the fragment |
||
46 | * |
||
47 | * @todo Implement more validation here. |
||
48 | */ |
||
49 | 131 | public function __construct( $scheme, $hierpart, $query, $fragment ) { |
|
61 | |||
62 | 131 | public function getDIType() { |
|
65 | |||
66 | /// @todo This should be changed to the spelling getUri(). |
||
67 | 131 | public function getURI() { |
|
68 | $schemesWithDoubleslesh = array( |
||
69 | 131 | 'http', 'https', 'ftp' |
|
70 | ); |
||
71 | |||
72 | 131 | $uri = $this->m_scheme . ':' |
|
73 | 131 | . ( in_array( $this->m_scheme, $schemesWithDoubleslesh ) ? '//' : '' ) |
|
74 | 131 | . $this->m_hierpart |
|
75 | 131 | . ( $this->m_query ? '?' . $this->m_query : '' ) |
|
76 | 131 | . ( $this->m_fragment ? '#' . $this->m_fragment : '' ); |
|
77 | |||
78 | 131 | return $uri; |
|
79 | } |
||
80 | |||
81 | 19 | public function getScheme() { |
|
84 | |||
85 | 5 | public function getHierpart() { |
|
88 | |||
89 | 5 | public function getQuery() { |
|
92 | |||
93 | 128 | public function getFragment() { |
|
96 | |||
97 | public function getSortKey() { |
||
100 | |||
101 | 131 | public function getSerialization() { |
|
104 | |||
105 | /** |
||
106 | * Create a data item from the provided serialization string and type |
||
107 | * ID. |
||
108 | * @return SMWDIUri |
||
109 | */ |
||
110 | 29 | public static function doUnserialize( $serialization ) { |
|
111 | 29 | $parts = explode( ':', $serialization, 2 ); // try to split "schema:rest" |
|
112 | 29 | if ( count( $parts ) <= 1 ) { |
|
113 | throw new DataItemException( "Unserialization failed: the string \"$serialization\" is no valid URI." ); |
||
114 | } |
||
115 | 29 | $scheme = $parts[0]; |
|
116 | 29 | $parts = explode( '?', $parts[1], 2 ); // try to split "hier-part?queryfrag" |
|
117 | 29 | if ( count( $parts ) == 2 ) { |
|
118 | $hierpart = $parts[0]; |
||
119 | $parts = explode( '#', $parts[1], 2 ); // try to split "query#frag" |
||
120 | $query = $parts[0]; |
||
121 | $fragment = ( count( $parts ) == 2 ) ? $parts[1] : ''; |
||
122 | } else { |
||
123 | 29 | $query = ''; |
|
124 | 29 | $parts = explode( '#', $parts[0], 2 ); // try to split "hier-part#frag" |
|
125 | 29 | $hierpart = $parts[0]; |
|
126 | 29 | $fragment = ( count( $parts ) == 2 ) ? $parts[1] : ''; |
|
127 | } |
||
128 | |||
129 | 29 | $hierpart = ltrim( $hierpart, '/' ); |
|
130 | |||
131 | 29 | return new SMWDIUri( $scheme, $hierpart, $query, $fragment ); |
|
132 | } |
||
133 | |||
134 | 1 | public function equals( SMWDataItem $di ) { |
|
141 | } |
||
142 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.