1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 00:02:40 +01:00

Allow PhutilArrayCheck to accept a list of objects as a context

Summary: This simplifies merging a list-of-lists, which is a common pattern when asking a list of extensions to each provide some kind of list of items.

Test Plan: Used elsewhere in Piledriver.

Differential Revision: https://secure.phabricator.com/D21294
This commit is contained in:
epriestley 2020-05-28 11:07:51 -07:00
parent a0c346bf63
commit 0da1a2e17d

View file

@ -29,10 +29,24 @@ final class PhutilArrayCheck
}
public function setContext($object, $method) {
if (!is_object($object) && !is_string($object)) {
if (is_array($object)) {
foreach ($object as $idx => $value) {
if (!is_object($value)) {
throw new Exception(
pht(
'Expected an object, string, or list of objects for "object" '.
'context. Got a list ("%s"), but the list item at index '.
'"%s" (with type "%s") is not an object.',
phutil_describe_type($object),
$idx,
phutil_describe_type($value)));
}
}
} else if (!is_object($object) && !is_string($object)) {
throw new Exception(
pht(
'Expected an object or string for "object" context, got "%s".',
'Expected an object, string, or list of objects for "object" '.
'context, got "%s".',
phutil_describe_type($object)));
}
@ -219,7 +233,20 @@ final class PhutilArrayCheck
$method = $context['method'];
$argv = $context['argv'];
if (is_object($object)) {
if (is_array($object)) {
$classes = array();
foreach ($object as $item) {
$classes[] = get_class($item);
}
$classes = array_fuse($classes);
$n = count($object);
$object_display = sprintf(
'[%s]<%d>->%s',
implode(', ', $classes),
$n,
$method);
} else if (is_object($object)) {
$object_display = sprintf(
'%s->%s',
get_class($object),