diff options
author | Marvin Borner | 2018-05-23 22:23:28 +0200 |
---|---|---|
committer | Marvin Borner | 2018-05-23 22:23:28 +0200 |
commit | b66a61addb6c8e66cb26fcf74b532d68891267e4 (patch) | |
tree | 05e9449ff25bdc98f68105f41923ccb9f6ef5095 /main/app/sprinkles/core/src/Util | |
parent | 1d4ef435177a5f9b6d1a289800d933e49be0c550 (diff) |
Refactored code, many fixes and improvements in chat backend+frontend
Diffstat (limited to 'main/app/sprinkles/core/src/Util')
-rw-r--r-- | main/app/sprinkles/core/src/Util/BadClassNameException.php | 1 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Util/Captcha.php | 53 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Util/CheckEnvironment.php | 123 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Util/ClassMapper.php | 14 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Util/EnvironmentInfo.php | 11 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Util/ShutdownHandler.php | 25 | ||||
-rw-r--r-- | main/app/sprinkles/core/src/Util/Util.php | 47 |
7 files changed, 126 insertions, 148 deletions
diff --git a/main/app/sprinkles/core/src/Util/BadClassNameException.php b/main/app/sprinkles/core/src/Util/BadClassNameException.php index 09c4ea5..1cd6f4e 100644 --- a/main/app/sprinkles/core/src/Util/BadClassNameException.php +++ b/main/app/sprinkles/core/src/Util/BadClassNameException.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Util; /** diff --git a/main/app/sprinkles/core/src/Util/Captcha.php b/main/app/sprinkles/core/src/Util/Captcha.php index c788b77..4c221cb 100644 --- a/main/app/sprinkles/core/src/Util/Captcha.php +++ b/main/app/sprinkles/core/src/Util/Captcha.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Util; use UserFrosting\Session\Session; @@ -43,8 +44,7 @@ class Captcha /** * Create a new captcha. */ - public function __construct($session, $key) - { + public function __construct($session, $key) { $this->session = $session; $this->key = $key; @@ -59,9 +59,8 @@ class Captcha * This generates a random 5-character captcha and stores it in the session with an md5 hash. * Also, generates the corresponding captcha image. */ - public function generateRandomCode() - { - $md5_hash = md5(rand(0,99999)); + public function generateRandomCode() { + $md5_hash = md5(rand(0, 99999)); $this->code = substr($md5_hash, 25, 5); $enc = md5($this->code); @@ -74,16 +73,14 @@ class Captcha /** * Returns the captcha code. */ - public function getCaptcha() - { + public function getCaptcha() { return $this->code; } /** * Returns the captcha image. */ - public function getImage() - { + public function getImage() { return $this->image; } @@ -94,8 +91,7 @@ class Captcha * @param string * @return bool */ - public function verifyCode($code) - { + public function verifyCode($code) { return (md5($code) == $this->session[$this->key]); } @@ -104,8 +100,7 @@ class Captcha * * This generates an image as a binary string. */ - protected function generateImage() - { + protected function generateImage() { $width = 150; $height = 30; @@ -114,39 +109,39 @@ class Captcha //color pallette $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); - $red = imagecolorallocate($image,255,0,0); + $red = imagecolorallocate($image, 255, 0, 0); $yellow = imagecolorallocate($image, 255, 255, 0); - $dark_grey = imagecolorallocate($image, 64,64,64); - $blue = imagecolorallocate($image, 0,0,255); + $dark_grey = imagecolorallocate($image, 64, 64, 64); + $blue = imagecolorallocate($image, 0, 0, 255); //create white rectangle - imagefilledrectangle($image,0,0,150,30,$white); + imagefilledrectangle($image, 0, 0, 150, 30, $white); //add some lines - for($i=0;$i<2;$i++) { - imageline($image,0,rand()%10,10,rand()%30,$dark_grey); - imageline($image,0,rand()%30,150,rand()%30,$red); - imageline($image,0,rand()%30,150,rand()%30,$yellow); + for ($i = 0; $i < 2; $i++) { + imageline($image, 0, rand() % 10, 10, rand() % 30, $dark_grey); + imageline($image, 0, rand() % 30, 150, rand() % 30, $red); + imageline($image, 0, rand() % 30, 150, rand() % 30, $yellow); } // RandTab color pallette $randc[0] = imagecolorallocate($image, 0, 0, 0); - $randc[1] = imagecolorallocate($image,255,0,0); + $randc[1] = imagecolorallocate($image, 255, 0, 0); $randc[2] = imagecolorallocate($image, 255, 255, 0); - $randc[3] = imagecolorallocate($image, 64,64,64); - $randc[4] = imagecolorallocate($image, 0,0,255); + $randc[3] = imagecolorallocate($image, 64, 64, 64); + $randc[4] = imagecolorallocate($image, 0, 0, 255); //add some dots - for($i=0;$i<1000;$i++) { - imagesetpixel($image,rand()%200,rand()%50,$randc[rand()%5]); + for ($i = 0; $i < 1000; $i++) { + imagesetpixel($image, rand() % 200, rand() % 50, $randc[rand() % 5]); } //calculate center of text - $x = ( 150 - 0 - imagefontwidth( 5 ) * strlen( $this->code ) ) / 2 + 0 + 5; + $x = (150 - 0 - imagefontwidth(5) * strlen($this->code)) / 2 + 0 + 5; //write string twice - imagestring($image,5, $x, 7, $this->code, $black); - imagestring($image,5, $x, 7, $this->code, $black); + imagestring($image, 5, $x, 7, $this->code, $black); + imagestring($image, 5, $x, 7, $this->code, $black); //start ob ob_start(); imagepng($image); diff --git a/main/app/sprinkles/core/src/Util/CheckEnvironment.php b/main/app/sprinkles/core/src/Util/CheckEnvironment.php index 26925d9..05b555f 100644 --- a/main/app/sprinkles/core/src/Util/CheckEnvironment.php +++ b/main/app/sprinkles/core/src/Util/CheckEnvironment.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Util; use Psr\Http\Message\ResponseInterface; @@ -49,8 +50,7 @@ class CheckEnvironment * @param $view \Slim\Views\Twig The view object, needed for rendering error page. * @param $locator \RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator Locator service for stream resources. */ - public function __construct($view, $locator, $cache) - { + public function __construct($view, $locator, $cache) { $this->view = $view; $this->locator = $locator; $this->cache = $cache; @@ -59,15 +59,14 @@ class CheckEnvironment /** * Invoke the CheckEnvironment middleware, performing all pre-flight checks and returning an error page if problems were found. * - * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request - * @param \Psr\Http\Message\ResponseInterface $response PSR7 response - * @param callable $next Next middleware + * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request + * @param \Psr\Http\Message\ResponseInterface $response PSR7 response + * @param callable $next Next middleware * * @return \Psr\Http\Message\ResponseInterface */ - public function __invoke($request, $response, $next) - { - $problemsFound = false; + public function __invoke($request, $response, $next) { + $problemsFound = FALSE; // If production environment and no cached checks, perform environment checks if ($this->isProduction() && $this->cache->get('checkEnvironment') != 'pass') { @@ -77,7 +76,7 @@ class CheckEnvironment if (!$problemsFound) { $this->cache->forever('checkEnvironment', 'pass'); } - } elseif (!$this->isProduction()) { + } else if (!$this->isProduction()) { $problemsFound = $this->checkAll(); } @@ -97,21 +96,20 @@ class CheckEnvironment /** * Run through all pre-flight checks. */ - public function checkAll() - { - $problemsFound = false; + public function checkAll() { + $problemsFound = FALSE; - if ($this->checkApache()) $problemsFound = true; + if ($this->checkApache()) $problemsFound = TRUE; - if ($this->checkPhp()) $problemsFound = true; + if ($this->checkPhp()) $problemsFound = TRUE; - if ($this->checkPdo()) $problemsFound = true; + if ($this->checkPdo()) $problemsFound = TRUE; - if ($this->checkGd()) $problemsFound = true; + if ($this->checkGd()) $problemsFound = TRUE; - if ($this->checkImageFunctions()) $problemsFound = true; + if ($this->checkImageFunctions()) $problemsFound = TRUE; - if ($this->checkPermissions()) $problemsFound = true; + if ($this->checkPermissions()) $problemsFound = TRUE; return $problemsFound; } @@ -119,12 +117,11 @@ class CheckEnvironment /** * For Apache environments, check that required Apache modules are installed. */ - public function checkApache() - { - $problemsFound = false; + public function checkApache() { + $problemsFound = FALSE; // Perform some Apache checks. We may also need to do this before any routing takes place. - if (strpos(php_sapi_name(), 'apache') !== false) { + if (strpos(php_sapi_name(), 'apache') !== FALSE) { $require_apache_modules = ['mod_rewrite']; $apache_modules = apache_get_modules(); @@ -133,17 +130,17 @@ class CheckEnvironment foreach ($require_apache_modules as $module) { if (!in_array($module, $apache_modules)) { - $problemsFound = true; + $problemsFound = TRUE; $this->resultsFailed['apache-' . $module] = [ "title" => "<i class='fa fa-server fa-fw'></i> Missing Apache module <b>$module</b>.", "message" => "Please make sure that the <code>$module</code> Apache module is installed and enabled. If you use shared hosting, you will need to ask your web host to do this for you.", - "success" => false + "success" => FALSE ]; } else { $this->resultsSuccess['apache-' . $module] = [ "title" => "<i class='fa fa-server fa-fw'></i> Apache module <b>$module</b> is installed and enabled.", "message" => "Great, we found the <code>$module</code> Apache module!", - "success" => true + "success" => TRUE ]; } } @@ -155,22 +152,21 @@ class CheckEnvironment /** * Check for GD library (required for Captcha). */ - public function checkGd() - { - $problemsFound = false; + public function checkGd() { + $problemsFound = FALSE; if (!(extension_loaded('gd') && function_exists('gd_info'))) { - $problemsFound = true; + $problemsFound = TRUE; $this->resultsFailed['gd'] = [ "title" => "<i class='fa fa-image fa-fw'></i> GD library not installed", "message" => "We could not confirm that the <code>GD</code> library is installed and enabled. GD is an image processing library that UserFrosting uses to generate captcha codes for user account registration.", - "success" => false + "success" => FALSE ]; } else { $this->resultsSuccess['gd'] = [ "title" => "<i class='fa fa-image fa-fw'></i> GD library installed!", "message" => "Great, you have <code>GD</code> installed and enabled.", - "success" => true + "success" => TRUE ]; } @@ -182,9 +178,8 @@ class CheckEnvironment * * Some versions of GD are missing one or more of these functions, thus why we check for them explicitly. */ - public function checkImageFunctions() - { - $problemsFound = false; + public function checkImageFunctions() { + $problemsFound = FALSE; $funcs = [ 'imagepng', @@ -199,17 +194,17 @@ class CheckEnvironment foreach ($funcs as $func) { if (!function_exists($func)) { - $problemsFound = true; + $problemsFound = TRUE; $this->resultsFailed['function-' . $func] = [ "title" => "<i class='fa fa-code fa-fw'></i> Missing image manipulation function.", "message" => "It appears that function <code>$func</code> is not available. UserFrosting needs this to render captchas.", - "success" => false + "success" => FALSE ]; } else { $this->resultsSuccess['function-' . $func] = [ "title" => "<i class='fa fa-code fa-fw'></i> Function <b>$func</b> is available!", "message" => "Sweet!", - "success" => true + "success" => TRUE ]; } } @@ -220,22 +215,21 @@ class CheckEnvironment /** * Check that PDO is installed and enabled. */ - public function checkPdo() - { - $problemsFound = false; + public function checkPdo() { + $problemsFound = FALSE; if (!class_exists('PDO')) { - $problemsFound = true; + $problemsFound = TRUE; $this->resultsFailed['pdo'] = [ "title" => "<i class='fa fa-database fa-fw'></i> PDO is not installed.", "message" => "I'm sorry, you must have PDO installed and enabled in order for UserFrosting to access the database. If you don't know what PDO is, please see <a href='http://php.net/manual/en/book.pdo.php'>http://php.net/manual/en/book.pdo.php</a>.", - "success" => false + "success" => FALSE ]; } else { $this->resultsSuccess['pdo'] = [ "title" => "<i class='fa fa-database fa-fw'></i> PDO is installed!", "message" => "You've got PDO installed. Good job!", - "success" => true + "success" => TRUE ]; } @@ -245,38 +239,37 @@ class CheckEnvironment /** * Check that log, cache, and session directories are writable, and that other directories are set appropriately for the environment. */ - function checkPermissions() - { - $problemsFound = false; + function checkPermissions() { + $problemsFound = FALSE; $shouldBeWriteable = [ - $this->locator->findResource('log://') => true, - $this->locator->findResource('cache://') => true, - $this->locator->findResource('session://') => true + $this->locator->findResource('log://') => TRUE, + $this->locator->findResource('cache://') => TRUE, + $this->locator->findResource('session://') => TRUE ]; if ($this->isProduction()) { // Should be write-protected in production! $shouldBeWriteable = array_merge($shouldBeWriteable, [ - \UserFrosting\SPRINKLES_DIR => false, - \UserFrosting\VENDOR_DIR => false + \UserFrosting\SPRINKLES_DIR => FALSE, + \UserFrosting\VENDOR_DIR => FALSE ]); } // Check for essential files & perms foreach ($shouldBeWriteable as $file => $assertWriteable) { - $is_dir = false; + $is_dir = FALSE; if (!file_exists($file)) { - $problemsFound = true; + $problemsFound = TRUE; $this->resultsFailed['file-' . $file] = [ "title" => "<i class='fa fa-file-o fa-fw'></i> File or directory does not exist.", "message" => "We could not find the file or directory <code>$file</code>.", - "success" => false + "success" => FALSE ]; } else { $writeable = is_writable($file); if ($assertWriteable !== $writeable) { - $problemsFound = true; + $problemsFound = TRUE; $this->resultsFailed['file-' . $file] = [ "title" => "<i class='fa fa-file-o fa-fw'></i> Incorrect permissions for file or directory.", "message" => "<code>$file</code> is " @@ -286,7 +279,7 @@ class CheckEnvironment . ". Please modify the OS user or group permissions so that user <b>" . exec('whoami') . "</b> " . ($assertWriteable ? "has" : "does not have") . " write permissions for this directory.", - "success" => false + "success" => FALSE ]; } else { $this->resultsSuccess['file-' . $file] = [ @@ -294,7 +287,7 @@ class CheckEnvironment "message" => "<code>$file</code> exists and is correctly set as <b>" . ($writeable ? "writeable" : "not writeable") . "</b>.", - "success" => true + "success" => TRUE ]; } } @@ -305,23 +298,22 @@ class CheckEnvironment /** * Check that PHP meets the minimum required version. */ - public function checkPhp() - { - $problemsFound = false; + public function checkPhp() { + $problemsFound = FALSE; // Check PHP version if (version_compare(phpversion(), \UserFrosting\PHP_MIN_VERSION, '<')) { - $problemsFound = true; + $problemsFound = TRUE; $this->resultsFailed['phpVersion'] = [ "title" => "<i class='fa fa-code fa-fw'></i> You need to upgrade your PHP installation.", "message" => "I'm sorry, UserFrosting requires version " . \UserFrosting\PHP_MIN_VERSION . " or greater. Please upgrade your version of PHP, or contact your web hosting service and ask them to upgrade it for you.", - "success" => false + "success" => FALSE ]; } else { $this->resultsSuccess['phpVersion'] = [ "title" => "<i class='fa fa-code fa-fw'></i> PHP version checks out!", - "message" => "You're using PHP " . \UserFrosting\PHP_MIN_VERSION . "or higher. Great!", - "success" => true + "message" => "You're using PHP " . \UserFrosting\PHP_MIN_VERSION . "or higher. Great!", + "success" => TRUE ]; } @@ -333,8 +325,7 @@ class CheckEnvironment * * @return bool */ - public function isProduction() - { + public function isProduction() { return (getenv('UF_MODE') == 'production'); } } diff --git a/main/app/sprinkles/core/src/Util/ClassMapper.php b/main/app/sprinkles/core/src/Util/ClassMapper.php index 5fa0881..11720f6 100644 --- a/main/app/sprinkles/core/src/Util/ClassMapper.php +++ b/main/app/sprinkles/core/src/Util/ClassMapper.php @@ -30,8 +30,7 @@ class ClassMapper * @param string $identifier The identifier for the class, e.g. 'user' * @param mixed ...$arg Whatever needs to be passed to the constructor. */ - public function createInstance($identifier) - { + public function createInstance($identifier) { $className = $this->getClassMapping($identifier); $params = array_slice(func_get_args(), 1); @@ -48,8 +47,7 @@ class ClassMapper * @param string $identifier * @return string */ - public function getClassMapping($identifier) - { + public function getClassMapping($identifier) { if (isset($this->classMappings[$identifier])) { return $this->classMappings[$identifier]; } else { @@ -64,11 +62,10 @@ class ClassMapper * @param string $className * @return ClassMapper */ - public function setClassMapping($identifier, $className) - { + public function setClassMapping($identifier, $className) { // Check that class exists if (!class_exists($className)) { - throw new BadClassNameException("Unable to find the class '$className'." ); + throw new BadClassNameException("Unable to find the class '$className'."); } $this->classMappings[$identifier] = $className; @@ -83,8 +80,7 @@ class ClassMapper * @param string $methodName The method to be invoked. * @param mixed ...$arg Whatever needs to be passed to the method. */ - public function staticMethod($identifier, $methodName) - { + public function staticMethod($identifier, $methodName) { $className = $this->getClassMapping($identifier); $params = array_slice(func_get_args(), 2); diff --git a/main/app/sprinkles/core/src/Util/EnvironmentInfo.php b/main/app/sprinkles/core/src/Util/EnvironmentInfo.php index aba9837..116a59e 100644 --- a/main/app/sprinkles/core/src/Util/EnvironmentInfo.php +++ b/main/app/sprinkles/core/src/Util/EnvironmentInfo.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Util; use Illuminate\Database\Capsule\Manager as Capsule; @@ -28,8 +29,7 @@ class EnvironmentInfo * * @return string[] the properties of this database. */ - public static function database() - { + public static function database() { static::$ci['db']; $pdo = Capsule::connection()->getPdo(); @@ -55,14 +55,13 @@ class EnvironmentInfo * * @return bool true if the connection can be established, false otherwise. */ - public static function canConnectToDatabase() - { + public static function canConnectToDatabase() { try { Capsule::connection()->getPdo(); } catch (\PDOException $e) { - return false; + return FALSE; } - return true; + return TRUE; } } diff --git a/main/app/sprinkles/core/src/Util/ShutdownHandler.php b/main/app/sprinkles/core/src/Util/ShutdownHandler.php index e7a6903..5447c8f 100644 --- a/main/app/sprinkles/core/src/Util/ShutdownHandler.php +++ b/main/app/sprinkles/core/src/Util/ShutdownHandler.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Util; use Interop\Container\ContainerInterface; @@ -36,8 +37,7 @@ class ShutdownHandler * @param ContainerInterface $ci The global container object, which holds all your services. * @param bool $displayErrorInfo */ - public function __construct(ContainerInterface $ci, $displayErrorInfo) - { + public function __construct(ContainerInterface $ci, $displayErrorInfo) { $this->ci = $ci; $this->displayErrorInfo = $displayErrorInfo; } @@ -47,16 +47,14 @@ class ShutdownHandler * * @return void */ - public function register() - { + public function register() { register_shutdown_function([$this, 'fatalHandler']); } /** * Set up the fatal error handler, so that we get a clean error message and alert instead of a WSOD. */ - public function fatalHandler() - { + public function fatalHandler() { $error = error_get_last(); $fatalErrorTypes = [ E_ERROR, @@ -78,7 +76,7 @@ class ShutdownHandler // For CLI, just print the message and exit. if (php_sapi_name() === 'cli') { - exit($errorMessage . PHP_EOL); + exit($errorMessage . PHP_EOL); } // For all other environments, print a debug response for the requested data type @@ -102,11 +100,10 @@ class ShutdownHandler * @param array $error * @return string */ - protected function buildErrorInfoMessage(array $error) - { + protected function buildErrorInfoMessage(array $error) { $errfile = $error['file']; - $errline = (string) $error['line']; - $errstr = $error['message']; + $errline = (string)$error['line']; + $errstr = $error['message']; $errorTypes = [ E_ERROR => 'Fatal error', @@ -125,8 +122,7 @@ class ShutdownHandler * @param string $message * @return string */ - protected function buildErrorPage($message) - { + protected function buildErrorPage($message) { $contentType = $this->determineContentType($this->ci->request, $this->ci->config['site.debug.ajax']); switch ($contentType) { @@ -149,8 +145,7 @@ class ShutdownHandler * @param string $errorMessage * @return string */ - protected function buildHtmlErrorPage($message) - { + protected function buildHtmlErrorPage($message) { $title = 'UserFrosting Application Error'; $html = "<p>$message</p>"; diff --git a/main/app/sprinkles/core/src/Util/Util.php b/main/app/sprinkles/core/src/Util/Util.php index ae551cf..0db3b72 100644 --- a/main/app/sprinkles/core/src/Util/Util.php +++ b/main/app/sprinkles/core/src/Util/Util.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Sprinkle\Core\Util; /** @@ -24,8 +25,7 @@ class Util * @param bool $remove * @return mixed[] */ - static public function extractFields(&$inputArray, $fieldArray, $remove = true) - { + static public function extractFields(&$inputArray, $fieldArray, $remove = TRUE) { $result = []; foreach ($fieldArray as $name) { @@ -48,8 +48,7 @@ class Util * @param string $str * @return string */ - static public function extractDigits($str) - { + static public function extractDigits($str) { return preg_replace('/[^0-9]/', '', $str); } @@ -59,15 +58,14 @@ class Util * @param string $phone * @return string */ - static public function formatPhoneNumber($phone) - { + static public function formatPhoneNumber($phone) { $num = static::extractDigits($phone); $len = strlen($num); if ($len == 7) { $num = preg_replace('/([0-9]{3})([0-9]{4})/', '$1-$2', $num); - } elseif ($len == 10) { + } else if ($len == 10) { $num = preg_replace('/([0-9]{3})([0-9]{3})([0-9]{4})/', '($1) $2-$3', $num); } @@ -81,13 +79,12 @@ class Util * @param array $arr * @return string */ - static public function prettyPrintArray(array $arr) - { + static public function prettyPrintArray(array $arr) { $json = json_encode($arr); $result = ''; $level = 0; - $inQuotes = false; - $inEscape = false; + $inQuotes = FALSE; + $inEscape = FALSE; $endsLineLevel = NULL; $jsonLength = strlen($json); @@ -100,18 +97,20 @@ class Util $endsLineLevel = NULL; } if ($inEscape) { - $inEscape = false; - } elseif ($char === '"') { + $inEscape = FALSE; + } else if ($char === '"') { $inQuotes = !$inQuotes; - } elseif (!$inQuotes) { + } else if (!$inQuotes) { switch ($char) { - case '}': case ']': + case '}': + case ']': $level--; $endsLineLevel = NULL; $newLineLevel = $level; break; - case '{': case '[': + case '{': + case '[': $level++; case ',': @@ -122,21 +121,24 @@ class Util $post = ' '; break; - case ' ': case '\t': case '\n': case '\r': + case ' ': + case '\t': + case '\n': + case '\r': $char = ''; $endsLineLevel = $newLineLevel; $newLineLevel = NULL; break; } - } elseif ($char === '\\') { - $inEscape = true; + } else if ($char === '\\') { + $inEscape = TRUE; } if ($newLineLevel !== NULL) { - $result .= '<br>'.str_repeat( ' ', $newLineLevel); + $result .= '<br>' . str_repeat(' ', $newLineLevel); } - $result .= $char.$post; + $result .= $char . $post; } return $result; @@ -151,8 +153,7 @@ class Util * @param string $separator * @return string */ - static public function randomPhrase($numAdjectives, $maxLength = 9999999, $maxTries = 10, $separator = '-') - { + static public function randomPhrase($numAdjectives, $maxLength = 9999999, $maxTries = 10, $separator = '-') { $adjectives = include('extra://adjectives.php'); $nouns = include('extra://nouns.php'); |