Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90668245
PhabricatorPHID.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Nov 3, 17:45
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Nov 5, 17:45 (2 d)
Engine
blob
Format
Raw Data
Handle
22117056
Attached To
rPH Phabricator
PhabricatorPHID.php
View Options
<?php
final
class
PhabricatorPHID
{
protected
$phid
;
protected
$phidType
;
protected
$ownerPHID
;
protected
$parentPHID
;
public
static
function
generateNewPHID
(
$type
,
$subtype
=
null
)
{
if
(!
$type
)
{
throw
new
Exception
(
"Can not generate PHID with no type."
);
}
if
(
$subtype
===
null
)
{
$uniq_len
=
20
;
$type_str
=
"{$type}"
;
}
else
{
$uniq_len
=
15
;
$type_str
=
"{$type}-{$subtype}"
;
}
$uniq
=
Filesystem
::
readRandomCharacters
(
$uniq_len
);
return
"PHID-{$type_str}-{$uniq}"
;
}
public
static
function
fromObjectName
(
$name
,
PhabricatorUser
$viewer
)
{
$query
=
id
(
new
PhabricatorObjectQuery
())
->
setViewer
(
$viewer
)
->
withNames
(
array
(
$name
));
$query
->
execute
();
$objects
=
$query
->
getNamedResults
();
if
(
$objects
)
{
return
head
(
$objects
)->
getPHID
();
}
/// TODO: Destroy this legacy stuff.
$object
=
null
;
$match
=
null
;
if
(
preg_match
(
'/^PHID-[A-Z]+-.{20}$/'
,
$name
))
{
// It's already a PHID! Yay.
return
$name
;
}
if
(
$object
)
{
return
$object
->
getPHID
();
}
return
null
;
}
}
Event Timeline
Log In to Comment