Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F552463
PhabricatorHandlePool.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
PhabricatorHandlePool.php
View Options
<?php
/**
* Coordinates loading object handles.
*
* This is a low-level piece of plumbing which code will not normally interact
* with directly. For discussion of the handle pool mechanism, see
* @{class:PhabricatorHandleList}.
*/
final
class
PhabricatorHandlePool
extends
Phobject
{
private
$viewer
;
private
$handles
=
array
();
private
$unloadedPHIDs
=
array
();
public
function
setViewer
(
PhabricatorUser
$user
)
{
$this
->
viewer
=
$user
;
return
$this
;
}
public
function
getViewer
()
{
return
$this
->
viewer
;
}
public
function
newHandleList
(
array
$phids
)
{
// Mark any PHIDs we haven't loaded yet as unloaded. This will let us bulk
// load them later.
foreach
(
$phids
as
$phid
)
{
if
(
empty
(
$this
->
handles
[
$phid
]))
{
$this
->
unloadedPHIDs
[
$phid
]
=
true
;
}
}
$unique
=
array
();
foreach
(
$phids
as
$phid
)
{
$unique
[
$phid
]
=
$phid
;
}
return
id
(
new
PhabricatorHandleList
())
->
setHandlePool
(
$this
)
->
setPHIDs
(
array_values
(
$unique
));
}
public
function
loadPHIDs
(
array
$phids
)
{
$need
=
array
();
foreach
(
$phids
as
$phid
)
{
if
(
empty
(
$this
->
handles
[
$phid
]))
{
$need
[
$phid
]
=
true
;
}
}
foreach
(
$need
as
$phid
=>
$ignored
)
{
if
(
empty
(
$this
->
unloadedPHIDs
[
$phid
]))
{
throw
new
Exception
(
pht
(
'Attempting to load PHID "%s", but it was not requested by any '
.
'handle list.'
,
$phid
));
}
}
// If we need any handles, bulk load everything in the queue.
if
(
$need
)
{
// Clear the list of PHIDs that need to be loaded before performing the
// actual fetch. This prevents us from looping if we need to reenter the
// HandlePool while loading handles.
$fetch_phids
=
array_keys
(
$this
->
unloadedPHIDs
);
$this
->
unloadedPHIDs
=
array
();
$handles
=
id
(
new
PhabricatorHandleQuery
())
->
setViewer
(
$this
->
getViewer
())
->
withPHIDs
(
$fetch_phids
)
->
execute
();
$this
->
handles
+=
$handles
;
}
return
array_select_keys
(
$this
->
handles
,
$phids
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 12, 4:26 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
105130
Default Alt Text
PhabricatorHandlePool.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment