@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | namespace GravityKit\GravityView\Foundation\ThirdParty\TrustedLogin; |
| 25 | 25 | |
| 26 | 26 | // Exit if accessed directly |
| 27 | -if ( ! defined('ABSPATH') ) { |
|
| 27 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 28 | 28 | exit; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $ns = $config->ns(); |
| 160 | 160 | |
| 161 | 161 | // Namespace isn't set; allow Config |
| 162 | - if( empty( $ns ) ) { |
|
| 162 | + if ( empty( $ns ) ) { |
|
| 163 | 163 | return true; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | return $created; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $return_data['timing']['remote'] = timer_stop( 0, 5 ); |
|
| 344 | + $return_data[ 'timing' ][ 'remote' ] = timer_stop( 0, 5 ); |
|
| 345 | 345 | |
| 346 | 346 | do_action( 'trustedlogin/' . $this->config->ns() . '/access/created', array( |
| 347 | 347 | 'url' => get_site_url(), |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | return $updated; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $return_data['timing']['remote'] = timer_stop( 0, 5 ); |
|
| 447 | + $return_data[ 'timing' ][ 'remote' ] = timer_stop( 0, 5 ); |
|
| 448 | 448 | |
| 449 | 449 | do_action( 'trustedlogin/' . $this->config->ns() . '/access/extended', array( |
| 450 | 450 | 'url' => get_site_url(), |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | $reference_id = self::get_reference_id(); |
| 544 | 544 | |
| 545 | 545 | if ( $reference_id ) { |
| 546 | - $metadata['reference_id'] = $reference_id; |
|
| 546 | + $metadata[ 'reference_id' ] = $reference_id; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | return $metadata; |
@@ -558,12 +558,12 @@ discard block |
||
| 558 | 558 | */ |
| 559 | 559 | public static function get_reference_id() { |
| 560 | 560 | |
| 561 | - if ( isset( $_REQUEST['reference_id'] ) ) { |
|
| 562 | - return esc_html( $_REQUEST['reference_id'] ); |
|
| 561 | + if ( isset( $_REQUEST[ 'reference_id' ] ) ) { |
|
| 562 | + return esc_html( $_REQUEST[ 'reference_id' ] ); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - if ( isset( $_REQUEST['ref'] ) ) { |
|
| 566 | - return esc_html( $_REQUEST['ref'] ); |
|
| 565 | + if ( isset( $_REQUEST[ 'ref' ] ) ) { |
|
| 566 | + return esc_html( $_REQUEST[ 'ref' ] ); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | return null; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | $user_ids = get_users( $args ); |
| 131 | 131 | |
| 132 | - return empty( $user_ids ) ? false : (int) $user_ids[0]; |
|
| 132 | + return empty( $user_ids ) ? false : (int)$user_ids[ 0 ]; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ( time() > (int) $expiration ) { |
|
| 156 | + if ( time() > (int)$expiration ) { |
|
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | |
| 380 | 380 | $user = get_users( $args ); |
| 381 | 381 | |
| 382 | - return empty( $user ) ? null : $user[0]; |
|
| 382 | + return empty( $user ) ? null : $user[ 0 ]; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | $support_users = $this->get_all(); |
| 438 | 438 | |
| 439 | 439 | if ( $support_users ) { |
| 440 | - return $support_users[0]; |
|
| 440 | + return $support_users[ 0 ]; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | return null; |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | 'number' => 1, |
| 525 | 525 | ) ); |
| 526 | 526 | |
| 527 | - $reassign_id = empty( $admins ) ? null : $admins[0]->ID; |
|
| 527 | + $reassign_id = empty( $admins ) ? null : $admins[ 0 ]->ID; |
|
| 528 | 528 | |
| 529 | 529 | $this->logging->log( 'Reassign user ID: ' . var_export( $reassign_id, true ), __METHOD__, 'info' ); |
| 530 | 530 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | namespace GravityKit\GravityView\Foundation\ThirdParty\TrustedLogin; |
| 10 | 10 | |
| 11 | 11 | // Exit if accessed directly |
| 12 | -if ( ! defined('ABSPATH') ) { |
|
| 12 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function ajax_generate_support() { |
| 59 | 59 | |
| 60 | - if ( empty( $_POST['vendor'] ) ) { |
|
| 60 | + if ( empty( $_POST[ 'vendor' ] ) ) { |
|
| 61 | 61 | |
| 62 | 62 | $this->logging->log( 'Vendor not defined in TrustedLogin configuration.', __METHOD__, 'critical' ); |
| 63 | 63 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | // There are multiple TrustedLogin instances, and this is not the one being called. |
| 68 | 68 | // This should not occur, since the AJAX action is namespaced. |
| 69 | - if ( $this->config->ns() !== $_POST['vendor'] ) { |
|
| 69 | + if ( $this->config->ns() !== $_POST[ 'vendor' ] ) { |
|
| 70 | 70 | |
| 71 | 71 | $this->logging->log( 'Vendor does not match TrustedLogin configuration.', __METHOD__, 'critical' ); |
| 72 | 72 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | return; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ( empty( $_POST['_nonce'] ) ) { |
|
| 77 | + if ( empty( $_POST[ '_nonce' ] ) ) { |
|
| 78 | 78 | wp_send_json_error( array( 'message' => 'Nonce not sent in the request.' ) ); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | if ( is_wp_error( $response ) ) { |
| 97 | 97 | |
| 98 | 98 | $error_data = $response->get_error_data(); |
| 99 | - $error_code = isset( $error_data['error_code'] ) ? $error_data['error_code'] : 500; |
|
| 99 | + $error_code = isset( $error_data[ 'error_code' ] ) ? $error_data[ 'error_code' ] : 500; |
|
| 100 | 100 | |
| 101 | 101 | wp_send_json_error( array( 'message' => $response->get_error_message() ), $error_code ); |
| 102 | 102 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | namespace GravityKit\GravityView\Foundation\ThirdParty\TrustedLogin; |
| 10 | 10 | |
| 11 | 11 | // Exit if accessed directly |
| 12 | -if ( ! defined('ABSPATH') ) { |
|
| 12 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | $unschedule_expiration = wp_clear_scheduled_hook( $this->hook_name, array( $hash ) ); |
| 100 | 100 | |
| 101 | - switch( $unschedule_expiration ) { |
|
| 101 | + switch ( $unschedule_expiration ) { |
|
| 102 | 102 | case false: |
| 103 | 103 | $this->logging->log( sprintf( 'Could not clear scheduled hook for %s', $this->hook_name ), __METHOD__, 'error' ); |
| 104 | 104 | return false; |
@@ -241,9 +241,9 @@ discard block |
||
| 241 | 241 | * |
| 242 | 242 | * @return string The tableized word. |
| 243 | 243 | */ |
| 244 | - public static function tableize($word) |
|
| 244 | + public static function tableize( $word ) |
|
| 245 | 245 | { |
| 246 | - return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word)); |
|
| 246 | + return strtolower( preg_replace( '~(?<=\\w)([A-Z])~', '_$1', $word ) ); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | * |
| 254 | 254 | * @return string The classified word. |
| 255 | 255 | */ |
| 256 | - public static function classify($word) |
|
| 256 | + public static function classify( $word ) |
|
| 257 | 257 | { |
| 258 | - return str_replace(" ", "", ucwords(strtr($word, "_-", " "))); |
|
| 258 | + return str_replace( " ", "", ucwords( strtr( $word, "_-", " " ) ) ); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -265,9 +265,9 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @return string The camelized word. |
| 267 | 267 | */ |
| 268 | - public static function camelize($word) |
|
| 268 | + public static function camelize( $word ) |
|
| 269 | 269 | { |
| 270 | - return lcfirst(self::classify($word)); |
|
| 270 | + return lcfirst( self::classify( $word ) ); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -295,12 +295,12 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @return string The string with all delimeter-separated words capitalized. |
| 297 | 297 | */ |
| 298 | - public static function ucwords($string, $delimiters = " \n\t\r\0\x0B-") |
|
| 298 | + public static function ucwords( $string, $delimiters = " \n\t\r\0\x0B-" ) |
|
| 299 | 299 | { |
| 300 | 300 | return preg_replace_callback( |
| 301 | - '/[^' . preg_quote($delimiters, '/') . ']+/', |
|
| 302 | - function($matches) { |
|
| 303 | - return ucfirst($matches[0]); |
|
| 301 | + '/[^' . preg_quote( $delimiters, '/' ) . ']+/', |
|
| 302 | + function( $matches ) { |
|
| 303 | + return ucfirst( $matches[ 0 ] ); |
|
| 304 | 304 | }, |
| 305 | 305 | $string |
| 306 | 306 | ); |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | public static function reset() |
| 316 | 316 | { |
| 317 | - if (empty(self::$initialState)) { |
|
| 318 | - self::$initialState = get_class_vars('Inflector'); |
|
| 317 | + if ( empty( self::$initialState ) ) { |
|
| 318 | + self::$initialState = get_class_vars( 'Inflector' ); |
|
| 319 | 319 | |
| 320 | 320 | return; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - foreach (self::$initialState as $key => $val) { |
|
| 324 | - if ($key != 'initialState') { |
|
| 323 | + foreach ( self::$initialState as $key => $val ) { |
|
| 324 | + if ( $key != 'initialState' ) { |
|
| 325 | 325 | self::${$key} = $val; |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -348,35 +348,35 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | * @return void |
| 350 | 350 | */ |
| 351 | - public static function rules($type, $rules, $reset = false) |
|
| 351 | + public static function rules( $type, $rules, $reset = false ) |
|
| 352 | 352 | { |
| 353 | - foreach ($rules as $rule => $pattern) { |
|
| 354 | - if ( ! is_array($pattern)) { |
|
| 353 | + foreach ( $rules as $rule => $pattern ) { |
|
| 354 | + if ( ! is_array( $pattern ) ) { |
|
| 355 | 355 | continue; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - if ($reset) { |
|
| 359 | - self::${$type}[$rule] = $pattern; |
|
| 358 | + if ( $reset ) { |
|
| 359 | + self::${$type}[ $rule ] = $pattern; |
|
| 360 | 360 | } else { |
| 361 | - self::${$type}[$rule] = ($rule === 'uninflected') |
|
| 362 | - ? array_merge($pattern, self::${$type}[$rule]) |
|
| 363 | - : $pattern + self::${$type}[$rule]; |
|
| 361 | + self::${$type}[ $rule ] = ( $rule === 'uninflected' ) |
|
| 362 | + ? array_merge( $pattern, self::${$type}[ $rule ] ) |
|
| 363 | + : $pattern + self::${$type}[ $rule ]; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - unset($rules[$rule], self::${$type}['cache' . ucfirst($rule)]); |
|
| 366 | + unset( $rules[ $rule ], self::${$type}[ 'cache' . ucfirst( $rule ) ] ); |
|
| 367 | 367 | |
| 368 | - if (isset(self::${$type}['merged'][$rule])) { |
|
| 369 | - unset(self::${$type}['merged'][$rule]); |
|
| 368 | + if ( isset( self::${$type}[ 'merged' ][ $rule ] ) ) { |
|
| 369 | + unset( self::${$type}[ 'merged' ][ $rule ] ); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - if ($type === 'plural') { |
|
| 373 | - self::$cache['pluralize'] = self::$cache['tableize'] = array(); |
|
| 374 | - } elseif ($type === 'singular') { |
|
| 375 | - self::$cache['singularize'] = array(); |
|
| 372 | + if ( $type === 'plural' ) { |
|
| 373 | + self::$cache[ 'pluralize' ] = self::$cache[ 'tableize' ] = array(); |
|
| 374 | + } elseif ( $type === 'singular' ) { |
|
| 375 | + self::$cache[ 'singularize' ] = array(); |
|
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - self::${$type}['rules'] = $rules + self::${$type}['rules']; |
|
| 379 | + self::${$type}[ 'rules' ] = $rules + self::${$type}[ 'rules' ]; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -386,42 +386,42 @@ discard block |
||
| 386 | 386 | * |
| 387 | 387 | * @return string The word in plural form. |
| 388 | 388 | */ |
| 389 | - public static function pluralize($word) |
|
| 389 | + public static function pluralize( $word ) |
|
| 390 | 390 | { |
| 391 | - if (isset(self::$cache['pluralize'][$word])) { |
|
| 392 | - return self::$cache['pluralize'][$word]; |
|
| 391 | + if ( isset( self::$cache[ 'pluralize' ][ $word ] ) ) { |
|
| 392 | + return self::$cache[ 'pluralize' ][ $word ]; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if (!isset(self::$plural['merged']['irregular'])) { |
|
| 396 | - self::$plural['merged']['irregular'] = self::$plural['irregular']; |
|
| 395 | + if ( ! isset( self::$plural[ 'merged' ][ 'irregular' ] ) ) { |
|
| 396 | + self::$plural[ 'merged' ][ 'irregular' ] = self::$plural[ 'irregular' ]; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - if (!isset(self::$plural['merged']['uninflected'])) { |
|
| 400 | - self::$plural['merged']['uninflected'] = array_merge(self::$plural['uninflected'], self::$uninflected); |
|
| 399 | + if ( ! isset( self::$plural[ 'merged' ][ 'uninflected' ] ) ) { |
|
| 400 | + self::$plural[ 'merged' ][ 'uninflected' ] = array_merge( self::$plural[ 'uninflected' ], self::$uninflected ); |
|
| 401 | 401 | } |
| 402 | 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'])) . ')'; |
|
| 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 | 406 | } |
| 407 | 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); |
|
| 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]; |
|
| 411 | + return self::$cache[ 'pluralize' ][ $word ]; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - if (preg_match('/^(' . self::$plural['cacheUninflected'] . ')$/i', $word, $regs)) { |
|
| 415 | - self::$cache['pluralize'][$word] = $word; |
|
| 414 | + if ( preg_match( '/^(' . self::$plural[ 'cacheUninflected' ] . ')$/i', $word, $regs ) ) { |
|
| 415 | + self::$cache[ 'pluralize' ][ $word ] = $word; |
|
| 416 | 416 | |
| 417 | 417 | return $word; |
| 418 | 418 | } |
| 419 | 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); |
|
| 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 | 423 | |
| 424 | - return self::$cache['pluralize'][$word]; |
|
| 424 | + return self::$cache[ 'pluralize' ][ $word ]; |
|
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -433,52 +433,52 @@ discard block |
||
| 433 | 433 | * |
| 434 | 434 | * @return string The word in singular form. |
| 435 | 435 | */ |
| 436 | - public static function singularize($word) |
|
| 436 | + public static function singularize( $word ) |
|
| 437 | 437 | { |
| 438 | - if (isset(self::$cache['singularize'][$word])) { |
|
| 439 | - return self::$cache['singularize'][$word]; |
|
| 438 | + if ( isset( self::$cache[ 'singularize' ][ $word ] ) ) { |
|
| 439 | + return self::$cache[ 'singularize' ][ $word ]; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - if (!isset(self::$singular['merged']['uninflected'])) { |
|
| 443 | - self::$singular['merged']['uninflected'] = array_merge( |
|
| 444 | - self::$singular['uninflected'], |
|
| 442 | + if ( ! isset( self::$singular[ 'merged' ][ 'uninflected' ] ) ) { |
|
| 443 | + self::$singular[ 'merged' ][ 'uninflected' ] = array_merge( |
|
| 444 | + self::$singular[ 'uninflected' ], |
|
| 445 | 445 | self::$uninflected |
| 446 | 446 | ); |
| 447 | 447 | } |
| 448 | 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']) |
|
| 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 | 453 | ); |
| 454 | 454 | } |
| 455 | 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'])) . ')'; |
|
| 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 | 459 | } |
| 460 | 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); |
|
| 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]; |
|
| 464 | + return self::$cache[ 'singularize' ][ $word ]; |
|
| 465 | 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 | 470 | return $word; |
| 471 | 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]; |
|
| 477 | + return self::$cache[ 'singularize' ][ $word ]; |
|
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - self::$cache['singularize'][$word] = $word; |
|
| 481 | + self::$cache[ 'singularize' ][ $word ] = $word; |
|
| 482 | 482 | |
| 483 | 483 | return $word; |
| 484 | 484 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @var array |
| 45 | 45 | */ |
| 46 | - protected $options = array ( |
|
| 46 | + protected $options = array( |
|
| 47 | 47 | 'extension' => 'txt', |
| 48 | 48 | 'dateFormat' => 'Y-m-d G:i:s.u', |
| 49 | 49 | 'filename' => false, |
@@ -115,52 +115,52 @@ discard block |
||
| 115 | 115 | * @internal param string $logFilePrefix The prefix for the log file name |
| 116 | 116 | * @internal param string $logFileExt The extension for the log file |
| 117 | 117 | */ |
| 118 | - public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array()) |
|
| 118 | + public function __construct( $logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array() ) |
|
| 119 | 119 | {
|
| 120 | 120 | $this->logLevelThreshold = $logLevelThreshold; |
| 121 | - $this->options = array_merge($this->options, $options); |
|
| 121 | + $this->options = array_merge( $this->options, $options ); |
|
| 122 | 122 | |
| 123 | - $logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR); |
|
| 124 | - if ( ! file_exists($logDirectory)) {
|
|
| 125 | - mkdir($logDirectory, $this->defaultPermissions, true); |
|
| 123 | + $logDirectory = rtrim( $logDirectory, DIRECTORY_SEPARATOR ); |
|
| 124 | + if ( ! file_exists( $logDirectory ) ) {
|
|
| 125 | + mkdir( $logDirectory, $this->defaultPermissions, true ); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if(strpos($logDirectory, 'php://') === 0) {
|
|
| 129 | - $this->setLogToStdOut($logDirectory); |
|
| 130 | - $this->setFileHandle('w+');
|
|
| 128 | + if ( strpos( $logDirectory, 'php://' ) === 0 ) {
|
|
| 129 | + $this->setLogToStdOut( $logDirectory ); |
|
| 130 | + $this->setFileHandle( 'w+' ); |
|
| 131 | 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.');
|
|
| 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 | 135 | } |
| 136 | - $this->setFileHandle('a');
|
|
| 136 | + $this->setFileHandle( 'a' ); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if ( ! $this->fileHandle) {
|
|
| 140 | - throw new RuntimeException('The file could not be opened. Check permissions.');
|
|
| 139 | + if ( ! $this->fileHandle ) {
|
|
| 140 | + throw new RuntimeException( 'The file could not be opened. Check permissions.' ); |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | 145 | * @param string $stdOutPath |
| 146 | 146 | */ |
| 147 | - public function setLogToStdOut($stdOutPath) {
|
|
| 147 | + public function setLogToStdOut( $stdOutPath ) {
|
|
| 148 | 148 | $this->logFilePath = $stdOutPath; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | * @param string $logDirectory |
| 153 | 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']; |
|
| 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 | 158 | } |
| 159 | 159 | else {
|
| 160 | - $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension']; |
|
| 160 | + $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options[ 'filename' ] . '.' . $this->options[ 'extension' ]; |
|
| 161 | 161 | } |
| 162 | 162 | } else {
|
| 163 | - $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
|
|
| 163 | + $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options[ 'prefix' ] . date( 'Y-m-d' ) . '.' . $this->options[ 'extension' ]; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @internal param resource $fileHandle |
| 171 | 171 | */ |
| 172 | - public function setFileHandle($writeMode) {
|
|
| 173 | - $this->fileHandle = fopen($this->logFilePath, $writeMode); |
|
| 172 | + public function setFileHandle( $writeMode ) {
|
|
| 173 | + $this->fileHandle = fopen( $this->logFilePath, $writeMode ); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | public function __destruct() |
| 181 | 181 | {
|
| 182 | - if ($this->fileHandle) {
|
|
| 183 | - fclose($this->fileHandle); |
|
| 182 | + if ( $this->fileHandle ) {
|
|
| 183 | + fclose( $this->fileHandle ); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @param string $dateFormat Valid format string for date() |
| 191 | 191 | */ |
| 192 | - public function setDateFormat($dateFormat) |
|
| 192 | + public function setDateFormat( $dateFormat ) |
|
| 193 | 193 | {
|
| 194 | - $this->options['dateFormat'] = $dateFormat; |
|
| 194 | + $this->options[ 'dateFormat' ] = $dateFormat; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @param string $logLevelThreshold The log level threshold |
| 201 | 201 | */ |
| 202 | - public function setLogLevelThreshold($logLevelThreshold) |
|
| 202 | + public function setLogLevelThreshold( $logLevelThreshold ) |
|
| 203 | 203 | {
|
| 204 | 204 | $this->logLevelThreshold = $logLevelThreshold; |
| 205 | 205 | } |
@@ -212,13 +212,13 @@ discard block |
||
| 212 | 212 | * @param array $context |
| 213 | 213 | * @return null |
| 214 | 214 | */ |
| 215 | - public function log($level, $message, array $context = array()) |
|
| 215 | + public function log( $level, $message, array $context = array() ) |
|
| 216 | 216 | {
|
| 217 | - if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
|
|
| 217 | + if ( $this->logLevels[ $this->logLevelThreshold ] < $this->logLevels[ $level ] ) {
|
|
| 218 | 218 | return; |
| 219 | 219 | } |
| 220 | - $message = $this->formatMessage($level, $message, $context); |
|
| 221 | - $this->write($message); |
|
| 220 | + $message = $this->formatMessage( $level, $message, $context ); |
|
| 221 | + $this->write( $message ); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -227,17 +227,17 @@ discard block |
||
| 227 | 227 | * @param string $message Line to write to the log |
| 228 | 228 | * @return void |
| 229 | 229 | */ |
| 230 | - public function write($message) |
|
| 230 | + public function write( $message ) |
|
| 231 | 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.');
|
|
| 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 | 235 | } else {
|
| 236 | - $this->lastLine = trim($message); |
|
| 236 | + $this->lastLine = trim( $message ); |
|
| 237 | 237 | $this->logLineCount++; |
| 238 | 238 | |
| 239 | - if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
|
|
| 240 | - fflush($this->fileHandle); |
|
| 239 | + if ( $this->options[ 'flushFrequency' ] && $this->logLineCount % $this->options[ 'flushFrequency' ] === 0 ) {
|
|
| 240 | + fflush( $this->fileHandle ); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -271,31 +271,31 @@ discard block |
||
| 271 | 271 | * @param array $context The context |
| 272 | 272 | * @return string |
| 273 | 273 | */ |
| 274 | - protected function formatMessage($level, $message, $context) |
|
| 274 | + protected function formatMessage( $level, $message, $context ) |
|
| 275 | 275 | {
|
| 276 | - if ($this->options['logFormat']) {
|
|
| 276 | + if ( $this->options[ 'logFormat' ] ) {
|
|
| 277 | 277 | $parts = array( |
| 278 | 278 | 'date' => $this->getTimestamp(), |
| 279 | - 'level' => strtoupper($level), |
|
| 280 | - 'level-padding' => str_repeat(' ', 9 - strlen($level)),
|
|
| 281 | - 'priority' => $this->logLevels[$level], |
|
| 279 | + 'level' => strtoupper( $level ), |
|
| 280 | + 'level-padding' => str_repeat( ' ', 9 - strlen( $level ) ), |
|
| 281 | + 'priority' => $this->logLevels[ $level ], |
|
| 282 | 282 | 'message' => $message, |
| 283 | - 'context' => json_encode($context), |
|
| 283 | + 'context' => json_encode( $context ), |
|
| 284 | 284 | ); |
| 285 | - $message = $this->options['logFormat']; |
|
| 286 | - foreach ($parts as $part => $value) {
|
|
| 287 | - $message = str_replace('{'.$part.'}', $value, $message);
|
|
| 285 | + $message = $this->options[ 'logFormat' ]; |
|
| 286 | + foreach ( $parts as $part => $value ) {
|
|
| 287 | + $message = str_replace( '{' . $part . '}', $value, $message );
|
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | } else {
|
| 291 | 291 | $message = "[{$this->getTimestamp()}] [{$level}] {$message}";
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ($this->options['appendContext'] && ! empty($context)) {
|
|
| 295 | - $message .= PHP_EOL.$this->indent($this->contextToString($context)); |
|
| 294 | + if ( $this->options[ 'appendContext' ] && ! empty( $context ) ) {
|
|
| 295 | + $message .= PHP_EOL . $this->indent( $this->contextToString( $context ) ); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - return $message.PHP_EOL; |
|
| 298 | + return $message . PHP_EOL; |
|
| 299 | 299 | |
| 300 | 300 | } |
| 301 | 301 | |
@@ -309,11 +309,11 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | private function getTimestamp() |
| 311 | 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));
|
|
| 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 | 315 | |
| 316 | - return $date->format($this->options['dateFormat']); |
|
| 316 | + return $date->format( $this->options[ 'dateFormat' ] ); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -322,12 +322,12 @@ discard block |
||
| 322 | 322 | * @param array $context The Context |
| 323 | 323 | * @return string |
| 324 | 324 | */ |
| 325 | - protected function contextToString($context) |
|
| 325 | + protected function contextToString( $context ) |
|
| 326 | 326 | {
|
| 327 | 327 | $export = ''; |
| 328 | - foreach ($context as $key => $value) {
|
|
| 328 | + foreach ( $context as $key => $value ) {
|
|
| 329 | 329 | $export .= "{$key}: ";
|
| 330 | - $export .= preg_replace(array( |
|
| 330 | + $export .= preg_replace( array( |
|
| 331 | 331 | '/=>\s+([a-zA-Z])/im', |
| 332 | 332 | '/array\(\s+\)/im', |
| 333 | 333 | '/^ |\G /m' |
@@ -335,10 +335,10 @@ discard block |
||
| 335 | 335 | '=> $1', |
| 336 | 336 | 'array()', |
| 337 | 337 | ' ' |
| 338 | - ), str_replace('array (', 'array(', var_export($value, true)));
|
|
| 338 | + ), str_replace( 'array (', 'array(', var_export( $value, true ) ) );
|
|
| 339 | 339 | $export .= PHP_EOL; |
| 340 | 340 | } |
| 341 | - return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
|
|
| 341 | + return str_replace( array( '\\\\', '\\\'' ), array( '\\', '\'' ), rtrim( $export ) ); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | * @param string $indent What to use as the indent. |
| 349 | 349 | * @return string |
| 350 | 350 | */ |
| 351 | - protected function indent($string, $indent = ' ') |
|
| 351 | + protected function indent( $string, $indent = ' ' ) |
|
| 352 | 352 | {
|
| 353 | - return $indent.str_replace("\n", "\n".$indent, $string);
|
|
| 353 | + return $indent . str_replace( "\n", "\n" . $indent, $string ); |
|
| 354 | 354 | } |
| 355 | 355 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @var array |
| 33 | 33 | */ |
| 34 | - protected $hints = []; |
|
| 34 | + protected $hints = [ ]; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Create a new file loader instance. |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param string $path |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - public function __construct(Filesystem $files, $path) |
|
| 43 | + public function __construct( Filesystem $files, $path ) |
|
| 44 | 44 | { |
| 45 | 45 | $this->path = $path; |
| 46 | 46 | $this->files = $files; |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @param string $namespace |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - public function load($locale, $group, $namespace = null) |
|
| 57 | + public function load( $locale, $group, $namespace = null ) |
|
| 58 | 58 | { |
| 59 | - if ($group == '*' && $namespace == '*') { |
|
| 60 | - return $this->loadJsonPath($this->path, $locale); |
|
| 59 | + if ( $group == '*' && $namespace == '*' ) { |
|
| 60 | + return $this->loadJsonPath( $this->path, $locale ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if (is_null($namespace) || $namespace == '*') { |
|
| 64 | - return $this->loadPath($this->path, $locale, $group); |
|
| 63 | + if ( is_null( $namespace ) || $namespace == '*' ) { |
|
| 64 | + return $this->loadPath( $this->path, $locale, $group ); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - return $this->loadNamespaced($locale, $group, $namespace); |
|
| 67 | + return $this->loadNamespaced( $locale, $group, $namespace ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | * @param string $namespace |
| 76 | 76 | * @return array |
| 77 | 77 | */ |
| 78 | - protected function loadNamespaced($locale, $group, $namespace) |
|
| 78 | + protected function loadNamespaced( $locale, $group, $namespace ) |
|
| 79 | 79 | { |
| 80 | - if (isset($this->hints[$namespace])) { |
|
| 81 | - $lines = $this->loadPath($this->hints[$namespace], $locale, $group); |
|
| 80 | + if ( isset( $this->hints[ $namespace ] ) ) { |
|
| 81 | + $lines = $this->loadPath( $this->hints[ $namespace ], $locale, $group ); |
|
| 82 | 82 | |
| 83 | - return $this->loadNamespaceOverrides($lines, $locale, $group, $namespace); |
|
| 83 | + return $this->loadNamespaceOverrides( $lines, $locale, $group, $namespace ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - return []; |
|
| 86 | + return [ ]; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -95,12 +95,12 @@ discard block |
||
| 95 | 95 | * @param string $namespace |
| 96 | 96 | * @return array |
| 97 | 97 | */ |
| 98 | - protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace) |
|
| 98 | + protected function loadNamespaceOverrides( array $lines, $locale, $group, $namespace ) |
|
| 99 | 99 | { |
| 100 | 100 | $file = "{$this->path}/vendor/{$namespace}/{$locale}/{$group}.php"; |
| 101 | 101 | |
| 102 | - if ($this->files->exists($file)) { |
|
| 103 | - return array_replace_recursive($lines, $this->files->getRequire($file)); |
|
| 102 | + if ( $this->files->exists( $file ) ) { |
|
| 103 | + return array_replace_recursive( $lines, $this->files->getRequire( $file ) ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | return $lines; |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | * @param string $group |
| 115 | 115 | * @return array |
| 116 | 116 | */ |
| 117 | - protected function loadPath($path, $locale, $group) |
|
| 117 | + protected function loadPath( $path, $locale, $group ) |
|
| 118 | 118 | { |
| 119 | - if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) { |
|
| 120 | - return $this->files->getRequire($full); |
|
| 119 | + if ( $this->files->exists( $full = "{$path}/{$locale}/{$group}.php" ) ) { |
|
| 120 | + return $this->files->getRequire( $full ); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - return []; |
|
| 123 | + return [ ]; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | * @param string $locale |
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | - protected function loadJsonPath($path, $locale) |
|
| 133 | + protected function loadJsonPath( $path, $locale ) |
|
| 134 | 134 | { |
| 135 | - if ($this->files->exists($full = "{$path}/{$locale}.json")) { |
|
| 136 | - return json_decode($this->files->get($full), true); |
|
| 135 | + if ( $this->files->exists( $full = "{$path}/{$locale}.json" ) ) { |
|
| 136 | + return json_decode( $this->files->get( $full ), true ); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - return []; |
|
| 139 | + return [ ]; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | * @param string $hint |
| 147 | 147 | * @return void |
| 148 | 148 | */ |
| 149 | - public function addNamespace($namespace, $hint) |
|
| 149 | + public function addNamespace( $namespace, $hint ) |
|
| 150 | 150 | { |
| 151 | - $this->hints[$namespace] = $hint; |
|
| 151 | + $this->hints[ $namespace ] = $hint; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -28,17 +28,17 @@ discard block |
||
| 28 | 28 | { |
| 29 | 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 | 34 | // When registering the translator component, we'll need to set the default |
| 35 | 35 | // locale as well as the fallback locale. So, we'll grab the application |
| 36 | 36 | // configuration so we can easily get both of these values from there. |
| 37 | - $locale = $app['config']['app.locale']; |
|
| 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 | 43 | return $trans; |
| 44 | 44 | }); |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | protected function registerLoader() |
| 53 | 53 | { |
| 54 | - $this->app->singleton('translation.loader', function ($app) { |
|
| 55 | - return new FileLoader($app['files'], $app['path.lang']); |
|
| 54 | + $this->app->singleton( 'translation.loader', function( $app ) { |
|
| 55 | + return new FileLoader( $app[ 'files' ], $app[ 'path.lang' ] ); |
|
| 56 | 56 | }); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -63,6 +63,6 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function provides() |
| 65 | 65 | { |
| 66 | - return ['translator', 'translation.loader']; |
|
| 66 | + return [ 'translator', 'translation.loader' ]; |
|
| 67 | 67 | } |
| 68 | 68 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @var array |
| 48 | 48 | */ |
| 49 | - protected $loaded = []; |
|
| 49 | + protected $loaded = [ ]; |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The message selector. |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param string $locale |
| 63 | 63 | * @return void |
| 64 | 64 | */ |
| 65 | - public function __construct(LoaderInterface $loader, $locale) |
|
| 65 | + public function __construct( LoaderInterface $loader, $locale ) |
|
| 66 | 66 | { |
| 67 | 67 | $this->loader = $loader; |
| 68 | 68 | $this->locale = $locale; |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | * @param string|null $locale |
| 76 | 76 | * @return bool |
| 77 | 77 | */ |
| 78 | - public function hasForLocale($key, $locale = null) |
|
| 78 | + public function hasForLocale( $key, $locale = null ) |
|
| 79 | 79 | { |
| 80 | - return $this->has($key, $locale, false); |
|
| 80 | + return $this->has( $key, $locale, false ); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | * @param bool $fallback |
| 89 | 89 | * @return bool |
| 90 | 90 | */ |
| 91 | - public function has($key, $locale = null, $fallback = true) |
|
| 91 | + public function has( $key, $locale = null, $fallback = true ) |
|
| 92 | 92 | { |
| 93 | - return $this->get($key, [], $locale, $fallback) !== $key; |
|
| 93 | + return $this->get( $key, [ ], $locale, $fallback ) !== $key; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | * @param string $locale |
| 102 | 102 | * @return string|array|null |
| 103 | 103 | */ |
| 104 | - public function trans($key, array $replace = [], $locale = null) |
|
| 104 | + public function trans( $key, array $replace = [ ], $locale = null ) |
|
| 105 | 105 | { |
| 106 | - return $this->get($key, $replace, $locale); |
|
| 106 | + return $this->get( $key, $replace, $locale ); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -115,20 +115,20 @@ discard block |
||
| 115 | 115 | * @param bool $fallback |
| 116 | 116 | * @return string|array|null |
| 117 | 117 | */ |
| 118 | - public function get($key, array $replace = [], $locale = null, $fallback = true) |
|
| 118 | + public function get( $key, array $replace = [ ], $locale = null, $fallback = true ) |
|
| 119 | 119 | { |
| 120 | - list($namespace, $group, $item) = $this->parseKey($key); |
|
| 120 | + list( $namespace, $group, $item ) = $this->parseKey( $key ); |
|
| 121 | 121 | |
| 122 | 122 | // Here we will get the locale that should be used for the language line. If one |
| 123 | 123 | // was not passed, we will use the default locales which was given to us when |
| 124 | 124 | // the translator was instantiated. Then, we can load the lines and return. |
| 125 | - $locales = $fallback ? $this->localeArray($locale) |
|
| 126 | - : [$locale ?: $this->locale]; |
|
| 125 | + $locales = $fallback ? $this->localeArray( $locale ) |
|
| 126 | + : [ $locale ?: $this->locale ]; |
|
| 127 | 127 | |
| 128 | - foreach ($locales as $locale) { |
|
| 129 | - if (! is_null($line = $this->getLine( |
|
| 128 | + foreach ( $locales as $locale ) { |
|
| 129 | + if ( ! is_null( $line = $this->getLine( |
|
| 130 | 130 | $namespace, $group, $locale, $item, $replace |
| 131 | - ))) { |
|
| 131 | + ) ) ) { |
|
| 132 | 132 | break; |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | // If the line doesn't exist, we will return back the key which was requested as |
| 137 | 137 | // that will be quick to spot in the UI if language keys are wrong or missing |
| 138 | 138 | // from the application's language files. Otherwise we can return the line. |
| 139 | - if (isset($line)) { |
|
| 139 | + if ( isset( $line ) ) { |
|
| 140 | 140 | return $line; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -151,30 +151,30 @@ discard block |
||
| 151 | 151 | * @param string $locale |
| 152 | 152 | * @return string |
| 153 | 153 | */ |
| 154 | - public function getFromJson($key, array $replace = [], $locale = null) |
|
| 154 | + public function getFromJson( $key, array $replace = [ ], $locale = null ) |
|
| 155 | 155 | { |
| 156 | 156 | $locale = $locale ?: $this->locale; |
| 157 | 157 | |
| 158 | 158 | // For JSON translations, there is only one file per locale, so we will simply load |
| 159 | 159 | // that file and then we will be ready to check the array for the key. These are |
| 160 | 160 | // only one level deep so we do not need to do any fancy searching through it. |
| 161 | - $this->load('*', '*', $locale); |
|
| 161 | + $this->load( '*', '*', $locale ); |
|
| 162 | 162 | |
| 163 | - $line = isset($this->loaded['*']['*'][$locale][$key]) |
|
| 164 | - ? $this->loaded['*']['*'][$locale][$key] : null; |
|
| 163 | + $line = isset( $this->loaded[ '*' ][ '*' ][ $locale ][ $key ] ) |
|
| 164 | + ? $this->loaded[ '*' ][ '*' ][ $locale ][ $key ] : null; |
|
| 165 | 165 | |
| 166 | 166 | // If we can't find a translation for the JSON key, we will attempt to translate it |
| 167 | 167 | // using the typical translation file. This way developers can always just use a |
| 168 | 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); |
|
| 169 | + if ( ! isset( $line ) ) { |
|
| 170 | + $fallback = $this->get( $key, $replace, $locale ); |
|
| 171 | 171 | |
| 172 | - if ($fallback !== $key) { |
|
| 172 | + if ( $fallback !== $key ) { |
|
| 173 | 173 | return $fallback; |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - return $this->makeReplacements($line ?: $key, $replace); |
|
| 177 | + return $this->makeReplacements( $line ?: $key, $replace ); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | * @param string $locale |
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | - public function transChoice($key, $number, array $replace = [], $locale = null) |
|
| 189 | + public function transChoice( $key, $number, array $replace = [ ], $locale = null ) |
|
| 190 | 190 | { |
| 191 | - return $this->choice($key, $number, $replace, $locale); |
|
| 191 | + return $this->choice( $key, $number, $replace, $locale ); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -200,23 +200,23 @@ discard block |
||
| 200 | 200 | * @param string $locale |
| 201 | 201 | * @return string |
| 202 | 202 | */ |
| 203 | - public function choice($key, $number, array $replace = [], $locale = null) |
|
| 203 | + public function choice( $key, $number, array $replace = [ ], $locale = null ) |
|
| 204 | 204 | { |
| 205 | 205 | $line = $this->get( |
| 206 | - $key, $replace, $locale = $this->localeForChoice($locale) |
|
| 206 | + $key, $replace, $locale = $this->localeForChoice( $locale ) |
|
| 207 | 207 | ); |
| 208 | 208 | |
| 209 | 209 | // If the given "number" is actually an array or countable we will simply count the |
| 210 | 210 | // number of elements in an instance. This allows developers to pass an array of |
| 211 | 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); |
|
| 212 | + if ( is_array( $number ) || $number instanceof Countable ) { |
|
| 213 | + $number = count( $number ); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $replace['count'] = $number; |
|
| 216 | + $replace[ 'count' ] = $number; |
|
| 217 | 217 | |
| 218 | 218 | return $this->makeReplacements( |
| 219 | - $this->getSelector()->choose($line, $number, $locale), $replace |
|
| 219 | + $this->getSelector()->choose( $line, $number, $locale ), $replace |
|
| 220 | 220 | ); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @param string|null $locale |
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | - protected function localeForChoice($locale) |
|
| 229 | + protected function localeForChoice( $locale ) |
|
| 230 | 230 | { |
| 231 | 231 | return $locale ?: $this->locale ?: $this->fallback; |
| 232 | 232 | } |
@@ -241,15 +241,15 @@ discard block |
||
| 241 | 241 | * @param array $replace |
| 242 | 242 | * @return string|array|null |
| 243 | 243 | */ |
| 244 | - protected function getLine($namespace, $group, $locale, $item, array $replace) |
|
| 244 | + protected function getLine( $namespace, $group, $locale, $item, array $replace ) |
|
| 245 | 245 | { |
| 246 | - $this->load($namespace, $group, $locale); |
|
| 246 | + $this->load( $namespace, $group, $locale ); |
|
| 247 | 247 | |
| 248 | - $line = Arr::get($this->loaded[$namespace][$group][$locale], $item); |
|
| 248 | + $line = Arr::get( $this->loaded[ $namespace ][ $group ][ $locale ], $item ); |
|
| 249 | 249 | |
| 250 | - if (is_string($line)) { |
|
| 251 | - return $this->makeReplacements($line, $replace); |
|
| 252 | - } elseif (is_array($line) && count($line) > 0) { |
|
| 250 | + if ( is_string( $line ) ) { |
|
| 251 | + return $this->makeReplacements( $line, $replace ); |
|
| 252 | + } elseif ( is_array( $line ) && count( $line ) > 0 ) { |
|
| 253 | 253 | return $line; |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -261,18 +261,18 @@ discard block |
||
| 261 | 261 | * @param array $replace |
| 262 | 262 | * @return string |
| 263 | 263 | */ |
| 264 | - protected function makeReplacements($line, array $replace) |
|
| 264 | + protected function makeReplacements( $line, array $replace ) |
|
| 265 | 265 | { |
| 266 | - if (empty($replace)) { |
|
| 266 | + if ( empty( $replace ) ) { |
|
| 267 | 267 | return $line; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - $replace = $this->sortReplacements($replace); |
|
| 270 | + $replace = $this->sortReplacements( $replace ); |
|
| 271 | 271 | |
| 272 | - foreach ($replace as $key => $value) { |
|
| 272 | + foreach ( $replace as $key => $value ) { |
|
| 273 | 273 | $line = str_replace( |
| 274 | - [':'.$key, ':'.Str::upper($key), ':'.Str::ucfirst($key)], |
|
| 275 | - [$value, Str::upper($value), Str::ucfirst($value)], |
|
| 274 | + [ ':' . $key, ':' . Str::upper( $key ), ':' . Str::ucfirst( $key ) ], |
|
| 275 | + [ $value, Str::upper( $value ), Str::ucfirst( $value ) ], |
|
| 276 | 276 | $line |
| 277 | 277 | ); |
| 278 | 278 | } |
@@ -286,10 +286,10 @@ discard block |
||
| 286 | 286 | * @param array $replace |
| 287 | 287 | * @return array |
| 288 | 288 | */ |
| 289 | - protected function sortReplacements(array $replace) |
|
| 289 | + protected function sortReplacements( array $replace ) |
|
| 290 | 290 | { |
| 291 | - return (new Collection($replace))->sortBy(function ($value, $key) { |
|
| 292 | - return mb_strlen($key) * -1; |
|
| 291 | + return ( new Collection( $replace ) )->sortBy( function( $value, $key ) { |
|
| 292 | + return mb_strlen( $key ) * -1; |
|
| 293 | 293 | })->all(); |
| 294 | 294 | } |
| 295 | 295 | |
@@ -301,12 +301,12 @@ discard block |
||
| 301 | 301 | * @param string $namespace |
| 302 | 302 | * @return void |
| 303 | 303 | */ |
| 304 | - public function addLines(array $lines, $locale, $namespace = '*') |
|
| 304 | + public function addLines( array $lines, $locale, $namespace = '*' ) |
|
| 305 | 305 | { |
| 306 | - foreach ($lines as $key => $value) { |
|
| 307 | - list($group, $item) = explode('.', $key, 2); |
|
| 306 | + foreach ( $lines as $key => $value ) { |
|
| 307 | + list( $group, $item ) = explode( '.', $key, 2 ); |
|
| 308 | 308 | |
| 309 | - Arr::set($this->loaded, "$namespace.$group.$locale.$item", $value); |
|
| 309 | + Arr::set( $this->loaded, "$namespace.$group.$locale.$item", $value ); |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
@@ -318,18 +318,18 @@ discard block |
||
| 318 | 318 | * @param string $locale |
| 319 | 319 | * @return void |
| 320 | 320 | */ |
| 321 | - public function load($namespace, $group, $locale) |
|
| 321 | + public function load( $namespace, $group, $locale ) |
|
| 322 | 322 | { |
| 323 | - if ($this->isLoaded($namespace, $group, $locale)) { |
|
| 323 | + if ( $this->isLoaded( $namespace, $group, $locale ) ) { |
|
| 324 | 324 | return; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // The loader is responsible for returning the array of language lines for the |
| 328 | 328 | // given namespace, group, and locale. We'll set the lines in this array of |
| 329 | 329 | // lines that have already been loaded so that we can easily access them. |
| 330 | - $lines = $this->loader->load($locale, $group, $namespace); |
|
| 330 | + $lines = $this->loader->load( $locale, $group, $namespace ); |
|
| 331 | 331 | |
| 332 | - $this->loaded[$namespace][$group][$locale] = $lines; |
|
| 332 | + $this->loaded[ $namespace ][ $group ][ $locale ] = $lines; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | * @param string $locale |
| 341 | 341 | * @return bool |
| 342 | 342 | */ |
| 343 | - protected function isLoaded($namespace, $group, $locale) |
|
| 343 | + protected function isLoaded( $namespace, $group, $locale ) |
|
| 344 | 344 | { |
| 345 | - return isset($this->loaded[$namespace][$group][$locale]); |
|
| 345 | + return isset( $this->loaded[ $namespace ][ $group ][ $locale ] ); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | * @param string $hint |
| 353 | 353 | * @return void |
| 354 | 354 | */ |
| 355 | - public function addNamespace($namespace, $hint) |
|
| 355 | + public function addNamespace( $namespace, $hint ) |
|
| 356 | 356 | { |
| 357 | - $this->loader->addNamespace($namespace, $hint); |
|
| 357 | + $this->loader->addNamespace( $namespace, $hint ); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -363,12 +363,12 @@ discard block |
||
| 363 | 363 | * @param string $key |
| 364 | 364 | * @return array |
| 365 | 365 | */ |
| 366 | - public function parseKey($key) |
|
| 366 | + public function parseKey( $key ) |
|
| 367 | 367 | { |
| 368 | - $segments = parent::parseKey($key); |
|
| 368 | + $segments = parent::parseKey( $key ); |
|
| 369 | 369 | |
| 370 | - if (is_null($segments[0])) { |
|
| 371 | - $segments[0] = '*'; |
|
| 370 | + if ( is_null( $segments[ 0 ] ) ) { |
|
| 371 | + $segments[ 0 ] = '*'; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | return $segments; |
@@ -380,9 +380,9 @@ discard block |
||
| 380 | 380 | * @param string|null $locale |
| 381 | 381 | * @return array |
| 382 | 382 | */ |
| 383 | - protected function localeArray($locale) |
|
| 383 | + protected function localeArray( $locale ) |
|
| 384 | 384 | { |
| 385 | - return array_filter([$locale ?: $this->locale, $this->fallback]); |
|
| 385 | + return array_filter( [ $locale ?: $this->locale, $this->fallback ] ); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | */ |
| 393 | 393 | public function getSelector() |
| 394 | 394 | { |
| 395 | - if (! isset($this->selector)) { |
|
| 395 | + if ( ! isset( $this->selector ) ) { |
|
| 396 | 396 | $this->selector = new MessageSelector; |
| 397 | 397 | } |
| 398 | 398 | |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Translation\MessageSelector $selector |
| 406 | 406 | * @return void |
| 407 | 407 | */ |
| 408 | - public function setSelector(MessageSelector $selector) |
|
| 408 | + public function setSelector( MessageSelector $selector ) |
|
| 409 | 409 | { |
| 410 | 410 | $this->selector = $selector; |
| 411 | 411 | } |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | * @param string $locale |
| 447 | 447 | * @return void |
| 448 | 448 | */ |
| 449 | - public function setLocale($locale) |
|
| 449 | + public function setLocale( $locale ) |
|
| 450 | 450 | { |
| 451 | 451 | $this->locale = $locale; |
| 452 | 452 | } |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @param string $fallback |
| 468 | 468 | * @return void |
| 469 | 469 | */ |
| 470 | - public function setFallback($fallback) |
|
| 470 | + public function setFallback( $fallback ) |
|
| 471 | 471 | { |
| 472 | 472 | $this->fallback = $fallback; |
| 473 | 473 | } |