ArrayUtils.php
2 years ago
CartController.php
2 years ago
CheckoutTrait.php
2 years ago
DraftOrderTrait.php
2 years ago
JsonWebToken.php
2 years ago
LocalPickupUtils.php
2 years ago
NoticeHandler.php
2 years ago
OrderAuthorizationTrait.php
2 years ago
OrderController.php
2 years ago
Pagination.php
2 years ago
ProductItemTrait.php
2 years ago
ProductQuery.php
2 years ago
ProductQueryFilters.php
2 years ago
QuantityLimits.php
2 years ago
RateLimits.php
2 years ago
ValidationUtils.php
2 years ago
ArrayUtils.php
37 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Utilities; |
| 3 | |
| 4 | /** |
| 5 | * ArrayUtils class used for custom functions to operate on arrays |
| 6 | */ |
| 7 | class ArrayUtils { |
| 8 | /** |
| 9 | * Join a string with a natural language conjunction at the end. |
| 10 | * |
| 11 | * @param array $array The array to join together with the natural language conjunction. |
| 12 | * @param bool $enclose_items_with_quotes Whether each item in the array should be enclosed within quotation marks. |
| 13 | * |
| 14 | * @return string a string containing a list of items and a natural language conjuction. |
| 15 | */ |
| 16 | public static function natural_language_join( $array, $enclose_items_with_quotes = false ) { |
| 17 | if ( true === $enclose_items_with_quotes ) { |
| 18 | $array = array_map( |
| 19 | function( $item ) { |
| 20 | return '"' . $item . '"'; |
| 21 | }, |
| 22 | $array |
| 23 | ); |
| 24 | } |
| 25 | $last = array_pop( $array ); |
| 26 | if ( $array ) { |
| 27 | return sprintf( |
| 28 | /* translators: 1: The first n-1 items of a list 2: the last item in the list. */ |
| 29 | __( '%1$s and %2$s', 'woocommerce' ), |
| 30 | implode( ', ', $array ), |
| 31 | $last |
| 32 | ); |
| 33 | } |
| 34 | return $last; |
| 35 | } |
| 36 | } |
| 37 |