Changeset View
Changeset View
Standalone View
Standalone View
src/utils/PhutilArrayCheck.php
| Show All 23 Lines | public function setUniqueMethod($unique_method) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getUniqueMethod() { | public function getUniqueMethod() { | ||||
| return $this->uniqueMethod; | return $this->uniqueMethod; | ||||
| } | } | ||||
| public function setContext($object, $method) { | 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( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Expected an object or string for "object" context, got "%s".', | '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, string, or list of objects for "object" '. | |||||
| 'context, got "%s".', | |||||
| phutil_describe_type($object))); | phutil_describe_type($object))); | ||||
| } | } | ||||
| if (!is_string($method)) { | if (!is_string($method)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Expected a string for "method" context, got "%s".', | 'Expected a string for "method" context, got "%s".', | ||||
| phutil_describe_type($method))); | phutil_describe_type($method))); | ||||
| ▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | final class PhutilArrayCheck | ||||
| private function raiseValueException($message) { | private function raiseValueException($message) { | ||||
| $context = $this->context; | $context = $this->context; | ||||
| $object = $context['object']; | $object = $context['object']; | ||||
| $method = $context['method']; | $method = $context['method']; | ||||
| $argv = $context['argv']; | $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( | $object_display = sprintf( | ||||
| '%s->%s', | '%s->%s', | ||||
| get_class($object), | get_class($object), | ||||
| $method); | $method); | ||||
| } else { | } else { | ||||
| $object_display = sprintf( | $object_display = sprintf( | ||||
| '%s::%s', | '%s::%s', | ||||
| $object, | $object, | ||||
| Show All 21 Lines | |||||