@@ -18,84 +18,84 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | class GravityView_Edit_Entry { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | 24 | static $file; |
| 25 | 25 | |
| 26 | 26 | static $instance; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Component instances. |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - public $instances = array(); |
|
| 28 | + /** |
|
| 29 | + * Component instances. |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + public $instances = array(); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | function __construct() { |
| 36 | 36 | |
| 37 | - self::$file = plugin_dir_path( __FILE__ ); |
|
| 37 | + self::$file = plugin_dir_path( __FILE__ ); |
|
| 38 | 38 | |
| 39 | - if( is_admin() ) { |
|
| 40 | - $this->load_components( 'admin' ); |
|
| 41 | - } |
|
| 39 | + if( is_admin() ) { |
|
| 40 | + $this->load_components( 'admin' ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | $this->load_components( 'locking' ); |
| 44 | 44 | |
| 45 | - $this->load_components( 'render' ); |
|
| 45 | + $this->load_components( 'render' ); |
|
| 46 | 46 | |
| 47 | - // If GF User Registration Add-on exists |
|
| 48 | - $this->load_components( 'user-registration' ); |
|
| 47 | + // If GF User Registration Add-on exists |
|
| 48 | + $this->load_components( 'user-registration' ); |
|
| 49 | 49 | |
| 50 | - $this->add_hooks(); |
|
| 50 | + $this->add_hooks(); |
|
| 51 | 51 | |
| 52 | 52 | // Process hooks for addons that may or may not be present |
| 53 | 53 | $this->addon_specific_hooks(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - static function getInstance() { |
|
| 57 | + static function getInstance() { |
|
| 58 | 58 | |
| 59 | - if( empty( self::$instance ) ) { |
|
| 60 | - self::$instance = new GravityView_Edit_Entry; |
|
| 61 | - } |
|
| 59 | + if( empty( self::$instance ) ) { |
|
| 60 | + self::$instance = new GravityView_Edit_Entry; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return self::$instance; |
|
| 64 | - } |
|
| 63 | + return self::$instance; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - private function load_components( $component ) { |
|
| 67 | + private function load_components( $component ) { |
|
| 68 | 68 | |
| 69 | - $dir = trailingslashit( self::$file ); |
|
| 69 | + $dir = trailingslashit( self::$file ); |
|
| 70 | 70 | |
| 71 | - $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 72 | - $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 71 | + $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 72 | + $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 73 | 73 | |
| 74 | - // Loads component and pass extension's instance so that component can |
|
| 75 | - // talk each other. |
|
| 76 | - require_once $filename; |
|
| 77 | - $this->instances[ $component ] = new $classname( $this ); |
|
| 78 | - $this->instances[ $component ]->load(); |
|
| 74 | + // Loads component and pass extension's instance so that component can |
|
| 75 | + // talk each other. |
|
| 76 | + require_once $filename; |
|
| 77 | + $this->instances[ $component ] = new $classname( $this ); |
|
| 78 | + $this->instances[ $component ]->load(); |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - private function add_hooks() { |
|
| 82 | + private function add_hooks() { |
|
| 83 | 83 | |
| 84 | - // Add front-end access to Gravity Forms delete file action |
|
| 85 | - add_action( 'wp_ajax_nopriv_rg_delete_file', array( $this, 'delete_file') ); |
|
| 84 | + // Add front-end access to Gravity Forms delete file action |
|
| 85 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( $this, 'delete_file') ); |
|
| 86 | 86 | |
| 87 | - // Make sure this hook is run for non-admins |
|
| 88 | - add_action( 'wp_ajax_rg_delete_file', array( $this, 'delete_file') ); |
|
| 87 | + // Make sure this hook is run for non-admins |
|
| 88 | + add_action( 'wp_ajax_rg_delete_file', array( $this, 'delete_file') ); |
|
| 89 | 89 | |
| 90 | - add_filter( 'gravityview_blocklist_field_types', array( $this, 'modify_field_blocklist' ), 10, 2 ); |
|
| 90 | + add_filter( 'gravityview_blocklist_field_types', array( $this, 'modify_field_blocklist' ), 10, 2 ); |
|
| 91 | 91 | |
| 92 | - // add template path to check for field |
|
| 93 | - add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 92 | + // add template path to check for field |
|
| 93 | + add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 94 | 94 | |
| 95 | 95 | add_filter( 'gravityview/field/is_visible', array( $this, 'maybe_not_visible' ), 10, 3 ); |
| 96 | 96 | |
| 97 | 97 | add_filter( 'gravityview/api/reserved_query_args', array( $this, 'add_reserved_arg' ) ); |
| 98 | - } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Adds "edit" to the list of internal reserved query args |
@@ -166,87 +166,87 @@ discard block |
||
| 166 | 166 | return false; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Include this extension templates path |
|
| 171 | - * @param array $file_paths List of template paths ordered |
|
| 172 | - */ |
|
| 173 | - public function add_template_path( $file_paths ) { |
|
| 174 | - |
|
| 175 | - // Index 100 is the default GravityView template path. |
|
| 176 | - $file_paths[ 110 ] = self::$file; |
|
| 177 | - |
|
| 178 | - return $file_paths; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * |
|
| 183 | - * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 184 | - * |
|
| 185 | - * @param $view_id int GravityView view id |
|
| 186 | - * @param $form_id int Gravity Forms form id |
|
| 187 | - * @param $entry_id int Gravity Forms entry id |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 191 | - return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * The edit entry link creates a secure link with a nonce |
|
| 197 | - * |
|
| 198 | - * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 199 | - * it formats the display of the edit form like it does in the backend, like |
|
| 200 | - * "You can edit this post from the post page" fields, for example. |
|
| 201 | - * |
|
| 202 | - * @param $entry array Gravity Forms entry object |
|
| 203 | - * @param $view_id int GravityView view id |
|
| 204 | - * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 205 | - * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 209 | - |
|
| 210 | - $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 211 | - |
|
| 212 | - $base = gv_entry_link( $entry, $post_id ? : $view_id ); |
|
| 213 | - |
|
| 214 | - $url = add_query_arg( array( |
|
| 215 | - 'edit' => wp_create_nonce( $nonce_key ) |
|
| 216 | - ), $base ); |
|
| 217 | - |
|
| 218 | - if ( $post_id ) { |
|
| 219 | - $url = add_query_arg( array( 'gvid' => $view_id ), $url ); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Allow passing params to dynamically populate entry with values |
|
| 224 | - * @since 1.9.2 |
|
| 225 | - */ |
|
| 226 | - if( !empty( $field_values ) ) { |
|
| 227 | - |
|
| 228 | - if( is_array( $field_values ) ) { |
|
| 229 | - // If already an array, no parse_str() needed |
|
| 230 | - $params = $field_values; |
|
| 231 | - } else { |
|
| 232 | - parse_str( $field_values, $params ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $url = add_query_arg( $params, $url ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @filter `gravityview/edit/link` Filter the edit URL link. |
|
| 240 | - * |
|
| 241 | - * @since 2.14.6 Added $post param. |
|
| 242 | - * |
|
| 243 | - * @param string $url The url. |
|
| 244 | - * @param array $entry The entry. |
|
| 245 | - * @param \GV\View $view The View. |
|
| 246 | - * @param WP_Post|null WP_Post $post WP post. |
|
| 247 | - */ |
|
| 248 | - return apply_filters( 'gravityview/edit/link', $url, $entry, \GV\View::by_id( $view_id ), get_post( $view_id ) ); |
|
| 249 | - } |
|
| 169 | + /** |
|
| 170 | + * Include this extension templates path |
|
| 171 | + * @param array $file_paths List of template paths ordered |
|
| 172 | + */ |
|
| 173 | + public function add_template_path( $file_paths ) { |
|
| 174 | + |
|
| 175 | + // Index 100 is the default GravityView template path. |
|
| 176 | + $file_paths[ 110 ] = self::$file; |
|
| 177 | + |
|
| 178 | + return $file_paths; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * |
|
| 183 | + * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 184 | + * |
|
| 185 | + * @param $view_id int GravityView view id |
|
| 186 | + * @param $form_id int Gravity Forms form id |
|
| 187 | + * @param $entry_id int Gravity Forms entry id |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 191 | + return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * The edit entry link creates a secure link with a nonce |
|
| 197 | + * |
|
| 198 | + * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 199 | + * it formats the display of the edit form like it does in the backend, like |
|
| 200 | + * "You can edit this post from the post page" fields, for example. |
|
| 201 | + * |
|
| 202 | + * @param $entry array Gravity Forms entry object |
|
| 203 | + * @param $view_id int GravityView view id |
|
| 204 | + * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 205 | + * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 209 | + |
|
| 210 | + $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 211 | + |
|
| 212 | + $base = gv_entry_link( $entry, $post_id ? : $view_id ); |
|
| 213 | + |
|
| 214 | + $url = add_query_arg( array( |
|
| 215 | + 'edit' => wp_create_nonce( $nonce_key ) |
|
| 216 | + ), $base ); |
|
| 217 | + |
|
| 218 | + if ( $post_id ) { |
|
| 219 | + $url = add_query_arg( array( 'gvid' => $view_id ), $url ); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Allow passing params to dynamically populate entry with values |
|
| 224 | + * @since 1.9.2 |
|
| 225 | + */ |
|
| 226 | + if( !empty( $field_values ) ) { |
|
| 227 | + |
|
| 228 | + if( is_array( $field_values ) ) { |
|
| 229 | + // If already an array, no parse_str() needed |
|
| 230 | + $params = $field_values; |
|
| 231 | + } else { |
|
| 232 | + parse_str( $field_values, $params ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $url = add_query_arg( $params, $url ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @filter `gravityview/edit/link` Filter the edit URL link. |
|
| 240 | + * |
|
| 241 | + * @since 2.14.6 Added $post param. |
|
| 242 | + * |
|
| 243 | + * @param string $url The url. |
|
| 244 | + * @param array $entry The entry. |
|
| 245 | + * @param \GV\View $view The View. |
|
| 246 | + * @param WP_Post|null WP_Post $post WP post. |
|
| 247 | + */ |
|
| 248 | + return apply_filters( 'gravityview/edit/link', $url, $entry, \GV\View::by_id( $view_id ), get_post( $view_id ) ); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | 252 | * @depecated 2.14 Use {@see GravityView_Edit_Entry::modify_field_blocklist()} |
@@ -337,19 +337,19 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * checks if user has permissions to edit a specific entry |
|
| 342 | - * |
|
| 343 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 344 | - * |
|
| 345 | - * @param array $entry Gravity Forms entry array |
|
| 346 | - * @param \GV\View|int $view ID of the view you want to check visibility against {@since 1.9.2}. Required since 2.0 |
|
| 347 | - * @return bool |
|
| 348 | - */ |
|
| 349 | - public static function check_user_cap_edit_entry( $entry, $view = 0 ) { |
|
| 340 | + /** |
|
| 341 | + * checks if user has permissions to edit a specific entry |
|
| 342 | + * |
|
| 343 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 344 | + * |
|
| 345 | + * @param array $entry Gravity Forms entry array |
|
| 346 | + * @param \GV\View|int $view ID of the view you want to check visibility against {@since 1.9.2}. Required since 2.0 |
|
| 347 | + * @return bool |
|
| 348 | + */ |
|
| 349 | + public static function check_user_cap_edit_entry( $entry, $view = 0 ) { |
|
| 350 | 350 | |
| 351 | - // No permission by default |
|
| 352 | - $user_can_edit = false; |
|
| 351 | + // No permission by default |
|
| 352 | + $user_can_edit = false; |
|
| 353 | 353 | |
| 354 | 354 | // get user_edit setting |
| 355 | 355 | if ( empty( $view ) ) { |
@@ -367,60 +367,60 @@ discard block |
||
| 367 | 367 | $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - // If they can edit any entries (as defined in Gravity Forms) |
|
| 371 | - // Or if they can edit other people's entries |
|
| 372 | - // Then we're good. |
|
| 373 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 370 | + // If they can edit any entries (as defined in Gravity Forms) |
|
| 371 | + // Or if they can edit other people's entries |
|
| 372 | + // Then we're good. |
|
| 373 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 374 | 374 | |
| 375 | - gravityview()->log->debug( 'User has ability to edit all entries.' ); |
|
| 375 | + gravityview()->log->debug( 'User has ability to edit all entries.' ); |
|
| 376 | 376 | |
| 377 | - $user_can_edit = true; |
|
| 377 | + $user_can_edit = true; |
|
| 378 | 378 | |
| 379 | - } else if( !isset( $entry['created_by'] ) ) { |
|
| 379 | + } else if( !isset( $entry['created_by'] ) ) { |
|
| 380 | 380 | |
| 381 | - gravityview()->log->error( 'Entry `created_by` doesn\'t exist.'); |
|
| 381 | + gravityview()->log->error( 'Entry `created_by` doesn\'t exist.'); |
|
| 382 | 382 | |
| 383 | - $user_can_edit = false; |
|
| 383 | + $user_can_edit = false; |
|
| 384 | 384 | |
| 385 | - } else { |
|
| 385 | + } else { |
|
| 386 | 386 | |
| 387 | - $current_user = wp_get_current_user(); |
|
| 387 | + $current_user = wp_get_current_user(); |
|
| 388 | 388 | |
| 389 | - // User edit is disabled |
|
| 390 | - if( empty( $user_edit ) ) { |
|
| 389 | + // User edit is disabled |
|
| 390 | + if( empty( $user_edit ) ) { |
|
| 391 | 391 | |
| 392 | - gravityview()->log->debug( 'User Edit is disabled. Returning false.' ); |
|
| 392 | + gravityview()->log->debug( 'User Edit is disabled. Returning false.' ); |
|
| 393 | 393 | |
| 394 | - $user_can_edit = false; |
|
| 395 | - } |
|
| 394 | + $user_can_edit = false; |
|
| 395 | + } |
|
| 396 | 396 | |
| 397 | - // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 398 | - else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 397 | + // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 398 | + else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 399 | 399 | |
| 400 | - gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id', $current_user->ID ) ); |
|
| 400 | + gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id', $current_user->ID ) ); |
|
| 401 | 401 | |
| 402 | - $user_can_edit = true; |
|
| 402 | + $user_can_edit = true; |
|
| 403 | 403 | |
| 404 | - } else if( ! is_user_logged_in() ) { |
|
| 404 | + } else if( ! is_user_logged_in() ) { |
|
| 405 | 405 | |
| 406 | - gravityview()->log->debug( 'No user defined; edit entry requires logged in user' ); |
|
| 406 | + gravityview()->log->debug( 'No user defined; edit entry requires logged in user' ); |
|
| 407 | 407 | |
| 408 | - $user_can_edit = false; // Here just for clarity |
|
| 409 | - } |
|
| 408 | + $user_can_edit = false; // Here just for clarity |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - } |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - /** |
|
| 414 | - * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 415 | - * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 416 | - * @param boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 417 | - * @param array $entry Gravity Forms entry array {@since 1.15} |
|
| 418 | - * @param int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 419 | - */ |
|
| 420 | - $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 413 | + /** |
|
| 414 | + * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 415 | + * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 416 | + * @param boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 417 | + * @param array $entry Gravity Forms entry array {@since 1.15} |
|
| 418 | + * @param int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 419 | + */ |
|
| 420 | + $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 421 | 421 | |
| 422 | - return (bool) $user_can_edit; |
|
| 423 | - } |
|
| 422 | + return (bool) $user_can_edit; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | 425 | /** |
| 426 | 426 | * Deletes a file. |
@@ -38,448 +38,448 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Inflector |
| 40 | 40 | { |
| 41 | - /** |
|
| 42 | - * Plural inflector rules. |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - private static $plural = array( |
|
| 47 | - 'rules' => array( |
|
| 48 | - '/(s)tatus$/i' => '\1\2tatuses', |
|
| 49 | - '/(quiz)$/i' => '\1zes', |
|
| 50 | - '/^(ox)$/i' => '\1\2en', |
|
| 51 | - '/([m|l])ouse$/i' => '\1ice', |
|
| 52 | - '/(matr|vert|ind)(ix|ex)$/i' => '\1ices', |
|
| 53 | - '/(x|ch|ss|sh)$/i' => '\1es', |
|
| 54 | - '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
| 55 | - '/(hive)$/i' => '\1s', |
|
| 56 | - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
| 57 | - '/sis$/i' => 'ses', |
|
| 58 | - '/([ti])um$/i' => '\1a', |
|
| 59 | - '/(p)erson$/i' => '\1eople', |
|
| 60 | - '/(m)an$/i' => '\1en', |
|
| 61 | - '/(c)hild$/i' => '\1hildren', |
|
| 62 | - '/(f)oot$/i' => '\1eet', |
|
| 63 | - '/(buffal|her|potat|tomat|volcan)o$/i' => '\1\2oes', |
|
| 64 | - '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i', |
|
| 65 | - '/us$/i' => 'uses', |
|
| 66 | - '/(alias)$/i' => '\1es', |
|
| 67 | - '/(analys|ax|cris|test|thes)is$/i' => '\1es', |
|
| 68 | - '/s$/' => 's', |
|
| 69 | - '/^$/' => '', |
|
| 70 | - '/$/' => 's', |
|
| 71 | - ), |
|
| 72 | - 'uninflected' => array( |
|
| 73 | - '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie' |
|
| 74 | - ), |
|
| 75 | - 'irregular' => array( |
|
| 76 | - 'atlas' => 'atlases', |
|
| 77 | - 'axe' => 'axes', |
|
| 78 | - 'beef' => 'beefs', |
|
| 79 | - 'brother' => 'brothers', |
|
| 80 | - 'cafe' => 'cafes', |
|
| 81 | - 'chateau' => 'chateaux', |
|
| 82 | - 'child' => 'children', |
|
| 83 | - 'cookie' => 'cookies', |
|
| 84 | - 'corpus' => 'corpuses', |
|
| 85 | - 'cow' => 'cows', |
|
| 86 | - 'criterion' => 'criteria', |
|
| 87 | - 'curriculum' => 'curricula', |
|
| 88 | - 'demo' => 'demos', |
|
| 89 | - 'domino' => 'dominoes', |
|
| 90 | - 'echo' => 'echoes', |
|
| 91 | - 'foot' => 'feet', |
|
| 92 | - 'fungus' => 'fungi', |
|
| 93 | - 'ganglion' => 'ganglions', |
|
| 94 | - 'genie' => 'genies', |
|
| 95 | - 'genus' => 'genera', |
|
| 96 | - 'graffito' => 'graffiti', |
|
| 97 | - 'hippopotamus' => 'hippopotami', |
|
| 98 | - 'hoof' => 'hoofs', |
|
| 99 | - 'human' => 'humans', |
|
| 100 | - 'iris' => 'irises', |
|
| 101 | - 'leaf' => 'leaves', |
|
| 102 | - 'loaf' => 'loaves', |
|
| 103 | - 'man' => 'men', |
|
| 104 | - 'medium' => 'media', |
|
| 105 | - 'memorandum' => 'memoranda', |
|
| 106 | - 'money' => 'monies', |
|
| 107 | - 'mongoose' => 'mongooses', |
|
| 108 | - 'motto' => 'mottoes', |
|
| 109 | - 'move' => 'moves', |
|
| 110 | - 'mythos' => 'mythoi', |
|
| 111 | - 'niche' => 'niches', |
|
| 112 | - 'nucleus' => 'nuclei', |
|
| 113 | - 'numen' => 'numina', |
|
| 114 | - 'occiput' => 'occiputs', |
|
| 115 | - 'octopus' => 'octopuses', |
|
| 116 | - 'opus' => 'opuses', |
|
| 117 | - 'ox' => 'oxen', |
|
| 118 | - 'penis' => 'penises', |
|
| 119 | - 'person' => 'people', |
|
| 120 | - 'plateau' => 'plateaux', |
|
| 121 | - 'runner-up' => 'runners-up', |
|
| 122 | - 'sex' => 'sexes', |
|
| 123 | - 'soliloquy' => 'soliloquies', |
|
| 124 | - 'son-in-law' => 'sons-in-law', |
|
| 125 | - 'syllabus' => 'syllabi', |
|
| 126 | - 'testis' => 'testes', |
|
| 127 | - 'thief' => 'thieves', |
|
| 128 | - 'tooth' => 'teeth', |
|
| 129 | - 'tornado' => 'tornadoes', |
|
| 130 | - 'trilby' => 'trilbys', |
|
| 131 | - 'turf' => 'turfs', |
|
| 132 | - 'volcano' => 'volcanoes', |
|
| 133 | - ) |
|
| 134 | - ); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Singular inflector rules. |
|
| 138 | - * |
|
| 139 | - * @var array |
|
| 140 | - */ |
|
| 141 | - private static $singular = array( |
|
| 142 | - 'rules' => array( |
|
| 143 | - '/(s)tatuses$/i' => '\1\2tatus', |
|
| 144 | - '/^(.*)(menu)s$/i' => '\1\2', |
|
| 145 | - '/(quiz)zes$/i' => '\\1', |
|
| 146 | - '/(matr)ices$/i' => '\1ix', |
|
| 147 | - '/(vert|ind)ices$/i' => '\1ex', |
|
| 148 | - '/^(ox)en/i' => '\1', |
|
| 149 | - '/(alias)(es)*$/i' => '\1', |
|
| 150 | - '/(buffal|her|potat|tomat|volcan)oes$/i' => '\1o', |
|
| 151 | - '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us', |
|
| 152 | - '/([ftw]ax)es/i' => '\1', |
|
| 153 | - '/(analys|ax|cris|test|thes)es$/i' => '\1is', |
|
| 154 | - '/(shoe|slave)s$/i' => '\1', |
|
| 155 | - '/(o)es$/i' => '\1', |
|
| 156 | - '/ouses$/' => 'ouse', |
|
| 157 | - '/([^a])uses$/' => '\1us', |
|
| 158 | - '/([m|l])ice$/i' => '\1ouse', |
|
| 159 | - '/(x|ch|ss|sh)es$/i' => '\1', |
|
| 160 | - '/(m)ovies$/i' => '\1\2ovie', |
|
| 161 | - '/(s)eries$/i' => '\1\2eries', |
|
| 162 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
| 163 | - '/([lr])ves$/i' => '\1f', |
|
| 164 | - '/(tive)s$/i' => '\1', |
|
| 165 | - '/(hive)s$/i' => '\1', |
|
| 166 | - '/(drive)s$/i' => '\1', |
|
| 167 | - '/([^fo])ves$/i' => '\1fe', |
|
| 168 | - '/(^analy)ses$/i' => '\1sis', |
|
| 169 | - '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
| 170 | - '/([ti])a$/i' => '\1um', |
|
| 171 | - '/(p)eople$/i' => '\1\2erson', |
|
| 172 | - '/(m)en$/i' => '\1an', |
|
| 173 | - '/(c)hildren$/i' => '\1\2hild', |
|
| 174 | - '/(f)eet$/i' => '\1oot', |
|
| 175 | - '/(n)ews$/i' => '\1\2ews', |
|
| 176 | - '/eaus$/' => 'eau', |
|
| 177 | - '/^(.*us)$/' => '\\1', |
|
| 178 | - '/s$/i' => '', |
|
| 179 | - ), |
|
| 180 | - 'uninflected' => array( |
|
| 181 | - '.*[nrlm]ese', |
|
| 182 | - '.*deer', |
|
| 183 | - '.*fish', |
|
| 184 | - '.*measles', |
|
| 185 | - '.*ois', |
|
| 186 | - '.*pox', |
|
| 187 | - '.*sheep', |
|
| 188 | - '.*ss', |
|
| 189 | - ), |
|
| 190 | - 'irregular' => array( |
|
| 191 | - 'criteria' => 'criterion', |
|
| 192 | - 'curves' => 'curve', |
|
| 193 | - 'emphases' => 'emphasis', |
|
| 194 | - 'foes' => 'foe', |
|
| 195 | - 'hoaxes' => 'hoax', |
|
| 196 | - 'media' => 'medium', |
|
| 197 | - 'neuroses' => 'neurosis', |
|
| 198 | - 'waves' => 'wave', |
|
| 199 | - 'oases' => 'oasis', |
|
| 200 | - ) |
|
| 201 | - ); |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Words that should not be inflected. |
|
| 205 | - * |
|
| 206 | - * @var array |
|
| 207 | - */ |
|
| 208 | - private static $uninflected = array( |
|
| 209 | - 'Amoyese', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', |
|
| 210 | - 'carp', 'chassis', 'clippers', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps', |
|
| 211 | - 'debris', 'diabetes', 'djinn', 'eland', 'elk', 'equipment', 'Faroese', 'flounder', |
|
| 212 | - 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti', |
|
| 213 | - 'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', |
|
| 214 | - 'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media', |
|
| 215 | - 'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese', |
|
| 216 | - 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', |
|
| 217 | - 'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', |
|
| 218 | - 'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'staff', 'swine', |
|
| 219 | - 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', |
|
| 220 | - 'wildebeest', 'Yengeese' |
|
| 221 | - ); |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Method cache array. |
|
| 225 | - * |
|
| 226 | - * @var array |
|
| 227 | - */ |
|
| 228 | - private static $cache = array(); |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * The initial state of Inflector so reset() works. |
|
| 232 | - * |
|
| 233 | - * @var array |
|
| 234 | - */ |
|
| 235 | - private static $initialState = array(); |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. |
|
| 239 | - * |
|
| 240 | - * @param string $word The word to tableize. |
|
| 241 | - * |
|
| 242 | - * @return string The tableized word. |
|
| 243 | - */ |
|
| 244 | - public static function tableize($word) |
|
| 245 | - { |
|
| 246 | - return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word)); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'. |
|
| 251 | - * |
|
| 252 | - * @param string $word The word to classify. |
|
| 253 | - * |
|
| 254 | - * @return string The classified word. |
|
| 255 | - */ |
|
| 256 | - public static function classify($word) |
|
| 257 | - { |
|
| 258 | - return str_replace(" ", "", ucwords(strtr($word, "_-", " "))); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Camelizes a word. This uses the classify() method and turns the first character to lowercase. |
|
| 263 | - * |
|
| 264 | - * @param string $word The word to camelize. |
|
| 265 | - * |
|
| 266 | - * @return string The camelized word. |
|
| 267 | - */ |
|
| 268 | - public static function camelize($word) |
|
| 269 | - { |
|
| 270 | - return lcfirst(self::classify($word)); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Uppercases words with configurable delimeters between words. |
|
| 275 | - * |
|
| 276 | - * Takes a string and capitalizes all of the words, like PHP's built-in |
|
| 277 | - * ucwords function. This extends that behavior, however, by allowing the |
|
| 278 | - * word delimeters to be configured, rather than only separating on |
|
| 279 | - * whitespace. |
|
| 280 | - * |
|
| 281 | - * Here is an example: |
|
| 282 | - * <code> |
|
| 283 | - * <?php |
|
| 284 | - * $string = 'top-o-the-morning to all_of_you!'; |
|
| 285 | - * echo \Doctrine\Common\Inflector\Inflector::ucwords($string); |
|
| 286 | - * // Top-O-The-Morning To All_of_you! |
|
| 287 | - * |
|
| 288 | - * echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ '); |
|
| 289 | - * // Top-O-The-Morning To All_Of_You! |
|
| 290 | - * ?> |
|
| 291 | - * </code> |
|
| 292 | - * |
|
| 293 | - * @param string $string The string to operate on. |
|
| 294 | - * @param string $delimiters A list of word separators. |
|
| 295 | - * |
|
| 296 | - * @return string The string with all delimeter-separated words capitalized. |
|
| 297 | - */ |
|
| 298 | - public static function ucwords($string, $delimiters = " \n\t\r\0\x0B-") |
|
| 299 | - { |
|
| 300 | - return preg_replace_callback( |
|
| 301 | - '/[^' . preg_quote($delimiters, '/') . ']+/', |
|
| 302 | - function($matches) { |
|
| 303 | - return ucfirst($matches[0]); |
|
| 304 | - }, |
|
| 305 | - $string |
|
| 306 | - ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Clears Inflectors inflected value caches, and resets the inflection |
|
| 311 | - * rules to the initial values. |
|
| 312 | - * |
|
| 313 | - * @return void |
|
| 314 | - */ |
|
| 315 | - public static function reset() |
|
| 316 | - { |
|
| 317 | - if (empty(self::$initialState)) { |
|
| 318 | - self::$initialState = get_class_vars('Inflector'); |
|
| 319 | - |
|
| 320 | - return; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - foreach (self::$initialState as $key => $val) { |
|
| 324 | - if ($key != 'initialState') { |
|
| 325 | - self::${$key} = $val; |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Adds custom inflection $rules, of either 'plural' or 'singular' $type. |
|
| 332 | - * |
|
| 333 | - * ### Usage: |
|
| 334 | - * |
|
| 335 | - * {{{ |
|
| 336 | - * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables')); |
|
| 337 | - * Inflector::rules('plural', array( |
|
| 338 | - * 'rules' => array('/^(inflect)ors$/i' => '\1ables'), |
|
| 339 | - * 'uninflected' => array('dontinflectme'), |
|
| 340 | - * 'irregular' => array('red' => 'redlings') |
|
| 341 | - * )); |
|
| 342 | - * }}} |
|
| 343 | - * |
|
| 344 | - * @param string $type The type of inflection, either 'plural' or 'singular' |
|
| 345 | - * @param array $rules An array of rules to be added. |
|
| 346 | - * @param boolean $reset If true, will unset default inflections for all |
|
| 347 | - * new rules that are being defined in $rules. |
|
| 348 | - * |
|
| 349 | - * @return void |
|
| 350 | - */ |
|
| 351 | - public static function rules($type, $rules, $reset = false) |
|
| 352 | - { |
|
| 353 | - foreach ($rules as $rule => $pattern) { |
|
| 354 | - if ( ! is_array($pattern)) { |
|
| 355 | - continue; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - if ($reset) { |
|
| 359 | - self::${$type}[$rule] = $pattern; |
|
| 360 | - } else { |
|
| 361 | - self::${$type}[$rule] = ($rule === 'uninflected') |
|
| 362 | - ? array_merge($pattern, self::${$type}[$rule]) |
|
| 363 | - : $pattern + self::${$type}[$rule]; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - unset($rules[$rule], self::${$type}['cache' . ucfirst($rule)]); |
|
| 367 | - |
|
| 368 | - if (isset(self::${$type}['merged'][$rule])) { |
|
| 369 | - unset(self::${$type}['merged'][$rule]); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if ($type === 'plural') { |
|
| 373 | - self::$cache['pluralize'] = self::$cache['tableize'] = array(); |
|
| 374 | - } elseif ($type === 'singular') { |
|
| 375 | - self::$cache['singularize'] = array(); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - self::${$type}['rules'] = $rules + self::${$type}['rules']; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Returns a word in plural form. |
|
| 384 | - * |
|
| 385 | - * @param string $word The word in singular form. |
|
| 386 | - * |
|
| 387 | - * @return string The word in plural form. |
|
| 388 | - */ |
|
| 389 | - public static function pluralize($word) |
|
| 390 | - { |
|
| 391 | - if (isset(self::$cache['pluralize'][$word])) { |
|
| 392 | - return self::$cache['pluralize'][$word]; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if (!isset(self::$plural['merged']['irregular'])) { |
|
| 396 | - self::$plural['merged']['irregular'] = self::$plural['irregular']; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if (!isset(self::$plural['merged']['uninflected'])) { |
|
| 400 | - self::$plural['merged']['uninflected'] = array_merge(self::$plural['uninflected'], self::$uninflected); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - if (!isset(self::$plural['cacheUninflected']) || !isset(self::$plural['cacheIrregular'])) { |
|
| 404 | - self::$plural['cacheUninflected'] = '(?:' . implode('|', self::$plural['merged']['uninflected']) . ')'; |
|
| 405 | - self::$plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$plural['merged']['irregular'])) . ')'; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - if (preg_match('/(.*)\\b(' . self::$plural['cacheIrregular'] . ')$/i', $word, $regs)) { |
|
| 409 | - self::$cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$plural['merged']['irregular'][strtolower($regs[2])], 1); |
|
| 41 | + /** |
|
| 42 | + * Plural inflector rules. |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + private static $plural = array( |
|
| 47 | + 'rules' => array( |
|
| 48 | + '/(s)tatus$/i' => '\1\2tatuses', |
|
| 49 | + '/(quiz)$/i' => '\1zes', |
|
| 50 | + '/^(ox)$/i' => '\1\2en', |
|
| 51 | + '/([m|l])ouse$/i' => '\1ice', |
|
| 52 | + '/(matr|vert|ind)(ix|ex)$/i' => '\1ices', |
|
| 53 | + '/(x|ch|ss|sh)$/i' => '\1es', |
|
| 54 | + '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
| 55 | + '/(hive)$/i' => '\1s', |
|
| 56 | + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
| 57 | + '/sis$/i' => 'ses', |
|
| 58 | + '/([ti])um$/i' => '\1a', |
|
| 59 | + '/(p)erson$/i' => '\1eople', |
|
| 60 | + '/(m)an$/i' => '\1en', |
|
| 61 | + '/(c)hild$/i' => '\1hildren', |
|
| 62 | + '/(f)oot$/i' => '\1eet', |
|
| 63 | + '/(buffal|her|potat|tomat|volcan)o$/i' => '\1\2oes', |
|
| 64 | + '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i', |
|
| 65 | + '/us$/i' => 'uses', |
|
| 66 | + '/(alias)$/i' => '\1es', |
|
| 67 | + '/(analys|ax|cris|test|thes)is$/i' => '\1es', |
|
| 68 | + '/s$/' => 's', |
|
| 69 | + '/^$/' => '', |
|
| 70 | + '/$/' => 's', |
|
| 71 | + ), |
|
| 72 | + 'uninflected' => array( |
|
| 73 | + '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie' |
|
| 74 | + ), |
|
| 75 | + 'irregular' => array( |
|
| 76 | + 'atlas' => 'atlases', |
|
| 77 | + 'axe' => 'axes', |
|
| 78 | + 'beef' => 'beefs', |
|
| 79 | + 'brother' => 'brothers', |
|
| 80 | + 'cafe' => 'cafes', |
|
| 81 | + 'chateau' => 'chateaux', |
|
| 82 | + 'child' => 'children', |
|
| 83 | + 'cookie' => 'cookies', |
|
| 84 | + 'corpus' => 'corpuses', |
|
| 85 | + 'cow' => 'cows', |
|
| 86 | + 'criterion' => 'criteria', |
|
| 87 | + 'curriculum' => 'curricula', |
|
| 88 | + 'demo' => 'demos', |
|
| 89 | + 'domino' => 'dominoes', |
|
| 90 | + 'echo' => 'echoes', |
|
| 91 | + 'foot' => 'feet', |
|
| 92 | + 'fungus' => 'fungi', |
|
| 93 | + 'ganglion' => 'ganglions', |
|
| 94 | + 'genie' => 'genies', |
|
| 95 | + 'genus' => 'genera', |
|
| 96 | + 'graffito' => 'graffiti', |
|
| 97 | + 'hippopotamus' => 'hippopotami', |
|
| 98 | + 'hoof' => 'hoofs', |
|
| 99 | + 'human' => 'humans', |
|
| 100 | + 'iris' => 'irises', |
|
| 101 | + 'leaf' => 'leaves', |
|
| 102 | + 'loaf' => 'loaves', |
|
| 103 | + 'man' => 'men', |
|
| 104 | + 'medium' => 'media', |
|
| 105 | + 'memorandum' => 'memoranda', |
|
| 106 | + 'money' => 'monies', |
|
| 107 | + 'mongoose' => 'mongooses', |
|
| 108 | + 'motto' => 'mottoes', |
|
| 109 | + 'move' => 'moves', |
|
| 110 | + 'mythos' => 'mythoi', |
|
| 111 | + 'niche' => 'niches', |
|
| 112 | + 'nucleus' => 'nuclei', |
|
| 113 | + 'numen' => 'numina', |
|
| 114 | + 'occiput' => 'occiputs', |
|
| 115 | + 'octopus' => 'octopuses', |
|
| 116 | + 'opus' => 'opuses', |
|
| 117 | + 'ox' => 'oxen', |
|
| 118 | + 'penis' => 'penises', |
|
| 119 | + 'person' => 'people', |
|
| 120 | + 'plateau' => 'plateaux', |
|
| 121 | + 'runner-up' => 'runners-up', |
|
| 122 | + 'sex' => 'sexes', |
|
| 123 | + 'soliloquy' => 'soliloquies', |
|
| 124 | + 'son-in-law' => 'sons-in-law', |
|
| 125 | + 'syllabus' => 'syllabi', |
|
| 126 | + 'testis' => 'testes', |
|
| 127 | + 'thief' => 'thieves', |
|
| 128 | + 'tooth' => 'teeth', |
|
| 129 | + 'tornado' => 'tornadoes', |
|
| 130 | + 'trilby' => 'trilbys', |
|
| 131 | + 'turf' => 'turfs', |
|
| 132 | + 'volcano' => 'volcanoes', |
|
| 133 | + ) |
|
| 134 | + ); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Singular inflector rules. |
|
| 138 | + * |
|
| 139 | + * @var array |
|
| 140 | + */ |
|
| 141 | + private static $singular = array( |
|
| 142 | + 'rules' => array( |
|
| 143 | + '/(s)tatuses$/i' => '\1\2tatus', |
|
| 144 | + '/^(.*)(menu)s$/i' => '\1\2', |
|
| 145 | + '/(quiz)zes$/i' => '\\1', |
|
| 146 | + '/(matr)ices$/i' => '\1ix', |
|
| 147 | + '/(vert|ind)ices$/i' => '\1ex', |
|
| 148 | + '/^(ox)en/i' => '\1', |
|
| 149 | + '/(alias)(es)*$/i' => '\1', |
|
| 150 | + '/(buffal|her|potat|tomat|volcan)oes$/i' => '\1o', |
|
| 151 | + '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us', |
|
| 152 | + '/([ftw]ax)es/i' => '\1', |
|
| 153 | + '/(analys|ax|cris|test|thes)es$/i' => '\1is', |
|
| 154 | + '/(shoe|slave)s$/i' => '\1', |
|
| 155 | + '/(o)es$/i' => '\1', |
|
| 156 | + '/ouses$/' => 'ouse', |
|
| 157 | + '/([^a])uses$/' => '\1us', |
|
| 158 | + '/([m|l])ice$/i' => '\1ouse', |
|
| 159 | + '/(x|ch|ss|sh)es$/i' => '\1', |
|
| 160 | + '/(m)ovies$/i' => '\1\2ovie', |
|
| 161 | + '/(s)eries$/i' => '\1\2eries', |
|
| 162 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
| 163 | + '/([lr])ves$/i' => '\1f', |
|
| 164 | + '/(tive)s$/i' => '\1', |
|
| 165 | + '/(hive)s$/i' => '\1', |
|
| 166 | + '/(drive)s$/i' => '\1', |
|
| 167 | + '/([^fo])ves$/i' => '\1fe', |
|
| 168 | + '/(^analy)ses$/i' => '\1sis', |
|
| 169 | + '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
| 170 | + '/([ti])a$/i' => '\1um', |
|
| 171 | + '/(p)eople$/i' => '\1\2erson', |
|
| 172 | + '/(m)en$/i' => '\1an', |
|
| 173 | + '/(c)hildren$/i' => '\1\2hild', |
|
| 174 | + '/(f)eet$/i' => '\1oot', |
|
| 175 | + '/(n)ews$/i' => '\1\2ews', |
|
| 176 | + '/eaus$/' => 'eau', |
|
| 177 | + '/^(.*us)$/' => '\\1', |
|
| 178 | + '/s$/i' => '', |
|
| 179 | + ), |
|
| 180 | + 'uninflected' => array( |
|
| 181 | + '.*[nrlm]ese', |
|
| 182 | + '.*deer', |
|
| 183 | + '.*fish', |
|
| 184 | + '.*measles', |
|
| 185 | + '.*ois', |
|
| 186 | + '.*pox', |
|
| 187 | + '.*sheep', |
|
| 188 | + '.*ss', |
|
| 189 | + ), |
|
| 190 | + 'irregular' => array( |
|
| 191 | + 'criteria' => 'criterion', |
|
| 192 | + 'curves' => 'curve', |
|
| 193 | + 'emphases' => 'emphasis', |
|
| 194 | + 'foes' => 'foe', |
|
| 195 | + 'hoaxes' => 'hoax', |
|
| 196 | + 'media' => 'medium', |
|
| 197 | + 'neuroses' => 'neurosis', |
|
| 198 | + 'waves' => 'wave', |
|
| 199 | + 'oases' => 'oasis', |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Words that should not be inflected. |
|
| 205 | + * |
|
| 206 | + * @var array |
|
| 207 | + */ |
|
| 208 | + private static $uninflected = array( |
|
| 209 | + 'Amoyese', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', |
|
| 210 | + 'carp', 'chassis', 'clippers', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps', |
|
| 211 | + 'debris', 'diabetes', 'djinn', 'eland', 'elk', 'equipment', 'Faroese', 'flounder', |
|
| 212 | + 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti', |
|
| 213 | + 'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', |
|
| 214 | + 'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media', |
|
| 215 | + 'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese', |
|
| 216 | + 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', |
|
| 217 | + 'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', |
|
| 218 | + 'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'staff', 'swine', |
|
| 219 | + 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', |
|
| 220 | + 'wildebeest', 'Yengeese' |
|
| 221 | + ); |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Method cache array. |
|
| 225 | + * |
|
| 226 | + * @var array |
|
| 227 | + */ |
|
| 228 | + private static $cache = array(); |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * The initial state of Inflector so reset() works. |
|
| 232 | + * |
|
| 233 | + * @var array |
|
| 234 | + */ |
|
| 235 | + private static $initialState = array(); |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. |
|
| 239 | + * |
|
| 240 | + * @param string $word The word to tableize. |
|
| 241 | + * |
|
| 242 | + * @return string The tableized word. |
|
| 243 | + */ |
|
| 244 | + public static function tableize($word) |
|
| 245 | + { |
|
| 246 | + return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word)); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'. |
|
| 251 | + * |
|
| 252 | + * @param string $word The word to classify. |
|
| 253 | + * |
|
| 254 | + * @return string The classified word. |
|
| 255 | + */ |
|
| 256 | + public static function classify($word) |
|
| 257 | + { |
|
| 258 | + return str_replace(" ", "", ucwords(strtr($word, "_-", " "))); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Camelizes a word. This uses the classify() method and turns the first character to lowercase. |
|
| 263 | + * |
|
| 264 | + * @param string $word The word to camelize. |
|
| 265 | + * |
|
| 266 | + * @return string The camelized word. |
|
| 267 | + */ |
|
| 268 | + public static function camelize($word) |
|
| 269 | + { |
|
| 270 | + return lcfirst(self::classify($word)); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Uppercases words with configurable delimeters between words. |
|
| 275 | + * |
|
| 276 | + * Takes a string and capitalizes all of the words, like PHP's built-in |
|
| 277 | + * ucwords function. This extends that behavior, however, by allowing the |
|
| 278 | + * word delimeters to be configured, rather than only separating on |
|
| 279 | + * whitespace. |
|
| 280 | + * |
|
| 281 | + * Here is an example: |
|
| 282 | + * <code> |
|
| 283 | + * <?php |
|
| 284 | + * $string = 'top-o-the-morning to all_of_you!'; |
|
| 285 | + * echo \Doctrine\Common\Inflector\Inflector::ucwords($string); |
|
| 286 | + * // Top-O-The-Morning To All_of_you! |
|
| 287 | + * |
|
| 288 | + * echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ '); |
|
| 289 | + * // Top-O-The-Morning To All_Of_You! |
|
| 290 | + * ?> |
|
| 291 | + * </code> |
|
| 292 | + * |
|
| 293 | + * @param string $string The string to operate on. |
|
| 294 | + * @param string $delimiters A list of word separators. |
|
| 295 | + * |
|
| 296 | + * @return string The string with all delimeter-separated words capitalized. |
|
| 297 | + */ |
|
| 298 | + public static function ucwords($string, $delimiters = " \n\t\r\0\x0B-") |
|
| 299 | + { |
|
| 300 | + return preg_replace_callback( |
|
| 301 | + '/[^' . preg_quote($delimiters, '/') . ']+/', |
|
| 302 | + function($matches) { |
|
| 303 | + return ucfirst($matches[0]); |
|
| 304 | + }, |
|
| 305 | + $string |
|
| 306 | + ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Clears Inflectors inflected value caches, and resets the inflection |
|
| 311 | + * rules to the initial values. |
|
| 312 | + * |
|
| 313 | + * @return void |
|
| 314 | + */ |
|
| 315 | + public static function reset() |
|
| 316 | + { |
|
| 317 | + if (empty(self::$initialState)) { |
|
| 318 | + self::$initialState = get_class_vars('Inflector'); |
|
| 319 | + |
|
| 320 | + return; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + foreach (self::$initialState as $key => $val) { |
|
| 324 | + if ($key != 'initialState') { |
|
| 325 | + self::${$key} = $val; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Adds custom inflection $rules, of either 'plural' or 'singular' $type. |
|
| 332 | + * |
|
| 333 | + * ### Usage: |
|
| 334 | + * |
|
| 335 | + * {{{ |
|
| 336 | + * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables')); |
|
| 337 | + * Inflector::rules('plural', array( |
|
| 338 | + * 'rules' => array('/^(inflect)ors$/i' => '\1ables'), |
|
| 339 | + * 'uninflected' => array('dontinflectme'), |
|
| 340 | + * 'irregular' => array('red' => 'redlings') |
|
| 341 | + * )); |
|
| 342 | + * }}} |
|
| 343 | + * |
|
| 344 | + * @param string $type The type of inflection, either 'plural' or 'singular' |
|
| 345 | + * @param array $rules An array of rules to be added. |
|
| 346 | + * @param boolean $reset If true, will unset default inflections for all |
|
| 347 | + * new rules that are being defined in $rules. |
|
| 348 | + * |
|
| 349 | + * @return void |
|
| 350 | + */ |
|
| 351 | + public static function rules($type, $rules, $reset = false) |
|
| 352 | + { |
|
| 353 | + foreach ($rules as $rule => $pattern) { |
|
| 354 | + if ( ! is_array($pattern)) { |
|
| 355 | + continue; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + if ($reset) { |
|
| 359 | + self::${$type}[$rule] = $pattern; |
|
| 360 | + } else { |
|
| 361 | + self::${$type}[$rule] = ($rule === 'uninflected') |
|
| 362 | + ? array_merge($pattern, self::${$type}[$rule]) |
|
| 363 | + : $pattern + self::${$type}[$rule]; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + unset($rules[$rule], self::${$type}['cache' . ucfirst($rule)]); |
|
| 367 | + |
|
| 368 | + if (isset(self::${$type}['merged'][$rule])) { |
|
| 369 | + unset(self::${$type}['merged'][$rule]); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if ($type === 'plural') { |
|
| 373 | + self::$cache['pluralize'] = self::$cache['tableize'] = array(); |
|
| 374 | + } elseif ($type === 'singular') { |
|
| 375 | + self::$cache['singularize'] = array(); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + self::${$type}['rules'] = $rules + self::${$type}['rules']; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Returns a word in plural form. |
|
| 384 | + * |
|
| 385 | + * @param string $word The word in singular form. |
|
| 386 | + * |
|
| 387 | + * @return string The word in plural form. |
|
| 388 | + */ |
|
| 389 | + public static function pluralize($word) |
|
| 390 | + { |
|
| 391 | + if (isset(self::$cache['pluralize'][$word])) { |
|
| 392 | + return self::$cache['pluralize'][$word]; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if (!isset(self::$plural['merged']['irregular'])) { |
|
| 396 | + self::$plural['merged']['irregular'] = self::$plural['irregular']; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if (!isset(self::$plural['merged']['uninflected'])) { |
|
| 400 | + self::$plural['merged']['uninflected'] = array_merge(self::$plural['uninflected'], self::$uninflected); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + if (!isset(self::$plural['cacheUninflected']) || !isset(self::$plural['cacheIrregular'])) { |
|
| 404 | + self::$plural['cacheUninflected'] = '(?:' . implode('|', self::$plural['merged']['uninflected']) . ')'; |
|
| 405 | + self::$plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$plural['merged']['irregular'])) . ')'; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + if (preg_match('/(.*)\\b(' . self::$plural['cacheIrregular'] . ')$/i', $word, $regs)) { |
|
| 409 | + self::$cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$plural['merged']['irregular'][strtolower($regs[2])], 1); |
|
| 410 | 410 | |
| 411 | - return self::$cache['pluralize'][$word]; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - if (preg_match('/^(' . self::$plural['cacheUninflected'] . ')$/i', $word, $regs)) { |
|
| 415 | - self::$cache['pluralize'][$word] = $word; |
|
| 416 | - |
|
| 417 | - return $word; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - foreach (self::$plural['rules'] as $rule => $replacement) { |
|
| 421 | - if (preg_match($rule, $word)) { |
|
| 422 | - self::$cache['pluralize'][$word] = preg_replace($rule, $replacement, $word); |
|
| 423 | - |
|
| 424 | - return self::$cache['pluralize'][$word]; |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Returns a word in singular form. |
|
| 431 | - * |
|
| 432 | - * @param string $word The word in plural form. |
|
| 433 | - * |
|
| 434 | - * @return string The word in singular form. |
|
| 435 | - */ |
|
| 436 | - public static function singularize($word) |
|
| 437 | - { |
|
| 438 | - if (isset(self::$cache['singularize'][$word])) { |
|
| 439 | - return self::$cache['singularize'][$word]; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - if (!isset(self::$singular['merged']['uninflected'])) { |
|
| 443 | - self::$singular['merged']['uninflected'] = array_merge( |
|
| 444 | - self::$singular['uninflected'], |
|
| 445 | - self::$uninflected |
|
| 446 | - ); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - if (!isset(self::$singular['merged']['irregular'])) { |
|
| 450 | - self::$singular['merged']['irregular'] = array_merge( |
|
| 451 | - self::$singular['irregular'], |
|
| 452 | - array_flip(self::$plural['irregular']) |
|
| 453 | - ); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - if (!isset(self::$singular['cacheUninflected']) || !isset(self::$singular['cacheIrregular'])) { |
|
| 457 | - self::$singular['cacheUninflected'] = '(?:' . join('|', self::$singular['merged']['uninflected']) . ')'; |
|
| 458 | - self::$singular['cacheIrregular'] = '(?:' . join('|', array_keys(self::$singular['merged']['irregular'])) . ')'; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - if (preg_match('/(.*)\\b(' . self::$singular['cacheIrregular'] . ')$/i', $word, $regs)) { |
|
| 462 | - self::$cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$singular['merged']['irregular'][strtolower($regs[2])], 1); |
|
| 411 | + return self::$cache['pluralize'][$word]; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + if (preg_match('/^(' . self::$plural['cacheUninflected'] . ')$/i', $word, $regs)) { |
|
| 415 | + self::$cache['pluralize'][$word] = $word; |
|
| 416 | + |
|
| 417 | + return $word; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + foreach (self::$plural['rules'] as $rule => $replacement) { |
|
| 421 | + if (preg_match($rule, $word)) { |
|
| 422 | + self::$cache['pluralize'][$word] = preg_replace($rule, $replacement, $word); |
|
| 423 | + |
|
| 424 | + return self::$cache['pluralize'][$word]; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Returns a word in singular form. |
|
| 431 | + * |
|
| 432 | + * @param string $word The word in plural form. |
|
| 433 | + * |
|
| 434 | + * @return string The word in singular form. |
|
| 435 | + */ |
|
| 436 | + public static function singularize($word) |
|
| 437 | + { |
|
| 438 | + if (isset(self::$cache['singularize'][$word])) { |
|
| 439 | + return self::$cache['singularize'][$word]; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + if (!isset(self::$singular['merged']['uninflected'])) { |
|
| 443 | + self::$singular['merged']['uninflected'] = array_merge( |
|
| 444 | + self::$singular['uninflected'], |
|
| 445 | + self::$uninflected |
|
| 446 | + ); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + if (!isset(self::$singular['merged']['irregular'])) { |
|
| 450 | + self::$singular['merged']['irregular'] = array_merge( |
|
| 451 | + self::$singular['irregular'], |
|
| 452 | + array_flip(self::$plural['irregular']) |
|
| 453 | + ); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + if (!isset(self::$singular['cacheUninflected']) || !isset(self::$singular['cacheIrregular'])) { |
|
| 457 | + self::$singular['cacheUninflected'] = '(?:' . join('|', self::$singular['merged']['uninflected']) . ')'; |
|
| 458 | + self::$singular['cacheIrregular'] = '(?:' . join('|', array_keys(self::$singular['merged']['irregular'])) . ')'; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if (preg_match('/(.*)\\b(' . self::$singular['cacheIrregular'] . ')$/i', $word, $regs)) { |
|
| 462 | + self::$cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$singular['merged']['irregular'][strtolower($regs[2])], 1); |
|
| 463 | 463 | |
| 464 | - return self::$cache['singularize'][$word]; |
|
| 465 | - } |
|
| 464 | + return self::$cache['singularize'][$word]; |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | - if (preg_match('/^(' . self::$singular['cacheUninflected'] . ')$/i', $word, $regs)) { |
|
| 468 | - self::$cache['singularize'][$word] = $word; |
|
| 467 | + if (preg_match('/^(' . self::$singular['cacheUninflected'] . ')$/i', $word, $regs)) { |
|
| 468 | + self::$cache['singularize'][$word] = $word; |
|
| 469 | 469 | |
| 470 | - return $word; |
|
| 471 | - } |
|
| 470 | + return $word; |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - foreach (self::$singular['rules'] as $rule => $replacement) { |
|
| 474 | - if (preg_match($rule, $word)) { |
|
| 475 | - self::$cache['singularize'][$word] = preg_replace($rule, $replacement, $word); |
|
| 473 | + foreach (self::$singular['rules'] as $rule => $replacement) { |
|
| 474 | + if (preg_match($rule, $word)) { |
|
| 475 | + self::$cache['singularize'][$word] = preg_replace($rule, $replacement, $word); |
|
| 476 | 476 | |
| 477 | - return self::$cache['singularize'][$word]; |
|
| 478 | - } |
|
| 479 | - } |
|
| 477 | + return self::$cache['singularize'][$word]; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - self::$cache['singularize'][$word] = $word; |
|
| 481 | + self::$cache['singularize'][$word] = $word; |
|
| 482 | 482 | |
| 483 | - return $word; |
|
| 484 | - } |
|
| 483 | + return $word; |
|
| 484 | + } |
|
| 485 | 485 | } |
@@ -34,322 +34,322 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Logger extends AbstractLogger |
| 36 | 36 | {
|
| 37 | - /** |
|
| 38 | - * KLogger options |
|
| 39 | - * Anything options not considered 'core' to the logging library should be |
|
| 40 | - * settable view the third parameter in the constructor |
|
| 41 | - * |
|
| 42 | - * Core options include the log file path and the log threshold |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $options = array ( |
|
| 47 | - 'extension' => 'txt', |
|
| 48 | - 'dateFormat' => 'Y-m-d G:i:s.u', |
|
| 49 | - 'filename' => false, |
|
| 50 | - 'flushFrequency' => false, |
|
| 51 | - 'prefix' => 'log_', |
|
| 52 | - 'logFormat' => false, |
|
| 53 | - 'appendContext' => true, |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Path to the log file |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 60 | - private $logFilePath; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Current minimum logging threshold |
|
| 64 | - * @var integer |
|
| 65 | - */ |
|
| 66 | - protected $logLevelThreshold = LogLevel::DEBUG; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The number of lines logged in this instance's lifetime |
|
| 70 | - * @var int |
|
| 71 | - */ |
|
| 72 | - private $logLineCount = 0; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Log Levels |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $logLevels = array( |
|
| 79 | - LogLevel::EMERGENCY => 0, |
|
| 80 | - LogLevel::ALERT => 1, |
|
| 81 | - LogLevel::CRITICAL => 2, |
|
| 82 | - LogLevel::ERROR => 3, |
|
| 83 | - LogLevel::WARNING => 4, |
|
| 84 | - LogLevel::NOTICE => 5, |
|
| 85 | - LogLevel::INFO => 6, |
|
| 86 | - LogLevel::DEBUG => 7 |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * This holds the file handle for this instance's log file |
|
| 91 | - * @var resource |
|
| 92 | - */ |
|
| 93 | - private $fileHandle; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * This holds the last line logged to the logger |
|
| 97 | - * Used for unit tests |
|
| 98 | - * @var string |
|
| 99 | - */ |
|
| 100 | - private $lastLine = ''; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Octal notation for default permissions of the log file |
|
| 104 | - * @var integer |
|
| 105 | - */ |
|
| 106 | - private $defaultPermissions = 0777; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Class constructor |
|
| 110 | - * |
|
| 111 | - * @param string $logDirectory File path to the logging directory |
|
| 112 | - * @param string $logLevelThreshold The LogLevel Threshold |
|
| 113 | - * @param array $options |
|
| 114 | - * |
|
| 115 | - * @internal param string $logFilePrefix The prefix for the log file name |
|
| 116 | - * @internal param string $logFileExt The extension for the log file |
|
| 117 | - */ |
|
| 118 | - public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array()) |
|
| 119 | - {
|
|
| 120 | - $this->logLevelThreshold = $logLevelThreshold; |
|
| 121 | - $this->options = array_merge($this->options, $options); |
|
| 122 | - |
|
| 123 | - $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR); |
|
| 124 | - if ( ! file_exists($logDirectory)) {
|
|
| 125 | - mkdir($logDirectory, $this->defaultPermissions, true); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if(strpos($logDirectory, 'php://') === 0) {
|
|
| 129 | - $this->setLogToStdOut($logDirectory); |
|
| 130 | - $this->setFileHandle('w+');
|
|
| 131 | - } else {
|
|
| 132 | - $this->setLogFilePath($logDirectory); |
|
| 133 | - if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
|
|
| 134 | - throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
|
|
| 135 | - } |
|
| 136 | - $this->setFileHandle('a');
|
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - if ( ! $this->fileHandle) {
|
|
| 140 | - throw new RuntimeException('The file could not be opened. Check permissions.');
|
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param string $stdOutPath |
|
| 146 | - */ |
|
| 147 | - public function setLogToStdOut($stdOutPath) {
|
|
| 148 | - $this->logFilePath = $stdOutPath; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param string $logDirectory |
|
| 153 | - */ |
|
| 154 | - public function setLogFilePath($logDirectory) {
|
|
| 155 | - if ($this->options['filename']) {
|
|
| 156 | - if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
|
|
| 157 | - $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename']; |
|
| 158 | - } |
|
| 159 | - else {
|
|
| 160 | - $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension']; |
|
| 161 | - } |
|
| 162 | - } else {
|
|
| 163 | - $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
|
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param $writeMode |
|
| 169 | - * |
|
| 170 | - * @internal param resource $fileHandle |
|
| 171 | - */ |
|
| 172 | - public function setFileHandle($writeMode) {
|
|
| 173 | - $this->fileHandle = fopen($this->logFilePath, $writeMode); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Class destructor |
|
| 179 | - */ |
|
| 180 | - public function __destruct() |
|
| 181 | - {
|
|
| 182 | - if ($this->fileHandle) {
|
|
| 183 | - fclose($this->fileHandle); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Sets the date format used by all instances of KLogger |
|
| 189 | - * |
|
| 190 | - * @param string $dateFormat Valid format string for date() |
|
| 191 | - */ |
|
| 192 | - public function setDateFormat($dateFormat) |
|
| 193 | - {
|
|
| 194 | - $this->options['dateFormat'] = $dateFormat; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Sets the Log Level Threshold |
|
| 199 | - * |
|
| 200 | - * @param string $logLevelThreshold The log level threshold |
|
| 201 | - */ |
|
| 202 | - public function setLogLevelThreshold($logLevelThreshold) |
|
| 203 | - {
|
|
| 204 | - $this->logLevelThreshold = $logLevelThreshold; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Logs with an arbitrary level. |
|
| 209 | - * |
|
| 210 | - * @param mixed $level |
|
| 211 | - * @param string $message |
|
| 212 | - * @param array $context |
|
| 213 | - * @return null |
|
| 214 | - */ |
|
| 215 | - public function log($level, $message, array $context = array()) |
|
| 216 | - {
|
|
| 217 | - if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
|
|
| 218 | - return; |
|
| 219 | - } |
|
| 220 | - $message = $this->formatMessage($level, $message, $context); |
|
| 221 | - $this->write($message); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Writes a line to the log without prepending a status or timestamp |
|
| 226 | - * |
|
| 227 | - * @param string $message Line to write to the log |
|
| 228 | - * @return void |
|
| 229 | - */ |
|
| 230 | - public function write($message) |
|
| 231 | - {
|
|
| 232 | - if (null !== $this->fileHandle) {
|
|
| 233 | - if (fwrite($this->fileHandle, $message) === false) {
|
|
| 234 | - throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
|
|
| 235 | - } else {
|
|
| 236 | - $this->lastLine = trim($message); |
|
| 237 | - $this->logLineCount++; |
|
| 238 | - |
|
| 239 | - if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
|
|
| 240 | - fflush($this->fileHandle); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Get the file path that the log is currently writing to |
|
| 248 | - * |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function getLogFilePath() |
|
| 252 | - {
|
|
| 253 | - return $this->logFilePath; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Get the last line logged to the log file |
|
| 258 | - * |
|
| 259 | - * @return string |
|
| 260 | - */ |
|
| 261 | - public function getLastLogLine() |
|
| 262 | - {
|
|
| 263 | - return $this->lastLine; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Formats the message for logging. |
|
| 268 | - * |
|
| 269 | - * @param string $level The Log Level of the message |
|
| 270 | - * @param string $message The message to log |
|
| 271 | - * @param array $context The context |
|
| 272 | - * @return string |
|
| 273 | - */ |
|
| 274 | - protected function formatMessage($level, $message, $context) |
|
| 275 | - {
|
|
| 276 | - if ($this->options['logFormat']) {
|
|
| 277 | - $parts = array( |
|
| 278 | - 'date' => $this->getTimestamp(), |
|
| 279 | - 'level' => strtoupper($level), |
|
| 280 | - 'level-padding' => str_repeat(' ', 9 - strlen($level)),
|
|
| 281 | - 'priority' => $this->logLevels[$level], |
|
| 282 | - 'message' => $message, |
|
| 283 | - 'context' => json_encode($context), |
|
| 284 | - ); |
|
| 285 | - $message = $this->options['logFormat']; |
|
| 286 | - foreach ($parts as $part => $value) {
|
|
| 287 | - $message = str_replace('{'.$part.'}', $value, $message);
|
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - } else {
|
|
| 291 | - $message = "[{$this->getTimestamp()}] [{$level}] {$message}";
|
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if ($this->options['appendContext'] && ! empty($context)) {
|
|
| 295 | - $message .= PHP_EOL.$this->indent($this->contextToString($context)); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return $message.PHP_EOL; |
|
| 299 | - |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Gets the correctly formatted Date/Time for the log entry. |
|
| 304 | - * |
|
| 305 | - * PHP DateTime is dump, and you have to resort to trickery to get microseconds |
|
| 306 | - * to work correctly, so here it is. |
|
| 307 | - * |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - private function getTimestamp() |
|
| 311 | - {
|
|
| 312 | - $originalTime = microtime(true); |
|
| 313 | - $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
|
|
| 314 | - $date = new DateTime(date('Y-m-d H:i:s.'.$micro, (int)$originalTime));
|
|
| 315 | - |
|
| 316 | - return $date->format($this->options['dateFormat']); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Takes the given context and coverts it to a string. |
|
| 321 | - * |
|
| 322 | - * @param array $context The Context |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - protected function contextToString($context) |
|
| 326 | - {
|
|
| 327 | - $export = ''; |
|
| 328 | - foreach ($context as $key => $value) {
|
|
| 329 | - $export .= "{$key}: ";
|
|
| 330 | - $export .= preg_replace(array( |
|
| 331 | - '/=>\s+([a-zA-Z])/im', |
|
| 332 | - '/array\(\s+\)/im', |
|
| 333 | - '/^ |\G /m' |
|
| 334 | - ), array( |
|
| 335 | - '=> $1', |
|
| 336 | - 'array()', |
|
| 337 | - ' ' |
|
| 338 | - ), str_replace('array (', 'array(', var_export($value, true)));
|
|
| 339 | - $export .= PHP_EOL; |
|
| 340 | - } |
|
| 341 | - return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
|
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Indents the given string with the given indent. |
|
| 346 | - * |
|
| 347 | - * @param string $string The string to indent |
|
| 348 | - * @param string $indent What to use as the indent. |
|
| 349 | - * @return string |
|
| 350 | - */ |
|
| 351 | - protected function indent($string, $indent = ' ') |
|
| 352 | - {
|
|
| 353 | - return $indent.str_replace("\n", "\n".$indent, $string);
|
|
| 354 | - } |
|
| 37 | + /** |
|
| 38 | + * KLogger options |
|
| 39 | + * Anything options not considered 'core' to the logging library should be |
|
| 40 | + * settable view the third parameter in the constructor |
|
| 41 | + * |
|
| 42 | + * Core options include the log file path and the log threshold |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $options = array ( |
|
| 47 | + 'extension' => 'txt', |
|
| 48 | + 'dateFormat' => 'Y-m-d G:i:s.u', |
|
| 49 | + 'filename' => false, |
|
| 50 | + 'flushFrequency' => false, |
|
| 51 | + 'prefix' => 'log_', |
|
| 52 | + 'logFormat' => false, |
|
| 53 | + 'appendContext' => true, |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Path to the log file |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | + private $logFilePath; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Current minimum logging threshold |
|
| 64 | + * @var integer |
|
| 65 | + */ |
|
| 66 | + protected $logLevelThreshold = LogLevel::DEBUG; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The number of lines logged in this instance's lifetime |
|
| 70 | + * @var int |
|
| 71 | + */ |
|
| 72 | + private $logLineCount = 0; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Log Levels |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $logLevels = array( |
|
| 79 | + LogLevel::EMERGENCY => 0, |
|
| 80 | + LogLevel::ALERT => 1, |
|
| 81 | + LogLevel::CRITICAL => 2, |
|
| 82 | + LogLevel::ERROR => 3, |
|
| 83 | + LogLevel::WARNING => 4, |
|
| 84 | + LogLevel::NOTICE => 5, |
|
| 85 | + LogLevel::INFO => 6, |
|
| 86 | + LogLevel::DEBUG => 7 |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * This holds the file handle for this instance's log file |
|
| 91 | + * @var resource |
|
| 92 | + */ |
|
| 93 | + private $fileHandle; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * This holds the last line logged to the logger |
|
| 97 | + * Used for unit tests |
|
| 98 | + * @var string |
|
| 99 | + */ |
|
| 100 | + private $lastLine = ''; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Octal notation for default permissions of the log file |
|
| 104 | + * @var integer |
|
| 105 | + */ |
|
| 106 | + private $defaultPermissions = 0777; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Class constructor |
|
| 110 | + * |
|
| 111 | + * @param string $logDirectory File path to the logging directory |
|
| 112 | + * @param string $logLevelThreshold The LogLevel Threshold |
|
| 113 | + * @param array $options |
|
| 114 | + * |
|
| 115 | + * @internal param string $logFilePrefix The prefix for the log file name |
|
| 116 | + * @internal param string $logFileExt The extension for the log file |
|
| 117 | + */ |
|
| 118 | + public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array()) |
|
| 119 | + {
|
|
| 120 | + $this->logLevelThreshold = $logLevelThreshold; |
|
| 121 | + $this->options = array_merge($this->options, $options); |
|
| 122 | + |
|
| 123 | + $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR); |
|
| 124 | + if ( ! file_exists($logDirectory)) {
|
|
| 125 | + mkdir($logDirectory, $this->defaultPermissions, true); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if(strpos($logDirectory, 'php://') === 0) {
|
|
| 129 | + $this->setLogToStdOut($logDirectory); |
|
| 130 | + $this->setFileHandle('w+');
|
|
| 131 | + } else {
|
|
| 132 | + $this->setLogFilePath($logDirectory); |
|
| 133 | + if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
|
|
| 134 | + throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
|
|
| 135 | + } |
|
| 136 | + $this->setFileHandle('a');
|
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + if ( ! $this->fileHandle) {
|
|
| 140 | + throw new RuntimeException('The file could not be opened. Check permissions.');
|
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param string $stdOutPath |
|
| 146 | + */ |
|
| 147 | + public function setLogToStdOut($stdOutPath) {
|
|
| 148 | + $this->logFilePath = $stdOutPath; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param string $logDirectory |
|
| 153 | + */ |
|
| 154 | + public function setLogFilePath($logDirectory) {
|
|
| 155 | + if ($this->options['filename']) {
|
|
| 156 | + if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
|
|
| 157 | + $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename']; |
|
| 158 | + } |
|
| 159 | + else {
|
|
| 160 | + $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension']; |
|
| 161 | + } |
|
| 162 | + } else {
|
|
| 163 | + $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
|
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param $writeMode |
|
| 169 | + * |
|
| 170 | + * @internal param resource $fileHandle |
|
| 171 | + */ |
|
| 172 | + public function setFileHandle($writeMode) {
|
|
| 173 | + $this->fileHandle = fopen($this->logFilePath, $writeMode); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Class destructor |
|
| 179 | + */ |
|
| 180 | + public function __destruct() |
|
| 181 | + {
|
|
| 182 | + if ($this->fileHandle) {
|
|
| 183 | + fclose($this->fileHandle); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Sets the date format used by all instances of KLogger |
|
| 189 | + * |
|
| 190 | + * @param string $dateFormat Valid format string for date() |
|
| 191 | + */ |
|
| 192 | + public function setDateFormat($dateFormat) |
|
| 193 | + {
|
|
| 194 | + $this->options['dateFormat'] = $dateFormat; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Sets the Log Level Threshold |
|
| 199 | + * |
|
| 200 | + * @param string $logLevelThreshold The log level threshold |
|
| 201 | + */ |
|
| 202 | + public function setLogLevelThreshold($logLevelThreshold) |
|
| 203 | + {
|
|
| 204 | + $this->logLevelThreshold = $logLevelThreshold; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Logs with an arbitrary level. |
|
| 209 | + * |
|
| 210 | + * @param mixed $level |
|
| 211 | + * @param string $message |
|
| 212 | + * @param array $context |
|
| 213 | + * @return null |
|
| 214 | + */ |
|
| 215 | + public function log($level, $message, array $context = array()) |
|
| 216 | + {
|
|
| 217 | + if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
|
|
| 218 | + return; |
|
| 219 | + } |
|
| 220 | + $message = $this->formatMessage($level, $message, $context); |
|
| 221 | + $this->write($message); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Writes a line to the log without prepending a status or timestamp |
|
| 226 | + * |
|
| 227 | + * @param string $message Line to write to the log |
|
| 228 | + * @return void |
|
| 229 | + */ |
|
| 230 | + public function write($message) |
|
| 231 | + {
|
|
| 232 | + if (null !== $this->fileHandle) {
|
|
| 233 | + if (fwrite($this->fileHandle, $message) === false) {
|
|
| 234 | + throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
|
|
| 235 | + } else {
|
|
| 236 | + $this->lastLine = trim($message); |
|
| 237 | + $this->logLineCount++; |
|
| 238 | + |
|
| 239 | + if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
|
|
| 240 | + fflush($this->fileHandle); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Get the file path that the log is currently writing to |
|
| 248 | + * |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function getLogFilePath() |
|
| 252 | + {
|
|
| 253 | + return $this->logFilePath; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Get the last line logged to the log file |
|
| 258 | + * |
|
| 259 | + * @return string |
|
| 260 | + */ |
|
| 261 | + public function getLastLogLine() |
|
| 262 | + {
|
|
| 263 | + return $this->lastLine; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Formats the message for logging. |
|
| 268 | + * |
|
| 269 | + * @param string $level The Log Level of the message |
|
| 270 | + * @param string $message The message to log |
|
| 271 | + * @param array $context The context |
|
| 272 | + * @return string |
|
| 273 | + */ |
|
| 274 | + protected function formatMessage($level, $message, $context) |
|
| 275 | + {
|
|
| 276 | + if ($this->options['logFormat']) {
|
|
| 277 | + $parts = array( |
|
| 278 | + 'date' => $this->getTimestamp(), |
|
| 279 | + 'level' => strtoupper($level), |
|
| 280 | + 'level-padding' => str_repeat(' ', 9 - strlen($level)),
|
|
| 281 | + 'priority' => $this->logLevels[$level], |
|
| 282 | + 'message' => $message, |
|
| 283 | + 'context' => json_encode($context), |
|
| 284 | + ); |
|
| 285 | + $message = $this->options['logFormat']; |
|
| 286 | + foreach ($parts as $part => $value) {
|
|
| 287 | + $message = str_replace('{'.$part.'}', $value, $message);
|
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + } else {
|
|
| 291 | + $message = "[{$this->getTimestamp()}] [{$level}] {$message}";
|
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if ($this->options['appendContext'] && ! empty($context)) {
|
|
| 295 | + $message .= PHP_EOL.$this->indent($this->contextToString($context)); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return $message.PHP_EOL; |
|
| 299 | + |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Gets the correctly formatted Date/Time for the log entry. |
|
| 304 | + * |
|
| 305 | + * PHP DateTime is dump, and you have to resort to trickery to get microseconds |
|
| 306 | + * to work correctly, so here it is. |
|
| 307 | + * |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + private function getTimestamp() |
|
| 311 | + {
|
|
| 312 | + $originalTime = microtime(true); |
|
| 313 | + $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
|
|
| 314 | + $date = new DateTime(date('Y-m-d H:i:s.'.$micro, (int)$originalTime));
|
|
| 315 | + |
|
| 316 | + return $date->format($this->options['dateFormat']); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Takes the given context and coverts it to a string. |
|
| 321 | + * |
|
| 322 | + * @param array $context The Context |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + protected function contextToString($context) |
|
| 326 | + {
|
|
| 327 | + $export = ''; |
|
| 328 | + foreach ($context as $key => $value) {
|
|
| 329 | + $export .= "{$key}: ";
|
|
| 330 | + $export .= preg_replace(array( |
|
| 331 | + '/=>\s+([a-zA-Z])/im', |
|
| 332 | + '/array\(\s+\)/im', |
|
| 333 | + '/^ |\G /m' |
|
| 334 | + ), array( |
|
| 335 | + '=> $1', |
|
| 336 | + 'array()', |
|
| 337 | + ' ' |
|
| 338 | + ), str_replace('array (', 'array(', var_export($value, true)));
|
|
| 339 | + $export .= PHP_EOL; |
|
| 340 | + } |
|
| 341 | + return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
|
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Indents the given string with the given indent. |
|
| 346 | + * |
|
| 347 | + * @param string $string The string to indent |
|
| 348 | + * @param string $indent What to use as the indent. |
|
| 349 | + * @return string |
|
| 350 | + */ |
|
| 351 | + protected function indent($string, $indent = ' ') |
|
| 352 | + {
|
|
| 353 | + return $indent.str_replace("\n", "\n".$indent, $string);
|
|
| 354 | + } |
|
| 355 | 355 | } |
@@ -12,152 +12,152 @@ |
||
| 12 | 12 | |
| 13 | 13 | class FileLoader implements LoaderInterface |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * The filesystem instance. |
|
| 17 | - * |
|
| 18 | - * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Filesystem\Filesystem |
|
| 19 | - */ |
|
| 20 | - protected $files; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * The default path for the loader. |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $path; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * All of the namespace hints. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $hints = []; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Create a new file loader instance. |
|
| 38 | - * |
|
| 39 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Filesystem\Filesystem $files |
|
| 40 | - * @param string $path |
|
| 41 | - * @return void |
|
| 42 | - */ |
|
| 43 | - public function __construct(Filesystem $files, $path) |
|
| 44 | - { |
|
| 45 | - $this->path = $path; |
|
| 46 | - $this->files = $files; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Load the messages for the given locale. |
|
| 51 | - * |
|
| 52 | - * @param string $locale |
|
| 53 | - * @param string $group |
|
| 54 | - * @param string $namespace |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function load($locale, $group, $namespace = null) |
|
| 58 | - { |
|
| 59 | - if ($group == '*' && $namespace == '*') { |
|
| 60 | - return $this->loadJsonPath($this->path, $locale); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - if (is_null($namespace) || $namespace == '*') { |
|
| 64 | - return $this->loadPath($this->path, $locale, $group); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $this->loadNamespaced($locale, $group, $namespace); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Load a namespaced translation group. |
|
| 72 | - * |
|
| 73 | - * @param string $locale |
|
| 74 | - * @param string $group |
|
| 75 | - * @param string $namespace |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - protected function loadNamespaced($locale, $group, $namespace) |
|
| 79 | - { |
|
| 80 | - if (isset($this->hints[$namespace])) { |
|
| 81 | - $lines = $this->loadPath($this->hints[$namespace], $locale, $group); |
|
| 82 | - |
|
| 83 | - return $this->loadNamespaceOverrides($lines, $locale, $group, $namespace); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return []; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Load a local namespaced translation group for overrides. |
|
| 91 | - * |
|
| 92 | - * @param array $lines |
|
| 93 | - * @param string $locale |
|
| 94 | - * @param string $group |
|
| 95 | - * @param string $namespace |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace) |
|
| 99 | - { |
|
| 100 | - $file = "{$this->path}/vendor/{$namespace}/{$locale}/{$group}.php"; |
|
| 101 | - |
|
| 102 | - if ($this->files->exists($file)) { |
|
| 103 | - return array_replace_recursive($lines, $this->files->getRequire($file)); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $lines; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Load a locale from a given path. |
|
| 111 | - * |
|
| 112 | - * @param string $path |
|
| 113 | - * @param string $locale |
|
| 114 | - * @param string $group |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - protected function loadPath($path, $locale, $group) |
|
| 118 | - { |
|
| 119 | - if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) { |
|
| 120 | - return $this->files->getRequire($full); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return []; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Load a locale from the given JSON file path. |
|
| 128 | - * |
|
| 129 | - * @param string $path |
|
| 130 | - * @param string $locale |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - protected function loadJsonPath($path, $locale) |
|
| 134 | - { |
|
| 135 | - if ($this->files->exists($full = "{$path}/{$locale}.json")) { |
|
| 136 | - return json_decode($this->files->get($full), true); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return []; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Add a new namespace to the loader. |
|
| 144 | - * |
|
| 145 | - * @param string $namespace |
|
| 146 | - * @param string $hint |
|
| 147 | - * @return void |
|
| 148 | - */ |
|
| 149 | - public function addNamespace($namespace, $hint) |
|
| 150 | - { |
|
| 151 | - $this->hints[$namespace] = $hint; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Get an array of all the registered namespaces. |
|
| 156 | - * |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - public function namespaces() |
|
| 160 | - { |
|
| 161 | - return $this->hints; |
|
| 162 | - } |
|
| 15 | + /** |
|
| 16 | + * The filesystem instance. |
|
| 17 | + * |
|
| 18 | + * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Filesystem\Filesystem |
|
| 19 | + */ |
|
| 20 | + protected $files; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * The default path for the loader. |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $path; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * All of the namespace hints. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $hints = []; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Create a new file loader instance. |
|
| 38 | + * |
|
| 39 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Filesystem\Filesystem $files |
|
| 40 | + * @param string $path |
|
| 41 | + * @return void |
|
| 42 | + */ |
|
| 43 | + public function __construct(Filesystem $files, $path) |
|
| 44 | + { |
|
| 45 | + $this->path = $path; |
|
| 46 | + $this->files = $files; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Load the messages for the given locale. |
|
| 51 | + * |
|
| 52 | + * @param string $locale |
|
| 53 | + * @param string $group |
|
| 54 | + * @param string $namespace |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function load($locale, $group, $namespace = null) |
|
| 58 | + { |
|
| 59 | + if ($group == '*' && $namespace == '*') { |
|
| 60 | + return $this->loadJsonPath($this->path, $locale); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + if (is_null($namespace) || $namespace == '*') { |
|
| 64 | + return $this->loadPath($this->path, $locale, $group); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $this->loadNamespaced($locale, $group, $namespace); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Load a namespaced translation group. |
|
| 72 | + * |
|
| 73 | + * @param string $locale |
|
| 74 | + * @param string $group |
|
| 75 | + * @param string $namespace |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + protected function loadNamespaced($locale, $group, $namespace) |
|
| 79 | + { |
|
| 80 | + if (isset($this->hints[$namespace])) { |
|
| 81 | + $lines = $this->loadPath($this->hints[$namespace], $locale, $group); |
|
| 82 | + |
|
| 83 | + return $this->loadNamespaceOverrides($lines, $locale, $group, $namespace); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return []; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Load a local namespaced translation group for overrides. |
|
| 91 | + * |
|
| 92 | + * @param array $lines |
|
| 93 | + * @param string $locale |
|
| 94 | + * @param string $group |
|
| 95 | + * @param string $namespace |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace) |
|
| 99 | + { |
|
| 100 | + $file = "{$this->path}/vendor/{$namespace}/{$locale}/{$group}.php"; |
|
| 101 | + |
|
| 102 | + if ($this->files->exists($file)) { |
|
| 103 | + return array_replace_recursive($lines, $this->files->getRequire($file)); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $lines; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Load a locale from a given path. |
|
| 111 | + * |
|
| 112 | + * @param string $path |
|
| 113 | + * @param string $locale |
|
| 114 | + * @param string $group |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + protected function loadPath($path, $locale, $group) |
|
| 118 | + { |
|
| 119 | + if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) { |
|
| 120 | + return $this->files->getRequire($full); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return []; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Load a locale from the given JSON file path. |
|
| 128 | + * |
|
| 129 | + * @param string $path |
|
| 130 | + * @param string $locale |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + protected function loadJsonPath($path, $locale) |
|
| 134 | + { |
|
| 135 | + if ($this->files->exists($full = "{$path}/{$locale}.json")) { |
|
| 136 | + return json_decode($this->files->get($full), true); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return []; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Add a new namespace to the loader. |
|
| 144 | + * |
|
| 145 | + * @param string $namespace |
|
| 146 | + * @param string $hint |
|
| 147 | + * @return void |
|
| 148 | + */ |
|
| 149 | + public function addNamespace($namespace, $hint) |
|
| 150 | + { |
|
| 151 | + $this->hints[$namespace] = $hint; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Get an array of all the registered namespaces. |
|
| 156 | + * |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + public function namespaces() |
|
| 160 | + { |
|
| 161 | + return $this->hints; |
|
| 162 | + } |
|
| 163 | 163 | } |
@@ -12,57 +12,57 @@ |
||
| 12 | 12 | |
| 13 | 13 | class TranslationServiceProvider extends ServiceProvider |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Indicates if loading of the provider is deferred. |
|
| 17 | - * |
|
| 18 | - * @var bool |
|
| 19 | - */ |
|
| 20 | - protected $defer = true; |
|
| 15 | + /** |
|
| 16 | + * Indicates if loading of the provider is deferred. |
|
| 17 | + * |
|
| 18 | + * @var bool |
|
| 19 | + */ |
|
| 20 | + protected $defer = true; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Register the service provider. |
|
| 24 | - * |
|
| 25 | - * @return void |
|
| 26 | - */ |
|
| 27 | - public function register() |
|
| 28 | - { |
|
| 29 | - $this->registerLoader(); |
|
| 22 | + /** |
|
| 23 | + * Register the service provider. |
|
| 24 | + * |
|
| 25 | + * @return void |
|
| 26 | + */ |
|
| 27 | + public function register() |
|
| 28 | + { |
|
| 29 | + $this->registerLoader(); |
|
| 30 | 30 | |
| 31 | - $this->app->singleton('translator', function ($app) { |
|
| 32 | - $loader = $app['translation.loader']; |
|
| 31 | + $this->app->singleton('translator', function ($app) { |
|
| 32 | + $loader = $app['translation.loader']; |
|
| 33 | 33 | |
| 34 | - // When registering the translator component, we'll need to set the default |
|
| 35 | - // locale as well as the fallback locale. So, we'll grab the application |
|
| 36 | - // configuration so we can easily get both of these values from there. |
|
| 37 | - $locale = $app['config']['app.locale']; |
|
| 34 | + // When registering the translator component, we'll need to set the default |
|
| 35 | + // locale as well as the fallback locale. So, we'll grab the application |
|
| 36 | + // configuration so we can easily get both of these values from there. |
|
| 37 | + $locale = $app['config']['app.locale']; |
|
| 38 | 38 | |
| 39 | - $trans = new Translator($loader, $locale); |
|
| 39 | + $trans = new Translator($loader, $locale); |
|
| 40 | 40 | |
| 41 | - $trans->setFallback($app['config']['app.fallback_locale']); |
|
| 41 | + $trans->setFallback($app['config']['app.fallback_locale']); |
|
| 42 | 42 | |
| 43 | - return $trans; |
|
| 44 | - }); |
|
| 45 | - } |
|
| 43 | + return $trans; |
|
| 44 | + }); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Register the translation line loader. |
|
| 49 | - * |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - protected function registerLoader() |
|
| 53 | - { |
|
| 54 | - $this->app->singleton('translation.loader', function ($app) { |
|
| 55 | - return new FileLoader($app['files'], $app['path.lang']); |
|
| 56 | - }); |
|
| 57 | - } |
|
| 47 | + /** |
|
| 48 | + * Register the translation line loader. |
|
| 49 | + * |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + protected function registerLoader() |
|
| 53 | + { |
|
| 54 | + $this->app->singleton('translation.loader', function ($app) { |
|
| 55 | + return new FileLoader($app['files'], $app['path.lang']); |
|
| 56 | + }); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get the services provided by the provider. |
|
| 61 | - * |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 64 | - public function provides() |
|
| 65 | - { |
|
| 66 | - return ['translator', 'translation.loader']; |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * Get the services provided by the provider. |
|
| 61 | + * |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | + public function provides() |
|
| 65 | + { |
|
| 66 | + return ['translator', 'translation.loader']; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -18,457 +18,457 @@ |
||
| 18 | 18 | |
| 19 | 19 | class Translator extends NamespacedItemResolver implements TranslatorContract |
| 20 | 20 | { |
| 21 | - use Macroable; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The loader implementation. |
|
| 25 | - * |
|
| 26 | - * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\LoaderInterface |
|
| 27 | - */ |
|
| 28 | - protected $loader; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The default locale being used by the translator. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $locale; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * The fallback locale used by the translator. |
|
| 39 | - * |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected $fallback; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * The array of loaded translation groups. |
|
| 46 | - * |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - protected $loaded = []; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The message selector. |
|
| 53 | - * |
|
| 54 | - * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\MessageSelector |
|
| 55 | - */ |
|
| 56 | - protected $selector; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Create a new translator instance. |
|
| 60 | - * |
|
| 61 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\LoaderInterface $loader |
|
| 62 | - * @param string $locale |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public function __construct(LoaderInterface $loader, $locale) |
|
| 66 | - { |
|
| 67 | - $this->loader = $loader; |
|
| 68 | - $this->locale = $locale; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Determine if a translation exists for a given locale. |
|
| 73 | - * |
|
| 74 | - * @param string $key |
|
| 75 | - * @param string|null $locale |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function hasForLocale($key, $locale = null) |
|
| 79 | - { |
|
| 80 | - return $this->has($key, $locale, false); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Determine if a translation exists. |
|
| 85 | - * |
|
| 86 | - * @param string $key |
|
| 87 | - * @param string|null $locale |
|
| 88 | - * @param bool $fallback |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function has($key, $locale = null, $fallback = true) |
|
| 92 | - { |
|
| 93 | - return $this->get($key, [], $locale, $fallback) !== $key; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Get the translation for a given key. |
|
| 98 | - * |
|
| 99 | - * @param string $key |
|
| 100 | - * @param array $replace |
|
| 101 | - * @param string $locale |
|
| 102 | - * @return string|array|null |
|
| 103 | - */ |
|
| 104 | - public function trans($key, array $replace = [], $locale = null) |
|
| 105 | - { |
|
| 106 | - return $this->get($key, $replace, $locale); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Get the translation for the given key. |
|
| 111 | - * |
|
| 112 | - * @param string $key |
|
| 113 | - * @param array $replace |
|
| 114 | - * @param string|null $locale |
|
| 115 | - * @param bool $fallback |
|
| 116 | - * @return string|array|null |
|
| 117 | - */ |
|
| 118 | - public function get($key, array $replace = [], $locale = null, $fallback = true) |
|
| 119 | - { |
|
| 120 | - list($namespace, $group, $item) = $this->parseKey($key); |
|
| 121 | - |
|
| 122 | - // Here we will get the locale that should be used for the language line. If one |
|
| 123 | - // was not passed, we will use the default locales which was given to us when |
|
| 124 | - // the translator was instantiated. Then, we can load the lines and return. |
|
| 125 | - $locales = $fallback ? $this->localeArray($locale) |
|
| 126 | - : [$locale ?: $this->locale]; |
|
| 127 | - |
|
| 128 | - foreach ($locales as $locale) { |
|
| 129 | - if (! is_null($line = $this->getLine( |
|
| 130 | - $namespace, $group, $locale, $item, $replace |
|
| 131 | - ))) { |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // If the line doesn't exist, we will return back the key which was requested as |
|
| 137 | - // that will be quick to spot in the UI if language keys are wrong or missing |
|
| 138 | - // from the application's language files. Otherwise we can return the line. |
|
| 139 | - if (isset($line)) { |
|
| 140 | - return $line; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $key; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Get the translation for a given key from the JSON translation files. |
|
| 148 | - * |
|
| 149 | - * @param string $key |
|
| 150 | - * @param array $replace |
|
| 151 | - * @param string $locale |
|
| 152 | - * @return string |
|
| 153 | - */ |
|
| 154 | - public function getFromJson($key, array $replace = [], $locale = null) |
|
| 155 | - { |
|
| 156 | - $locale = $locale ?: $this->locale; |
|
| 157 | - |
|
| 158 | - // For JSON translations, there is only one file per locale, so we will simply load |
|
| 159 | - // that file and then we will be ready to check the array for the key. These are |
|
| 160 | - // only one level deep so we do not need to do any fancy searching through it. |
|
| 161 | - $this->load('*', '*', $locale); |
|
| 162 | - |
|
| 163 | - $line = isset($this->loaded['*']['*'][$locale][$key]) |
|
| 164 | - ? $this->loaded['*']['*'][$locale][$key] : null; |
|
| 165 | - |
|
| 166 | - // If we can't find a translation for the JSON key, we will attempt to translate it |
|
| 167 | - // using the typical translation file. This way developers can always just use a |
|
| 168 | - // helper such as __ instead of having to pick between trans or __ with views. |
|
| 169 | - if (! isset($line)) { |
|
| 170 | - $fallback = $this->get($key, $replace, $locale); |
|
| 171 | - |
|
| 172 | - if ($fallback !== $key) { |
|
| 173 | - return $fallback; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $this->makeReplacements($line ?: $key, $replace); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Get a translation according to an integer value. |
|
| 182 | - * |
|
| 183 | - * @param string $key |
|
| 184 | - * @param int|array|\Countable $number |
|
| 185 | - * @param array $replace |
|
| 186 | - * @param string $locale |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function transChoice($key, $number, array $replace = [], $locale = null) |
|
| 190 | - { |
|
| 191 | - return $this->choice($key, $number, $replace, $locale); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Get a translation according to an integer value. |
|
| 196 | - * |
|
| 197 | - * @param string $key |
|
| 198 | - * @param int|array|\Countable $number |
|
| 199 | - * @param array $replace |
|
| 200 | - * @param string $locale |
|
| 201 | - * @return string |
|
| 202 | - */ |
|
| 203 | - public function choice($key, $number, array $replace = [], $locale = null) |
|
| 204 | - { |
|
| 205 | - $line = $this->get( |
|
| 206 | - $key, $replace, $locale = $this->localeForChoice($locale) |
|
| 207 | - ); |
|
| 208 | - |
|
| 209 | - // If the given "number" is actually an array or countable we will simply count the |
|
| 210 | - // number of elements in an instance. This allows developers to pass an array of |
|
| 211 | - // items without having to count it on their end first which gives bad syntax. |
|
| 212 | - if (is_array($number) || $number instanceof Countable) { |
|
| 213 | - $number = count($number); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $replace['count'] = $number; |
|
| 217 | - |
|
| 218 | - return $this->makeReplacements( |
|
| 219 | - $this->getSelector()->choose($line, $number, $locale), $replace |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Get the proper locale for a choice operation. |
|
| 225 | - * |
|
| 226 | - * @param string|null $locale |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - protected function localeForChoice($locale) |
|
| 230 | - { |
|
| 231 | - return $locale ?: $this->locale ?: $this->fallback; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Retrieve a language line out the loaded array. |
|
| 236 | - * |
|
| 237 | - * @param string $namespace |
|
| 238 | - * @param string $group |
|
| 239 | - * @param string $locale |
|
| 240 | - * @param string $item |
|
| 241 | - * @param array $replace |
|
| 242 | - * @return string|array|null |
|
| 243 | - */ |
|
| 244 | - protected function getLine($namespace, $group, $locale, $item, array $replace) |
|
| 245 | - { |
|
| 246 | - $this->load($namespace, $group, $locale); |
|
| 247 | - |
|
| 248 | - $line = Arr::get($this->loaded[$namespace][$group][$locale], $item); |
|
| 249 | - |
|
| 250 | - if (is_string($line)) { |
|
| 251 | - return $this->makeReplacements($line, $replace); |
|
| 252 | - } elseif (is_array($line) && count($line) > 0) { |
|
| 253 | - return $line; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Make the place-holder replacements on a line. |
|
| 259 | - * |
|
| 260 | - * @param string $line |
|
| 261 | - * @param array $replace |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - protected function makeReplacements($line, array $replace) |
|
| 265 | - { |
|
| 266 | - if (empty($replace)) { |
|
| 267 | - return $line; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $replace = $this->sortReplacements($replace); |
|
| 271 | - |
|
| 272 | - foreach ($replace as $key => $value) { |
|
| 273 | - $line = str_replace( |
|
| 274 | - [':'.$key, ':'.Str::upper($key), ':'.Str::ucfirst($key)], |
|
| 275 | - [$value, Str::upper($value), Str::ucfirst($value)], |
|
| 276 | - $line |
|
| 277 | - ); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $line; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Sort the replacements array. |
|
| 285 | - * |
|
| 286 | - * @param array $replace |
|
| 287 | - * @return array |
|
| 288 | - */ |
|
| 289 | - protected function sortReplacements(array $replace) |
|
| 290 | - { |
|
| 291 | - return (new Collection($replace))->sortBy(function ($value, $key) { |
|
| 292 | - return mb_strlen($key) * -1; |
|
| 293 | - })->all(); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Add translation lines to the given locale. |
|
| 298 | - * |
|
| 299 | - * @param array $lines |
|
| 300 | - * @param string $locale |
|
| 301 | - * @param string $namespace |
|
| 302 | - * @return void |
|
| 303 | - */ |
|
| 304 | - public function addLines(array $lines, $locale, $namespace = '*') |
|
| 305 | - { |
|
| 306 | - foreach ($lines as $key => $value) { |
|
| 307 | - list($group, $item) = explode('.', $key, 2); |
|
| 308 | - |
|
| 309 | - Arr::set($this->loaded, "$namespace.$group.$locale.$item", $value); |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Load the specified language group. |
|
| 315 | - * |
|
| 316 | - * @param string $namespace |
|
| 317 | - * @param string $group |
|
| 318 | - * @param string $locale |
|
| 319 | - * @return void |
|
| 320 | - */ |
|
| 321 | - public function load($namespace, $group, $locale) |
|
| 322 | - { |
|
| 323 | - if ($this->isLoaded($namespace, $group, $locale)) { |
|
| 324 | - return; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // The loader is responsible for returning the array of language lines for the |
|
| 328 | - // given namespace, group, and locale. We'll set the lines in this array of |
|
| 329 | - // lines that have already been loaded so that we can easily access them. |
|
| 330 | - $lines = $this->loader->load($locale, $group, $namespace); |
|
| 331 | - |
|
| 332 | - $this->loaded[$namespace][$group][$locale] = $lines; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Determine if the given group has been loaded. |
|
| 337 | - * |
|
| 338 | - * @param string $namespace |
|
| 339 | - * @param string $group |
|
| 340 | - * @param string $locale |
|
| 341 | - * @return bool |
|
| 342 | - */ |
|
| 343 | - protected function isLoaded($namespace, $group, $locale) |
|
| 344 | - { |
|
| 345 | - return isset($this->loaded[$namespace][$group][$locale]); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Add a new namespace to the loader. |
|
| 350 | - * |
|
| 351 | - * @param string $namespace |
|
| 352 | - * @param string $hint |
|
| 353 | - * @return void |
|
| 354 | - */ |
|
| 355 | - public function addNamespace($namespace, $hint) |
|
| 356 | - { |
|
| 357 | - $this->loader->addNamespace($namespace, $hint); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Parse a key into namespace, group, and item. |
|
| 362 | - * |
|
| 363 | - * @param string $key |
|
| 364 | - * @return array |
|
| 365 | - */ |
|
| 366 | - public function parseKey($key) |
|
| 367 | - { |
|
| 368 | - $segments = parent::parseKey($key); |
|
| 369 | - |
|
| 370 | - if (is_null($segments[0])) { |
|
| 371 | - $segments[0] = '*'; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - return $segments; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Get the array of locales to be checked. |
|
| 379 | - * |
|
| 380 | - * @param string|null $locale |
|
| 381 | - * @return array |
|
| 382 | - */ |
|
| 383 | - protected function localeArray($locale) |
|
| 384 | - { |
|
| 385 | - return array_filter([$locale ?: $this->locale, $this->fallback]); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Get the message selector instance. |
|
| 390 | - * |
|
| 391 | - * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\MessageSelector |
|
| 392 | - */ |
|
| 393 | - public function getSelector() |
|
| 394 | - { |
|
| 395 | - if (! isset($this->selector)) { |
|
| 396 | - $this->selector = new MessageSelector; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return $this->selector; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Set the message selector instance. |
|
| 404 | - * |
|
| 405 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\MessageSelector $selector |
|
| 406 | - * @return void |
|
| 407 | - */ |
|
| 408 | - public function setSelector(MessageSelector $selector) |
|
| 409 | - { |
|
| 410 | - $this->selector = $selector; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Get the language line loader implementation. |
|
| 415 | - * |
|
| 416 | - * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\LoaderInterface |
|
| 417 | - */ |
|
| 418 | - public function getLoader() |
|
| 419 | - { |
|
| 420 | - return $this->loader; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Get the default locale being used. |
|
| 425 | - * |
|
| 426 | - * @return string |
|
| 427 | - */ |
|
| 428 | - public function locale() |
|
| 429 | - { |
|
| 430 | - return $this->getLocale(); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Get the default locale being used. |
|
| 435 | - * |
|
| 436 | - * @return string |
|
| 437 | - */ |
|
| 438 | - public function getLocale() |
|
| 439 | - { |
|
| 440 | - return $this->locale; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Set the default locale. |
|
| 445 | - * |
|
| 446 | - * @param string $locale |
|
| 447 | - * @return void |
|
| 448 | - */ |
|
| 449 | - public function setLocale($locale) |
|
| 450 | - { |
|
| 451 | - $this->locale = $locale; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Get the fallback locale being used. |
|
| 456 | - * |
|
| 457 | - * @return string |
|
| 458 | - */ |
|
| 459 | - public function getFallback() |
|
| 460 | - { |
|
| 461 | - return $this->fallback; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Set the fallback locale being used. |
|
| 466 | - * |
|
| 467 | - * @param string $fallback |
|
| 468 | - * @return void |
|
| 469 | - */ |
|
| 470 | - public function setFallback($fallback) |
|
| 471 | - { |
|
| 472 | - $this->fallback = $fallback; |
|
| 473 | - } |
|
| 21 | + use Macroable; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The loader implementation. |
|
| 25 | + * |
|
| 26 | + * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\LoaderInterface |
|
| 27 | + */ |
|
| 28 | + protected $loader; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The default locale being used by the translator. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $locale; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * The fallback locale used by the translator. |
|
| 39 | + * |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected $fallback; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * The array of loaded translation groups. |
|
| 46 | + * |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + protected $loaded = []; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The message selector. |
|
| 53 | + * |
|
| 54 | + * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\MessageSelector |
|
| 55 | + */ |
|
| 56 | + protected $selector; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Create a new translator instance. |
|
| 60 | + * |
|
| 61 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\LoaderInterface $loader |
|
| 62 | + * @param string $locale |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public function __construct(LoaderInterface $loader, $locale) |
|
| 66 | + { |
|
| 67 | + $this->loader = $loader; |
|
| 68 | + $this->locale = $locale; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Determine if a translation exists for a given locale. |
|
| 73 | + * |
|
| 74 | + * @param string $key |
|
| 75 | + * @param string|null $locale |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function hasForLocale($key, $locale = null) |
|
| 79 | + { |
|
| 80 | + return $this->has($key, $locale, false); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Determine if a translation exists. |
|
| 85 | + * |
|
| 86 | + * @param string $key |
|
| 87 | + * @param string|null $locale |
|
| 88 | + * @param bool $fallback |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function has($key, $locale = null, $fallback = true) |
|
| 92 | + { |
|
| 93 | + return $this->get($key, [], $locale, $fallback) !== $key; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Get the translation for a given key. |
|
| 98 | + * |
|
| 99 | + * @param string $key |
|
| 100 | + * @param array $replace |
|
| 101 | + * @param string $locale |
|
| 102 | + * @return string|array|null |
|
| 103 | + */ |
|
| 104 | + public function trans($key, array $replace = [], $locale = null) |
|
| 105 | + { |
|
| 106 | + return $this->get($key, $replace, $locale); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Get the translation for the given key. |
|
| 111 | + * |
|
| 112 | + * @param string $key |
|
| 113 | + * @param array $replace |
|
| 114 | + * @param string|null $locale |
|
| 115 | + * @param bool $fallback |
|
| 116 | + * @return string|array|null |
|
| 117 | + */ |
|
| 118 | + public function get($key, array $replace = [], $locale = null, $fallback = true) |
|
| 119 | + { |
|
| 120 | + list($namespace, $group, $item) = $this->parseKey($key); |
|
| 121 | + |
|
| 122 | + // Here we will get the locale that should be used for the language line. If one |
|
| 123 | + // was not passed, we will use the default locales which was given to us when |
|
| 124 | + // the translator was instantiated. Then, we can load the lines and return. |
|
| 125 | + $locales = $fallback ? $this->localeArray($locale) |
|
| 126 | + : [$locale ?: $this->locale]; |
|
| 127 | + |
|
| 128 | + foreach ($locales as $locale) { |
|
| 129 | + if (! is_null($line = $this->getLine( |
|
| 130 | + $namespace, $group, $locale, $item, $replace |
|
| 131 | + ))) { |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // If the line doesn't exist, we will return back the key which was requested as |
|
| 137 | + // that will be quick to spot in the UI if language keys are wrong or missing |
|
| 138 | + // from the application's language files. Otherwise we can return the line. |
|
| 139 | + if (isset($line)) { |
|
| 140 | + return $line; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $key; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Get the translation for a given key from the JSON translation files. |
|
| 148 | + * |
|
| 149 | + * @param string $key |
|
| 150 | + * @param array $replace |
|
| 151 | + * @param string $locale |
|
| 152 | + * @return string |
|
| 153 | + */ |
|
| 154 | + public function getFromJson($key, array $replace = [], $locale = null) |
|
| 155 | + { |
|
| 156 | + $locale = $locale ?: $this->locale; |
|
| 157 | + |
|
| 158 | + // For JSON translations, there is only one file per locale, so we will simply load |
|
| 159 | + // that file and then we will be ready to check the array for the key. These are |
|
| 160 | + // only one level deep so we do not need to do any fancy searching through it. |
|
| 161 | + $this->load('*', '*', $locale); |
|
| 162 | + |
|
| 163 | + $line = isset($this->loaded['*']['*'][$locale][$key]) |
|
| 164 | + ? $this->loaded['*']['*'][$locale][$key] : null; |
|
| 165 | + |
|
| 166 | + // If we can't find a translation for the JSON key, we will attempt to translate it |
|
| 167 | + // using the typical translation file. This way developers can always just use a |
|
| 168 | + // helper such as __ instead of having to pick between trans or __ with views. |
|
| 169 | + if (! isset($line)) { |
|
| 170 | + $fallback = $this->get($key, $replace, $locale); |
|
| 171 | + |
|
| 172 | + if ($fallback !== $key) { |
|
| 173 | + return $fallback; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $this->makeReplacements($line ?: $key, $replace); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Get a translation according to an integer value. |
|
| 182 | + * |
|
| 183 | + * @param string $key |
|
| 184 | + * @param int|array|\Countable $number |
|
| 185 | + * @param array $replace |
|
| 186 | + * @param string $locale |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function transChoice($key, $number, array $replace = [], $locale = null) |
|
| 190 | + { |
|
| 191 | + return $this->choice($key, $number, $replace, $locale); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Get a translation according to an integer value. |
|
| 196 | + * |
|
| 197 | + * @param string $key |
|
| 198 | + * @param int|array|\Countable $number |
|
| 199 | + * @param array $replace |
|
| 200 | + * @param string $locale |
|
| 201 | + * @return string |
|
| 202 | + */ |
|
| 203 | + public function choice($key, $number, array $replace = [], $locale = null) |
|
| 204 | + { |
|
| 205 | + $line = $this->get( |
|
| 206 | + $key, $replace, $locale = $this->localeForChoice($locale) |
|
| 207 | + ); |
|
| 208 | + |
|
| 209 | + // If the given "number" is actually an array or countable we will simply count the |
|
| 210 | + // number of elements in an instance. This allows developers to pass an array of |
|
| 211 | + // items without having to count it on their end first which gives bad syntax. |
|
| 212 | + if (is_array($number) || $number instanceof Countable) { |
|
| 213 | + $number = count($number); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $replace['count'] = $number; |
|
| 217 | + |
|
| 218 | + return $this->makeReplacements( |
|
| 219 | + $this->getSelector()->choose($line, $number, $locale), $replace |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Get the proper locale for a choice operation. |
|
| 225 | + * |
|
| 226 | + * @param string|null $locale |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + protected function localeForChoice($locale) |
|
| 230 | + { |
|
| 231 | + return $locale ?: $this->locale ?: $this->fallback; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Retrieve a language line out the loaded array. |
|
| 236 | + * |
|
| 237 | + * @param string $namespace |
|
| 238 | + * @param string $group |
|
| 239 | + * @param string $locale |
|
| 240 | + * @param string $item |
|
| 241 | + * @param array $replace |
|
| 242 | + * @return string|array|null |
|
| 243 | + */ |
|
| 244 | + protected function getLine($namespace, $group, $locale, $item, array $replace) |
|
| 245 | + { |
|
| 246 | + $this->load($namespace, $group, $locale); |
|
| 247 | + |
|
| 248 | + $line = Arr::get($this->loaded[$namespace][$group][$locale], $item); |
|
| 249 | + |
|
| 250 | + if (is_string($line)) { |
|
| 251 | + return $this->makeReplacements($line, $replace); |
|
| 252 | + } elseif (is_array($line) && count($line) > 0) { |
|
| 253 | + return $line; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Make the place-holder replacements on a line. |
|
| 259 | + * |
|
| 260 | + * @param string $line |
|
| 261 | + * @param array $replace |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + protected function makeReplacements($line, array $replace) |
|
| 265 | + { |
|
| 266 | + if (empty($replace)) { |
|
| 267 | + return $line; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $replace = $this->sortReplacements($replace); |
|
| 271 | + |
|
| 272 | + foreach ($replace as $key => $value) { |
|
| 273 | + $line = str_replace( |
|
| 274 | + [':'.$key, ':'.Str::upper($key), ':'.Str::ucfirst($key)], |
|
| 275 | + [$value, Str::upper($value), Str::ucfirst($value)], |
|
| 276 | + $line |
|
| 277 | + ); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $line; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Sort the replacements array. |
|
| 285 | + * |
|
| 286 | + * @param array $replace |
|
| 287 | + * @return array |
|
| 288 | + */ |
|
| 289 | + protected function sortReplacements(array $replace) |
|
| 290 | + { |
|
| 291 | + return (new Collection($replace))->sortBy(function ($value, $key) { |
|
| 292 | + return mb_strlen($key) * -1; |
|
| 293 | + })->all(); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Add translation lines to the given locale. |
|
| 298 | + * |
|
| 299 | + * @param array $lines |
|
| 300 | + * @param string $locale |
|
| 301 | + * @param string $namespace |
|
| 302 | + * @return void |
|
| 303 | + */ |
|
| 304 | + public function addLines(array $lines, $locale, $namespace = '*') |
|
| 305 | + { |
|
| 306 | + foreach ($lines as $key => $value) { |
|
| 307 | + list($group, $item) = explode('.', $key, 2); |
|
| 308 | + |
|
| 309 | + Arr::set($this->loaded, "$namespace.$group.$locale.$item", $value); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Load the specified language group. |
|
| 315 | + * |
|
| 316 | + * @param string $namespace |
|
| 317 | + * @param string $group |
|
| 318 | + * @param string $locale |
|
| 319 | + * @return void |
|
| 320 | + */ |
|
| 321 | + public function load($namespace, $group, $locale) |
|
| 322 | + { |
|
| 323 | + if ($this->isLoaded($namespace, $group, $locale)) { |
|
| 324 | + return; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // The loader is responsible for returning the array of language lines for the |
|
| 328 | + // given namespace, group, and locale. We'll set the lines in this array of |
|
| 329 | + // lines that have already been loaded so that we can easily access them. |
|
| 330 | + $lines = $this->loader->load($locale, $group, $namespace); |
|
| 331 | + |
|
| 332 | + $this->loaded[$namespace][$group][$locale] = $lines; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Determine if the given group has been loaded. |
|
| 337 | + * |
|
| 338 | + * @param string $namespace |
|
| 339 | + * @param string $group |
|
| 340 | + * @param string $locale |
|
| 341 | + * @return bool |
|
| 342 | + */ |
|
| 343 | + protected function isLoaded($namespace, $group, $locale) |
|
| 344 | + { |
|
| 345 | + return isset($this->loaded[$namespace][$group][$locale]); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Add a new namespace to the loader. |
|
| 350 | + * |
|
| 351 | + * @param string $namespace |
|
| 352 | + * @param string $hint |
|
| 353 | + * @return void |
|
| 354 | + */ |
|
| 355 | + public function addNamespace($namespace, $hint) |
|
| 356 | + { |
|
| 357 | + $this->loader->addNamespace($namespace, $hint); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Parse a key into namespace, group, and item. |
|
| 362 | + * |
|
| 363 | + * @param string $key |
|
| 364 | + * @return array |
|
| 365 | + */ |
|
| 366 | + public function parseKey($key) |
|
| 367 | + { |
|
| 368 | + $segments = parent::parseKey($key); |
|
| 369 | + |
|
| 370 | + if (is_null($segments[0])) { |
|
| 371 | + $segments[0] = '*'; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + return $segments; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Get the array of locales to be checked. |
|
| 379 | + * |
|
| 380 | + * @param string|null $locale |
|
| 381 | + * @return array |
|
| 382 | + */ |
|
| 383 | + protected function localeArray($locale) |
|
| 384 | + { |
|
| 385 | + return array_filter([$locale ?: $this->locale, $this->fallback]); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Get the message selector instance. |
|
| 390 | + * |
|
| 391 | + * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\MessageSelector |
|
| 392 | + */ |
|
| 393 | + public function getSelector() |
|
| 394 | + { |
|
| 395 | + if (! isset($this->selector)) { |
|
| 396 | + $this->selector = new MessageSelector; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return $this->selector; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Set the message selector instance. |
|
| 404 | + * |
|
| 405 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\MessageSelector $selector |
|
| 406 | + * @return void |
|
| 407 | + */ |
|
| 408 | + public function setSelector(MessageSelector $selector) |
|
| 409 | + { |
|
| 410 | + $this->selector = $selector; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Get the language line loader implementation. |
|
| 415 | + * |
|
| 416 | + * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\LoaderInterface |
|
| 417 | + */ |
|
| 418 | + public function getLoader() |
|
| 419 | + { |
|
| 420 | + return $this->loader; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Get the default locale being used. |
|
| 425 | + * |
|
| 426 | + * @return string |
|
| 427 | + */ |
|
| 428 | + public function locale() |
|
| 429 | + { |
|
| 430 | + return $this->getLocale(); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Get the default locale being used. |
|
| 435 | + * |
|
| 436 | + * @return string |
|
| 437 | + */ |
|
| 438 | + public function getLocale() |
|
| 439 | + { |
|
| 440 | + return $this->locale; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Set the default locale. |
|
| 445 | + * |
|
| 446 | + * @param string $locale |
|
| 447 | + * @return void |
|
| 448 | + */ |
|
| 449 | + public function setLocale($locale) |
|
| 450 | + { |
|
| 451 | + $this->locale = $locale; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Get the fallback locale being used. |
|
| 456 | + * |
|
| 457 | + * @return string |
|
| 458 | + */ |
|
| 459 | + public function getFallback() |
|
| 460 | + { |
|
| 461 | + return $this->fallback; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Set the fallback locale being used. |
|
| 466 | + * |
|
| 467 | + * @param string $fallback |
|
| 468 | + * @return void |
|
| 469 | + */ |
|
| 470 | + public function setFallback($fallback) |
|
| 471 | + { |
|
| 472 | + $this->fallback = $fallback; |
|
| 473 | + } |
|
| 474 | 474 | } |
@@ -12,407 +12,407 @@ |
||
| 12 | 12 | |
| 13 | 13 | class MessageSelector |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Select a proper translation string based on the given number. |
|
| 17 | - * |
|
| 18 | - * @param string $line |
|
| 19 | - * @param int $number |
|
| 20 | - * @param string $locale |
|
| 21 | - * @return mixed |
|
| 22 | - */ |
|
| 23 | - public function choose($line, $number, $locale) |
|
| 24 | - { |
|
| 25 | - $segments = explode('|', $line); |
|
| 15 | + /** |
|
| 16 | + * Select a proper translation string based on the given number. |
|
| 17 | + * |
|
| 18 | + * @param string $line |
|
| 19 | + * @param int $number |
|
| 20 | + * @param string $locale |
|
| 21 | + * @return mixed |
|
| 22 | + */ |
|
| 23 | + public function choose($line, $number, $locale) |
|
| 24 | + { |
|
| 25 | + $segments = explode('|', $line); |
|
| 26 | 26 | |
| 27 | - if (($value = $this->extract($segments, $number)) !== null) { |
|
| 28 | - return trim($value); |
|
| 29 | - } |
|
| 27 | + if (($value = $this->extract($segments, $number)) !== null) { |
|
| 28 | + return trim($value); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $segments = $this->stripConditions($segments); |
|
| 31 | + $segments = $this->stripConditions($segments); |
|
| 32 | 32 | |
| 33 | - $pluralIndex = $this->getPluralIndex($locale, $number); |
|
| 33 | + $pluralIndex = $this->getPluralIndex($locale, $number); |
|
| 34 | 34 | |
| 35 | - if (count($segments) == 1 || ! isset($segments[$pluralIndex])) { |
|
| 36 | - return $segments[0]; |
|
| 37 | - } |
|
| 35 | + if (count($segments) == 1 || ! isset($segments[$pluralIndex])) { |
|
| 36 | + return $segments[0]; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return $segments[$pluralIndex]; |
|
| 40 | - } |
|
| 39 | + return $segments[$pluralIndex]; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Extract a translation string using inline conditions. |
|
| 44 | - * |
|
| 45 | - * @param array $segments |
|
| 46 | - * @param int $number |
|
| 47 | - * @return mixed |
|
| 48 | - */ |
|
| 49 | - private function extract($segments, $number) |
|
| 50 | - { |
|
| 51 | - foreach ($segments as $part) { |
|
| 52 | - if (! is_null($line = $this->extractFromString($part, $number))) { |
|
| 53 | - return $line; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - } |
|
| 42 | + /** |
|
| 43 | + * Extract a translation string using inline conditions. |
|
| 44 | + * |
|
| 45 | + * @param array $segments |
|
| 46 | + * @param int $number |
|
| 47 | + * @return mixed |
|
| 48 | + */ |
|
| 49 | + private function extract($segments, $number) |
|
| 50 | + { |
|
| 51 | + foreach ($segments as $part) { |
|
| 52 | + if (! is_null($line = $this->extractFromString($part, $number))) { |
|
| 53 | + return $line; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Get the translation string if the condition matches. |
|
| 60 | - * |
|
| 61 | - * @param string $part |
|
| 62 | - * @param int $number |
|
| 63 | - * @return mixed |
|
| 64 | - */ |
|
| 65 | - private function extractFromString($part, $number) |
|
| 66 | - { |
|
| 67 | - preg_match('/^[\{\[]([^\[\]\{\}]*)[\}\]](.*)/s', $part, $matches); |
|
| 58 | + /** |
|
| 59 | + * Get the translation string if the condition matches. |
|
| 60 | + * |
|
| 61 | + * @param string $part |
|
| 62 | + * @param int $number |
|
| 63 | + * @return mixed |
|
| 64 | + */ |
|
| 65 | + private function extractFromString($part, $number) |
|
| 66 | + { |
|
| 67 | + preg_match('/^[\{\[]([^\[\]\{\}]*)[\}\]](.*)/s', $part, $matches); |
|
| 68 | 68 | |
| 69 | - if (count($matches) != 3) { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 69 | + if (count($matches) != 3) { |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $condition = $matches[1]; |
|
| 73 | + $condition = $matches[1]; |
|
| 74 | 74 | |
| 75 | - $value = $matches[2]; |
|
| 75 | + $value = $matches[2]; |
|
| 76 | 76 | |
| 77 | - if (Str::contains($condition, ',')) { |
|
| 78 | - list($from, $to) = explode(',', $condition, 2); |
|
| 77 | + if (Str::contains($condition, ',')) { |
|
| 78 | + list($from, $to) = explode(',', $condition, 2); |
|
| 79 | 79 | |
| 80 | - if ($to == '*' && $number >= $from) { |
|
| 81 | - return $value; |
|
| 82 | - } elseif ($from == '*' && $number <= $to) { |
|
| 83 | - return $value; |
|
| 84 | - } elseif ($number >= $from && $number <= $to) { |
|
| 85 | - return $value; |
|
| 86 | - } |
|
| 87 | - } |
|
| 80 | + if ($to == '*' && $number >= $from) { |
|
| 81 | + return $value; |
|
| 82 | + } elseif ($from == '*' && $number <= $to) { |
|
| 83 | + return $value; |
|
| 84 | + } elseif ($number >= $from && $number <= $to) { |
|
| 85 | + return $value; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return $condition == $number ? $value : null; |
|
| 90 | - } |
|
| 89 | + return $condition == $number ? $value : null; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Strip the inline conditions from each segment, just leaving the text. |
|
| 94 | - * |
|
| 95 | - * @param array $segments |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - private function stripConditions($segments) |
|
| 99 | - { |
|
| 100 | - return collect($segments)->map(function ($part) { |
|
| 101 | - return preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part); |
|
| 102 | - })->all(); |
|
| 103 | - } |
|
| 92 | + /** |
|
| 93 | + * Strip the inline conditions from each segment, just leaving the text. |
|
| 94 | + * |
|
| 95 | + * @param array $segments |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + private function stripConditions($segments) |
|
| 99 | + { |
|
| 100 | + return collect($segments)->map(function ($part) { |
|
| 101 | + return preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part); |
|
| 102 | + })->all(); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Get the index to use for pluralization. |
|
| 107 | - * |
|
| 108 | - * The plural rules are derived from code of the Zend Framework (2010-09-25), which |
|
| 109 | - * is subject to the new BSD license (http://framework.zend.com/license/new-bsd) |
|
| 110 | - * Copyright (c) 2005-2010 - Zend Technologies USA Inc. (http://www.zend.com) |
|
| 111 | - * |
|
| 112 | - * @param string $locale |
|
| 113 | - * @param int $number |
|
| 114 | - * @return int |
|
| 115 | - */ |
|
| 116 | - public function getPluralIndex($locale, $number) |
|
| 117 | - { |
|
| 118 | - switch ($locale) { |
|
| 119 | - case 'az': |
|
| 120 | - case 'az_AZ': |
|
| 121 | - case 'bo': |
|
| 122 | - case 'bo_CN': |
|
| 123 | - case 'bo_IN': |
|
| 124 | - case 'dz': |
|
| 125 | - case 'dz_BT': |
|
| 126 | - case 'id': |
|
| 127 | - case 'id_ID': |
|
| 128 | - case 'ja': |
|
| 129 | - case 'ja_JP': |
|
| 130 | - case 'jv': |
|
| 131 | - case 'ka': |
|
| 132 | - case 'ka_GE': |
|
| 133 | - case 'km': |
|
| 134 | - case 'km_KH': |
|
| 135 | - case 'kn': |
|
| 136 | - case 'kn_IN': |
|
| 137 | - case 'ko': |
|
| 138 | - case 'ko_KR': |
|
| 139 | - case 'ms': |
|
| 140 | - case 'ms_MY': |
|
| 141 | - case 'th': |
|
| 142 | - case 'th_TH': |
|
| 143 | - case 'tr': |
|
| 144 | - case 'tr_CY': |
|
| 145 | - case 'tr_TR': |
|
| 146 | - case 'vi': |
|
| 147 | - case 'vi_VN': |
|
| 148 | - case 'zh': |
|
| 149 | - case 'zh_CN': |
|
| 150 | - case 'zh_HK': |
|
| 151 | - case 'zh_SG': |
|
| 152 | - case 'zh_TW': |
|
| 153 | - return 0; |
|
| 154 | - case 'af': |
|
| 155 | - case 'af_ZA': |
|
| 156 | - case 'bn': |
|
| 157 | - case 'bn_BD': |
|
| 158 | - case 'bn_IN': |
|
| 159 | - case 'bg': |
|
| 160 | - case 'bg_BG': |
|
| 161 | - case 'ca': |
|
| 162 | - case 'ca_AD': |
|
| 163 | - case 'ca_ES': |
|
| 164 | - case 'ca_FR': |
|
| 165 | - case 'ca_IT': |
|
| 166 | - case 'da': |
|
| 167 | - case 'da_DK': |
|
| 168 | - case 'de': |
|
| 169 | - case 'de_AT': |
|
| 170 | - case 'de_BE': |
|
| 171 | - case 'de_CH': |
|
| 172 | - case 'de_DE': |
|
| 173 | - case 'de_LI': |
|
| 174 | - case 'de_LU': |
|
| 175 | - case 'el': |
|
| 176 | - case 'el_CY': |
|
| 177 | - case 'el_GR': |
|
| 178 | - case 'en': |
|
| 179 | - case 'en_AG': |
|
| 180 | - case 'en_AU': |
|
| 181 | - case 'en_BW': |
|
| 182 | - case 'en_CA': |
|
| 183 | - case 'en_DK': |
|
| 184 | - case 'en_GB': |
|
| 185 | - case 'en_HK': |
|
| 186 | - case 'en_IE': |
|
| 187 | - case 'en_IN': |
|
| 188 | - case 'en_NG': |
|
| 189 | - case 'en_NZ': |
|
| 190 | - case 'en_PH': |
|
| 191 | - case 'en_SG': |
|
| 192 | - case 'en_US': |
|
| 193 | - case 'en_ZA': |
|
| 194 | - case 'en_ZM': |
|
| 195 | - case 'en_ZW': |
|
| 196 | - case 'eo': |
|
| 197 | - case 'eo_US': |
|
| 198 | - case 'es': |
|
| 199 | - case 'es_AR': |
|
| 200 | - case 'es_BO': |
|
| 201 | - case 'es_CL': |
|
| 202 | - case 'es_CO': |
|
| 203 | - case 'es_CR': |
|
| 204 | - case 'es_CU': |
|
| 205 | - case 'es_DO': |
|
| 206 | - case 'es_EC': |
|
| 207 | - case 'es_ES': |
|
| 208 | - case 'es_GT': |
|
| 209 | - case 'es_HN': |
|
| 210 | - case 'es_MX': |
|
| 211 | - case 'es_NI': |
|
| 212 | - case 'es_PA': |
|
| 213 | - case 'es_PE': |
|
| 214 | - case 'es_PR': |
|
| 215 | - case 'es_PY': |
|
| 216 | - case 'es_SV': |
|
| 217 | - case 'es_US': |
|
| 218 | - case 'es_UY': |
|
| 219 | - case 'es_VE': |
|
| 220 | - case 'et': |
|
| 221 | - case 'et_EE': |
|
| 222 | - case 'eu': |
|
| 223 | - case 'eu_ES': |
|
| 224 | - case 'eu_FR': |
|
| 225 | - case 'fa': |
|
| 226 | - case 'fa_IR': |
|
| 227 | - case 'fi': |
|
| 228 | - case 'fi_FI': |
|
| 229 | - case 'fo': |
|
| 230 | - case 'fo_FO': |
|
| 231 | - case 'fur': |
|
| 232 | - case 'fur_IT': |
|
| 233 | - case 'fy': |
|
| 234 | - case 'fy_DE': |
|
| 235 | - case 'fy_NL': |
|
| 236 | - case 'gl': |
|
| 237 | - case 'gl_ES': |
|
| 238 | - case 'gu': |
|
| 239 | - case 'gu_IN': |
|
| 240 | - case 'ha': |
|
| 241 | - case 'ha_NG': |
|
| 242 | - case 'he': |
|
| 243 | - case 'he_IL': |
|
| 244 | - case 'hu': |
|
| 245 | - case 'hu_HU': |
|
| 246 | - case 'is': |
|
| 247 | - case 'is_IS': |
|
| 248 | - case 'it': |
|
| 249 | - case 'it_CH': |
|
| 250 | - case 'it_IT': |
|
| 251 | - case 'ku': |
|
| 252 | - case 'ku_TR': |
|
| 253 | - case 'lb': |
|
| 254 | - case 'lb_LU': |
|
| 255 | - case 'ml': |
|
| 256 | - case 'ml_IN': |
|
| 257 | - case 'mn': |
|
| 258 | - case 'mn_MN': |
|
| 259 | - case 'mr': |
|
| 260 | - case 'mr_IN': |
|
| 261 | - case 'nah': |
|
| 262 | - case 'nb': |
|
| 263 | - case 'nb_NO': |
|
| 264 | - case 'ne': |
|
| 265 | - case 'ne_NP': |
|
| 266 | - case 'nl': |
|
| 267 | - case 'nl_AW': |
|
| 268 | - case 'nl_BE': |
|
| 269 | - case 'nl_NL': |
|
| 270 | - case 'nn': |
|
| 271 | - case 'nn_NO': |
|
| 272 | - case 'no': |
|
| 273 | - case 'om': |
|
| 274 | - case 'om_ET': |
|
| 275 | - case 'om_KE': |
|
| 276 | - case 'or': |
|
| 277 | - case 'or_IN': |
|
| 278 | - case 'pa': |
|
| 279 | - case 'pa_IN': |
|
| 280 | - case 'pa_PK': |
|
| 281 | - case 'pap': |
|
| 282 | - case 'pap_AN': |
|
| 283 | - case 'pap_AW': |
|
| 284 | - case 'pap_CW': |
|
| 285 | - case 'ps': |
|
| 286 | - case 'ps_AF': |
|
| 287 | - case 'pt': |
|
| 288 | - case 'pt_BR': |
|
| 289 | - case 'pt_PT': |
|
| 290 | - case 'so': |
|
| 291 | - case 'so_DJ': |
|
| 292 | - case 'so_ET': |
|
| 293 | - case 'so_KE': |
|
| 294 | - case 'so_SO': |
|
| 295 | - case 'sq': |
|
| 296 | - case 'sq_AL': |
|
| 297 | - case 'sq_MK': |
|
| 298 | - case 'sv': |
|
| 299 | - case 'sv_FI': |
|
| 300 | - case 'sv_SE': |
|
| 301 | - case 'sw': |
|
| 302 | - case 'sw_KE': |
|
| 303 | - case 'sw_TZ': |
|
| 304 | - case 'ta': |
|
| 305 | - case 'ta_IN': |
|
| 306 | - case 'ta_LK': |
|
| 307 | - case 'te': |
|
| 308 | - case 'te_IN': |
|
| 309 | - case 'tk': |
|
| 310 | - case 'tk_TM': |
|
| 311 | - case 'ur': |
|
| 312 | - case 'ur_IN': |
|
| 313 | - case 'ur_PK': |
|
| 314 | - case 'zu': |
|
| 315 | - case 'zu_ZA': |
|
| 316 | - return ($number == 1) ? 0 : 1; |
|
| 317 | - case 'am': |
|
| 318 | - case 'am_ET': |
|
| 319 | - case 'bh': |
|
| 320 | - case 'fil': |
|
| 321 | - case 'fil_PH': |
|
| 322 | - case 'fr': |
|
| 323 | - case 'fr_BE': |
|
| 324 | - case 'fr_CA': |
|
| 325 | - case 'fr_CH': |
|
| 326 | - case 'fr_FR': |
|
| 327 | - case 'fr_LU': |
|
| 328 | - case 'gun': |
|
| 329 | - case 'hi': |
|
| 330 | - case 'hi_IN': |
|
| 331 | - case 'hy': |
|
| 332 | - case 'hy_AM': |
|
| 333 | - case 'ln': |
|
| 334 | - case 'ln_CD': |
|
| 335 | - case 'mg': |
|
| 336 | - case 'mg_MG': |
|
| 337 | - case 'nso': |
|
| 338 | - case 'nso_ZA': |
|
| 339 | - case 'ti': |
|
| 340 | - case 'ti_ER': |
|
| 341 | - case 'ti_ET': |
|
| 342 | - case 'wa': |
|
| 343 | - case 'wa_BE': |
|
| 344 | - case 'xbr': |
|
| 345 | - return (($number == 0) || ($number == 1)) ? 0 : 1; |
|
| 346 | - case 'be': |
|
| 347 | - case 'be_BY': |
|
| 348 | - case 'bs': |
|
| 349 | - case 'bs_BA': |
|
| 350 | - case 'hr': |
|
| 351 | - case 'hr_HR': |
|
| 352 | - case 'ru': |
|
| 353 | - case 'ru_RU': |
|
| 354 | - case 'ru_UA': |
|
| 355 | - case 'sr': |
|
| 356 | - case 'sr_ME': |
|
| 357 | - case 'sr_RS': |
|
| 358 | - case 'uk': |
|
| 359 | - case 'uk_UA': |
|
| 360 | - return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); |
|
| 361 | - case 'cs': |
|
| 362 | - case 'cs_CZ': |
|
| 363 | - case 'sk': |
|
| 364 | - case 'sk_SK': |
|
| 365 | - return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2); |
|
| 366 | - case 'ga': |
|
| 367 | - case 'ga_IE': |
|
| 368 | - return ($number == 1) ? 0 : (($number == 2) ? 1 : 2); |
|
| 369 | - case 'lt': |
|
| 370 | - case 'lt_LT': |
|
| 371 | - return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); |
|
| 372 | - case 'sl': |
|
| 373 | - case 'sl_SI': |
|
| 374 | - return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3)); |
|
| 375 | - case 'mk': |
|
| 376 | - case 'mk_MK': |
|
| 377 | - return ($number % 10 == 1) ? 0 : 1; |
|
| 378 | - case 'mt': |
|
| 379 | - case 'mt_MT': |
|
| 380 | - return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)); |
|
| 381 | - case 'lv': |
|
| 382 | - case 'lv_LV': |
|
| 383 | - return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2); |
|
| 384 | - case 'pl': |
|
| 385 | - case 'pl_PL': |
|
| 386 | - return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2); |
|
| 387 | - case 'cy': |
|
| 388 | - case 'cy_GB': |
|
| 389 | - return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3)); |
|
| 390 | - case 'ro': |
|
| 391 | - case 'ro_RO': |
|
| 392 | - return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2); |
|
| 393 | - case 'ar': |
|
| 394 | - case 'ar_AE': |
|
| 395 | - case 'ar_BH': |
|
| 396 | - case 'ar_DZ': |
|
| 397 | - case 'ar_EG': |
|
| 398 | - case 'ar_IN': |
|
| 399 | - case 'ar_IQ': |
|
| 400 | - case 'ar_JO': |
|
| 401 | - case 'ar_KW': |
|
| 402 | - case 'ar_LB': |
|
| 403 | - case 'ar_LY': |
|
| 404 | - case 'ar_MA': |
|
| 405 | - case 'ar_OM': |
|
| 406 | - case 'ar_QA': |
|
| 407 | - case 'ar_SA': |
|
| 408 | - case 'ar_SD': |
|
| 409 | - case 'ar_SS': |
|
| 410 | - case 'ar_SY': |
|
| 411 | - case 'ar_TN': |
|
| 412 | - case 'ar_YE': |
|
| 413 | - return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))); |
|
| 414 | - default: |
|
| 415 | - return 0; |
|
| 416 | - } |
|
| 417 | - } |
|
| 105 | + /** |
|
| 106 | + * Get the index to use for pluralization. |
|
| 107 | + * |
|
| 108 | + * The plural rules are derived from code of the Zend Framework (2010-09-25), which |
|
| 109 | + * is subject to the new BSD license (http://framework.zend.com/license/new-bsd) |
|
| 110 | + * Copyright (c) 2005-2010 - Zend Technologies USA Inc. (http://www.zend.com) |
|
| 111 | + * |
|
| 112 | + * @param string $locale |
|
| 113 | + * @param int $number |
|
| 114 | + * @return int |
|
| 115 | + */ |
|
| 116 | + public function getPluralIndex($locale, $number) |
|
| 117 | + { |
|
| 118 | + switch ($locale) { |
|
| 119 | + case 'az': |
|
| 120 | + case 'az_AZ': |
|
| 121 | + case 'bo': |
|
| 122 | + case 'bo_CN': |
|
| 123 | + case 'bo_IN': |
|
| 124 | + case 'dz': |
|
| 125 | + case 'dz_BT': |
|
| 126 | + case 'id': |
|
| 127 | + case 'id_ID': |
|
| 128 | + case 'ja': |
|
| 129 | + case 'ja_JP': |
|
| 130 | + case 'jv': |
|
| 131 | + case 'ka': |
|
| 132 | + case 'ka_GE': |
|
| 133 | + case 'km': |
|
| 134 | + case 'km_KH': |
|
| 135 | + case 'kn': |
|
| 136 | + case 'kn_IN': |
|
| 137 | + case 'ko': |
|
| 138 | + case 'ko_KR': |
|
| 139 | + case 'ms': |
|
| 140 | + case 'ms_MY': |
|
| 141 | + case 'th': |
|
| 142 | + case 'th_TH': |
|
| 143 | + case 'tr': |
|
| 144 | + case 'tr_CY': |
|
| 145 | + case 'tr_TR': |
|
| 146 | + case 'vi': |
|
| 147 | + case 'vi_VN': |
|
| 148 | + case 'zh': |
|
| 149 | + case 'zh_CN': |
|
| 150 | + case 'zh_HK': |
|
| 151 | + case 'zh_SG': |
|
| 152 | + case 'zh_TW': |
|
| 153 | + return 0; |
|
| 154 | + case 'af': |
|
| 155 | + case 'af_ZA': |
|
| 156 | + case 'bn': |
|
| 157 | + case 'bn_BD': |
|
| 158 | + case 'bn_IN': |
|
| 159 | + case 'bg': |
|
| 160 | + case 'bg_BG': |
|
| 161 | + case 'ca': |
|
| 162 | + case 'ca_AD': |
|
| 163 | + case 'ca_ES': |
|
| 164 | + case 'ca_FR': |
|
| 165 | + case 'ca_IT': |
|
| 166 | + case 'da': |
|
| 167 | + case 'da_DK': |
|
| 168 | + case 'de': |
|
| 169 | + case 'de_AT': |
|
| 170 | + case 'de_BE': |
|
| 171 | + case 'de_CH': |
|
| 172 | + case 'de_DE': |
|
| 173 | + case 'de_LI': |
|
| 174 | + case 'de_LU': |
|
| 175 | + case 'el': |
|
| 176 | + case 'el_CY': |
|
| 177 | + case 'el_GR': |
|
| 178 | + case 'en': |
|
| 179 | + case 'en_AG': |
|
| 180 | + case 'en_AU': |
|
| 181 | + case 'en_BW': |
|
| 182 | + case 'en_CA': |
|
| 183 | + case 'en_DK': |
|
| 184 | + case 'en_GB': |
|
| 185 | + case 'en_HK': |
|
| 186 | + case 'en_IE': |
|
| 187 | + case 'en_IN': |
|
| 188 | + case 'en_NG': |
|
| 189 | + case 'en_NZ': |
|
| 190 | + case 'en_PH': |
|
| 191 | + case 'en_SG': |
|
| 192 | + case 'en_US': |
|
| 193 | + case 'en_ZA': |
|
| 194 | + case 'en_ZM': |
|
| 195 | + case 'en_ZW': |
|
| 196 | + case 'eo': |
|
| 197 | + case 'eo_US': |
|
| 198 | + case 'es': |
|
| 199 | + case 'es_AR': |
|
| 200 | + case 'es_BO': |
|
| 201 | + case 'es_CL': |
|
| 202 | + case 'es_CO': |
|
| 203 | + case 'es_CR': |
|
| 204 | + case 'es_CU': |
|
| 205 | + case 'es_DO': |
|
| 206 | + case 'es_EC': |
|
| 207 | + case 'es_ES': |
|
| 208 | + case 'es_GT': |
|
| 209 | + case 'es_HN': |
|
| 210 | + case 'es_MX': |
|
| 211 | + case 'es_NI': |
|
| 212 | + case 'es_PA': |
|
| 213 | + case 'es_PE': |
|
| 214 | + case 'es_PR': |
|
| 215 | + case 'es_PY': |
|
| 216 | + case 'es_SV': |
|
| 217 | + case 'es_US': |
|
| 218 | + case 'es_UY': |
|
| 219 | + case 'es_VE': |
|
| 220 | + case 'et': |
|
| 221 | + case 'et_EE': |
|
| 222 | + case 'eu': |
|
| 223 | + case 'eu_ES': |
|
| 224 | + case 'eu_FR': |
|
| 225 | + case 'fa': |
|
| 226 | + case 'fa_IR': |
|
| 227 | + case 'fi': |
|
| 228 | + case 'fi_FI': |
|
| 229 | + case 'fo': |
|
| 230 | + case 'fo_FO': |
|
| 231 | + case 'fur': |
|
| 232 | + case 'fur_IT': |
|
| 233 | + case 'fy': |
|
| 234 | + case 'fy_DE': |
|
| 235 | + case 'fy_NL': |
|
| 236 | + case 'gl': |
|
| 237 | + case 'gl_ES': |
|
| 238 | + case 'gu': |
|
| 239 | + case 'gu_IN': |
|
| 240 | + case 'ha': |
|
| 241 | + case 'ha_NG': |
|
| 242 | + case 'he': |
|
| 243 | + case 'he_IL': |
|
| 244 | + case 'hu': |
|
| 245 | + case 'hu_HU': |
|
| 246 | + case 'is': |
|
| 247 | + case 'is_IS': |
|
| 248 | + case 'it': |
|
| 249 | + case 'it_CH': |
|
| 250 | + case 'it_IT': |
|
| 251 | + case 'ku': |
|
| 252 | + case 'ku_TR': |
|
| 253 | + case 'lb': |
|
| 254 | + case 'lb_LU': |
|
| 255 | + case 'ml': |
|
| 256 | + case 'ml_IN': |
|
| 257 | + case 'mn': |
|
| 258 | + case 'mn_MN': |
|
| 259 | + case 'mr': |
|
| 260 | + case 'mr_IN': |
|
| 261 | + case 'nah': |
|
| 262 | + case 'nb': |
|
| 263 | + case 'nb_NO': |
|
| 264 | + case 'ne': |
|
| 265 | + case 'ne_NP': |
|
| 266 | + case 'nl': |
|
| 267 | + case 'nl_AW': |
|
| 268 | + case 'nl_BE': |
|
| 269 | + case 'nl_NL': |
|
| 270 | + case 'nn': |
|
| 271 | + case 'nn_NO': |
|
| 272 | + case 'no': |
|
| 273 | + case 'om': |
|
| 274 | + case 'om_ET': |
|
| 275 | + case 'om_KE': |
|
| 276 | + case 'or': |
|
| 277 | + case 'or_IN': |
|
| 278 | + case 'pa': |
|
| 279 | + case 'pa_IN': |
|
| 280 | + case 'pa_PK': |
|
| 281 | + case 'pap': |
|
| 282 | + case 'pap_AN': |
|
| 283 | + case 'pap_AW': |
|
| 284 | + case 'pap_CW': |
|
| 285 | + case 'ps': |
|
| 286 | + case 'ps_AF': |
|
| 287 | + case 'pt': |
|
| 288 | + case 'pt_BR': |
|
| 289 | + case 'pt_PT': |
|
| 290 | + case 'so': |
|
| 291 | + case 'so_DJ': |
|
| 292 | + case 'so_ET': |
|
| 293 | + case 'so_KE': |
|
| 294 | + case 'so_SO': |
|
| 295 | + case 'sq': |
|
| 296 | + case 'sq_AL': |
|
| 297 | + case 'sq_MK': |
|
| 298 | + case 'sv': |
|
| 299 | + case 'sv_FI': |
|
| 300 | + case 'sv_SE': |
|
| 301 | + case 'sw': |
|
| 302 | + case 'sw_KE': |
|
| 303 | + case 'sw_TZ': |
|
| 304 | + case 'ta': |
|
| 305 | + case 'ta_IN': |
|
| 306 | + case 'ta_LK': |
|
| 307 | + case 'te': |
|
| 308 | + case 'te_IN': |
|
| 309 | + case 'tk': |
|
| 310 | + case 'tk_TM': |
|
| 311 | + case 'ur': |
|
| 312 | + case 'ur_IN': |
|
| 313 | + case 'ur_PK': |
|
| 314 | + case 'zu': |
|
| 315 | + case 'zu_ZA': |
|
| 316 | + return ($number == 1) ? 0 : 1; |
|
| 317 | + case 'am': |
|
| 318 | + case 'am_ET': |
|
| 319 | + case 'bh': |
|
| 320 | + case 'fil': |
|
| 321 | + case 'fil_PH': |
|
| 322 | + case 'fr': |
|
| 323 | + case 'fr_BE': |
|
| 324 | + case 'fr_CA': |
|
| 325 | + case 'fr_CH': |
|
| 326 | + case 'fr_FR': |
|
| 327 | + case 'fr_LU': |
|
| 328 | + case 'gun': |
|
| 329 | + case 'hi': |
|
| 330 | + case 'hi_IN': |
|
| 331 | + case 'hy': |
|
| 332 | + case 'hy_AM': |
|
| 333 | + case 'ln': |
|
| 334 | + case 'ln_CD': |
|
| 335 | + case 'mg': |
|
| 336 | + case 'mg_MG': |
|
| 337 | + case 'nso': |
|
| 338 | + case 'nso_ZA': |
|
| 339 | + case 'ti': |
|
| 340 | + case 'ti_ER': |
|
| 341 | + case 'ti_ET': |
|
| 342 | + case 'wa': |
|
| 343 | + case 'wa_BE': |
|
| 344 | + case 'xbr': |
|
| 345 | + return (($number == 0) || ($number == 1)) ? 0 : 1; |
|
| 346 | + case 'be': |
|
| 347 | + case 'be_BY': |
|
| 348 | + case 'bs': |
|
| 349 | + case 'bs_BA': |
|
| 350 | + case 'hr': |
|
| 351 | + case 'hr_HR': |
|
| 352 | + case 'ru': |
|
| 353 | + case 'ru_RU': |
|
| 354 | + case 'ru_UA': |
|
| 355 | + case 'sr': |
|
| 356 | + case 'sr_ME': |
|
| 357 | + case 'sr_RS': |
|
| 358 | + case 'uk': |
|
| 359 | + case 'uk_UA': |
|
| 360 | + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); |
|
| 361 | + case 'cs': |
|
| 362 | + case 'cs_CZ': |
|
| 363 | + case 'sk': |
|
| 364 | + case 'sk_SK': |
|
| 365 | + return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2); |
|
| 366 | + case 'ga': |
|
| 367 | + case 'ga_IE': |
|
| 368 | + return ($number == 1) ? 0 : (($number == 2) ? 1 : 2); |
|
| 369 | + case 'lt': |
|
| 370 | + case 'lt_LT': |
|
| 371 | + return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2); |
|
| 372 | + case 'sl': |
|
| 373 | + case 'sl_SI': |
|
| 374 | + return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3)); |
|
| 375 | + case 'mk': |
|
| 376 | + case 'mk_MK': |
|
| 377 | + return ($number % 10 == 1) ? 0 : 1; |
|
| 378 | + case 'mt': |
|
| 379 | + case 'mt_MT': |
|
| 380 | + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)); |
|
| 381 | + case 'lv': |
|
| 382 | + case 'lv_LV': |
|
| 383 | + return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2); |
|
| 384 | + case 'pl': |
|
| 385 | + case 'pl_PL': |
|
| 386 | + return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2); |
|
| 387 | + case 'cy': |
|
| 388 | + case 'cy_GB': |
|
| 389 | + return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3)); |
|
| 390 | + case 'ro': |
|
| 391 | + case 'ro_RO': |
|
| 392 | + return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2); |
|
| 393 | + case 'ar': |
|
| 394 | + case 'ar_AE': |
|
| 395 | + case 'ar_BH': |
|
| 396 | + case 'ar_DZ': |
|
| 397 | + case 'ar_EG': |
|
| 398 | + case 'ar_IN': |
|
| 399 | + case 'ar_IQ': |
|
| 400 | + case 'ar_JO': |
|
| 401 | + case 'ar_KW': |
|
| 402 | + case 'ar_LB': |
|
| 403 | + case 'ar_LY': |
|
| 404 | + case 'ar_MA': |
|
| 405 | + case 'ar_OM': |
|
| 406 | + case 'ar_QA': |
|
| 407 | + case 'ar_SA': |
|
| 408 | + case 'ar_SD': |
|
| 409 | + case 'ar_SS': |
|
| 410 | + case 'ar_SY': |
|
| 411 | + case 'ar_TN': |
|
| 412 | + case 'ar_YE': |
|
| 413 | + return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))); |
|
| 414 | + default: |
|
| 415 | + return 0; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | 418 | } |
@@ -10,29 +10,29 @@ |
||
| 10 | 10 | |
| 11 | 11 | interface LoaderInterface |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Load the messages for the given locale. |
|
| 15 | - * |
|
| 16 | - * @param string $locale |
|
| 17 | - * @param string $group |
|
| 18 | - * @param string $namespace |
|
| 19 | - * @return array |
|
| 20 | - */ |
|
| 21 | - public function load($locale, $group, $namespace = null); |
|
| 13 | + /** |
|
| 14 | + * Load the messages for the given locale. |
|
| 15 | + * |
|
| 16 | + * @param string $locale |
|
| 17 | + * @param string $group |
|
| 18 | + * @param string $namespace |
|
| 19 | + * @return array |
|
| 20 | + */ |
|
| 21 | + public function load($locale, $group, $namespace = null); |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Add a new namespace to the loader. |
|
| 25 | - * |
|
| 26 | - * @param string $namespace |
|
| 27 | - * @param string $hint |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function addNamespace($namespace, $hint); |
|
| 23 | + /** |
|
| 24 | + * Add a new namespace to the loader. |
|
| 25 | + * |
|
| 26 | + * @param string $namespace |
|
| 27 | + * @param string $hint |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function addNamespace($namespace, $hint); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Get an array of all the registered namespaces. |
|
| 34 | - * |
|
| 35 | - * @return array |
|
| 36 | - */ |
|
| 37 | - public function namespaces(); |
|
| 32 | + /** |
|
| 33 | + * Get an array of all the registered namespaces. |
|
| 34 | + * |
|
| 35 | + * @return array |
|
| 36 | + */ |
|
| 37 | + public function namespaces(); |
|
| 38 | 38 | } |
@@ -10,69 +10,69 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ArrayLoader implements LoaderInterface |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * All of the translation messages. |
|
| 15 | - * |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - protected $messages = []; |
|
| 13 | + /** |
|
| 14 | + * All of the translation messages. |
|
| 15 | + * |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + protected $messages = []; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Load the messages for the given locale. |
|
| 22 | - * |
|
| 23 | - * @param string $locale |
|
| 24 | - * @param string $group |
|
| 25 | - * @param string $namespace |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - public function load($locale, $group, $namespace = null) |
|
| 29 | - { |
|
| 30 | - $namespace = $namespace ?: '*'; |
|
| 20 | + /** |
|
| 21 | + * Load the messages for the given locale. |
|
| 22 | + * |
|
| 23 | + * @param string $locale |
|
| 24 | + * @param string $group |
|
| 25 | + * @param string $namespace |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + public function load($locale, $group, $namespace = null) |
|
| 29 | + { |
|
| 30 | + $namespace = $namespace ?: '*'; |
|
| 31 | 31 | |
| 32 | - if (isset($this->messages[$namespace][$locale][$group])) { |
|
| 33 | - return $this->messages[$namespace][$locale][$group]; |
|
| 34 | - } |
|
| 32 | + if (isset($this->messages[$namespace][$locale][$group])) { |
|
| 33 | + return $this->messages[$namespace][$locale][$group]; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - return []; |
|
| 37 | - } |
|
| 36 | + return []; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Add a new namespace to the loader. |
|
| 41 | - * |
|
| 42 | - * @param string $namespace |
|
| 43 | - * @param string $hint |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function addNamespace($namespace, $hint) |
|
| 47 | - { |
|
| 48 | - // |
|
| 49 | - } |
|
| 39 | + /** |
|
| 40 | + * Add a new namespace to the loader. |
|
| 41 | + * |
|
| 42 | + * @param string $namespace |
|
| 43 | + * @param string $hint |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function addNamespace($namespace, $hint) |
|
| 47 | + { |
|
| 48 | + // |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Add messages to the loader. |
|
| 53 | - * |
|
| 54 | - * @param string $locale |
|
| 55 | - * @param string $group |
|
| 56 | - * @param array $messages |
|
| 57 | - * @param string|null $namespace |
|
| 58 | - * @return $this |
|
| 59 | - */ |
|
| 60 | - public function addMessages($locale, $group, array $messages, $namespace = null) |
|
| 61 | - { |
|
| 62 | - $namespace = $namespace ?: '*'; |
|
| 51 | + /** |
|
| 52 | + * Add messages to the loader. |
|
| 53 | + * |
|
| 54 | + * @param string $locale |
|
| 55 | + * @param string $group |
|
| 56 | + * @param array $messages |
|
| 57 | + * @param string|null $namespace |
|
| 58 | + * @return $this |
|
| 59 | + */ |
|
| 60 | + public function addMessages($locale, $group, array $messages, $namespace = null) |
|
| 61 | + { |
|
| 62 | + $namespace = $namespace ?: '*'; |
|
| 63 | 63 | |
| 64 | - $this->messages[$namespace][$locale][$group] = $messages; |
|
| 64 | + $this->messages[$namespace][$locale][$group] = $messages; |
|
| 65 | 65 | |
| 66 | - return $this; |
|
| 67 | - } |
|
| 66 | + return $this; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Get an array of all the registered namespaces. |
|
| 71 | - * |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function namespaces() |
|
| 75 | - { |
|
| 76 | - return []; |
|
| 77 | - } |
|
| 69 | + /** |
|
| 70 | + * Get an array of all the registered namespaces. |
|
| 71 | + * |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function namespaces() |
|
| 75 | + { |
|
| 76 | + return []; |
|
| 77 | + } |
|
| 78 | 78 | } |