Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15379654
D14070.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D14070.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -419,6 +419,7 @@
'phutil_console_prompt' => 'console/format.php',
'phutil_console_require_tty' => 'console/format.php',
'phutil_console_wrap' => 'console/format.php',
+ 'phutil_count' => 'internationalization/pht.php',
'phutil_date_format' => 'utils/viewutils.php',
'phutil_deprecated' => 'moduleutils/moduleutils.php',
'phutil_error_listener_example' => 'error/phlog.php',
diff --git a/src/internationalization/pht.php b/src/internationalization/pht.php
--- a/src/internationalization/pht.php
+++ b/src/internationalization/pht.php
@@ -16,3 +16,18 @@
$translator = PhutilTranslator::getInstance();
return call_user_func_array(array($translator, 'translate'), $args);
}
+
+/**
+ * Count all elements in an array, or something in an object.
+ *
+ * @param array|Countable A countable object.
+ * @return PhutilNumber Returns the number of elements in the input
+ * parameter.
+ */
+function phutil_count($countable) {
+ if (!(is_array($countable) || $countable instanceof Countable)) {
+ throw new InvalidArgumentException(pht('Argument should be countable.'));
+ }
+
+ return new PhutilNumber(count($countable));
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 14, 10:35 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7674249
Default Alt Text
D14070.diff (1 KB)
Attached To
Mode
D14070: Add a `phutil_count` function
Attached
Detach File
Event Timeline
Log In to Comment