Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F540146
PhutilURIHelper.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilURIHelper.php
View Options
<?php
/**
* A simple wrapper for PhutilURI, to be aware of the
* relative/absolute context, and other minor things.
*/
final
class
PhutilURIHelper
extends
Phobject
{
/**
* String version of your original URI.
* @var string
*/
private
$uriStr
;
/**
* Structured version of your URI.
* @var PhutilURI
*/
private
$phutilUri
;
/**
* @param string|PhutilURI $uri
*/
public
function
__construct
(
$uri
)
{
// Keep the original string for basic checks.
$this
->
uriStr
=
phutil_string_cast
(
$uri
);
// A PhutilURI may be useful. If available, import that as-is.
// Note that the constructor PhutilURI(string) is a bit expensive.
if
(
$uri
instanceof
PhutilURI
)
{
$this
->
phutilUri
=
$uri
;
}
}
/**
* Check if the URI points to Phorge itself.
* @return bool
*/
public
function
isSelf
()
{
// The backend prefers a PhutilURI object, if available.
$uri
=
$this
->
phutilUri
?
$this
->
phutilUri
:
$this
->
uriStr
;
return
PhabricatorEnv
::
isSelfURI
(
$uri
);
}
/**
* Check whenever an URI is just a simple fragment without path and protocol.
* @return bool
*/
public
function
isAnchor
()
{
return
$this
->
isStartingWithChar
(
'#'
);
}
/**
* Check whenever an URI starts with a slash (no protocol, etc.)
* @return bool
*/
public
function
isStartingWithSlash
()
{
return
$this
->
isStartingWithChar
(
'/'
);
}
/**
* A sane default.
*/
public
function
__toString
()
{
return
$this
->
uriStr
;
}
/**
* Check whenever the URI starts with the provided character.
* @param string $char String that MUST have length of 1.
* @return bool
*/
private
function
isStartingWithChar
(
$char
)
{
return
strncmp
(
$this
->
uriStr
,
$char
,
1
)
===
0
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 12, 9:27 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
120425
Default Alt Text
PhutilURIHelper.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment