Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92657127
PhabricatorRemarkupRuleObjectHandle.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
Fri, Nov 22, 11:27
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Nov 24, 11:27 (2 d)
Engine
blob
Format
Raw Data
Handle
22479739
Attached To
rPH Phabricator
PhabricatorRemarkupRuleObjectHandle.php
View Options
<?php
/**
* @group markup
*/
abstract
class
PhabricatorRemarkupRuleObjectHandle
extends
PhutilRemarkupRule
{
const
KEY_RULE_HANDLE
=
'rule.handle'
;
abstract
protected
function
getObjectNamePrefix
();
abstract
protected
function
loadObjectPHID
(
$id
);
public
function
apply
(
$text
)
{
$prefix
=
$this
->
getObjectNamePrefix
();
return
$this
->
replaceHTML
(
"@
\B
{{$prefix}(
\d
+)}
\B
@"
,
array
(
$this
,
'markupObjectHandle'
),
$text
);
}
protected
function
markupObjectHandle
(
$matches
)
{
// TODO: These are single gets but should be okay for now, they're behind
// the cache.
$phid
=
$this
->
loadObjectPHID
(
$matches
[
1
]);
if
(!
$phid
)
{
return
$matches
[
0
];
}
$engine
=
$this
->
getEngine
();
$token
=
$engine
->
storeText
(
''
);
$metadata_key
=
self
::
KEY_RULE_HANDLE
;
$metadata
=
$engine
->
getTextMetadata
(
$metadata_key
,
array
());
if
(
empty
(
$metadata
[
$phid
]))
{
$metadata
[
$phid
]
=
array
();
}
$metadata
[
$phid
][]
=
$token
;
$engine
->
setTextMetadata
(
$metadata_key
,
$metadata
);
return
$token
;
}
public
function
didMarkupText
()
{
$engine
=
$this
->
getEngine
();
$metadata_key
=
self
::
KEY_RULE_HANDLE
;
$metadata
=
$engine
->
getTextMetadata
(
$metadata_key
,
array
());
if
(
empty
(
$metadata
))
{
return
;
}
$handles
=
id
(
new
PhabricatorObjectHandleData
(
array_keys
(
$metadata
)))
->
loadHandles
();
foreach
(
$metadata
as
$phid
=>
$tokens
)
{
$link
=
$handles
[
$phid
]->
renderLink
();
foreach
(
$tokens
as
$token
)
{
$engine
->
overwriteStoredText
(
$token
,
$link
);
}
}
$engine
->
setTextMetadata
(
$metadata_key
,
array
());
}
}
Event Timeline
Log In to Comment