for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Created by Gorlum 04.06.2017 15:18
*/
namespace Common\Exceptions;
use Throwable;
* Class ExceptionSnLocalized
*
* Localized Exception - uses Message as locale string ID
* @package Exceptions
class ExceptionSnLocalized extends \Exception {
* @var array $sprintf
protected $sprintf = array();
* ExceptionSnLocalized constructor.
* @param string $message
* @param int $code
* @param Throwable|null $previous
* @param array $sprintf - params for sprintf() call to embed into message
public function __construct($message = "", $code = 0, Throwable $previous = null, $sprintf = array()) {
parent::__construct($message, $code, $previous);
$this->sprintf = $sprintf;
}
* @return string
protected function getPlayerLocalization($message) {
global $lang;
global
Instead of relying on global state, we recommend one of these alternatives:
function myFunction($a, $b) { // Do something }
class MyClass { private $a; private $b; public function __construct($a, $b) { $this->a = $a; $this->b = $b; } public function myFunction() { // Do something } }
return !empty($lang[$message]) ? $lang[$message] : '';
public function getMessageLocalized() {
$message = $this->getPlayerLocalization($this->getMessage());
if (is_array($this->sprintf) && !empty($this->sprintf)) {
$message = call_user_func_array('sprintf', array_merge(array($message), $this->sprintf));
return $message;
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state