Refresh
This commit is contained in:
56
app/Helpers/Cleaner.php
Executable file
56
app/Helpers/Cleaner.php
Executable file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use ForceUTF8\Encoding as UTF8;
|
||||
|
||||
/**
|
||||
* Helper class to cleanup, format, sanitize strings.
|
||||
*/
|
||||
class Cleaner
|
||||
{
|
||||
/**
|
||||
* Ensures string doesn't contain any "undesirable" characters, such as
|
||||
* extra-spaces or line-breaks. This is not a purifying method. Only basic
|
||||
* cleanup is done here.
|
||||
*
|
||||
* @param string $string
|
||||
* @param mixed $stripTags
|
||||
* @param mixed $removeExtraSpaces
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function cleanupString($string, $stripTags = false, $removeExtraSpaces = false)
|
||||
{
|
||||
if (empty($string)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$string = trim($string);
|
||||
$string = UTF8::toUTF8($string, UTF8::ICONV_TRANSLIT);
|
||||
$string = html_entity_decode($string, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$string = str_replace(''', "'", $string);
|
||||
|
||||
if ($removeExtraSpaces) {
|
||||
$string = preg_replace('/[[:space:]]+/', ' ', $string);
|
||||
}
|
||||
|
||||
if ($stripTags) {
|
||||
return strip_tags(trim($string));
|
||||
}
|
||||
|
||||
return self::sanitize($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform some sanitizing actions on specified string.
|
||||
*
|
||||
* @param mixed $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitize($string)
|
||||
{
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
36
app/Helpers/Url.php
Executable file
36
app/Helpers/Url.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use League\Uri\Http as UriHttp;
|
||||
use League\Uri\UriResolver;
|
||||
|
||||
/**
|
||||
* Helper to work with urls.
|
||||
*/
|
||||
class Url
|
||||
{
|
||||
/**
|
||||
* Convert specified relative URL to an absolute URL using specified base
|
||||
* URL.
|
||||
*
|
||||
* @param mixed $baseUrl
|
||||
* @param mixed $relativeUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function makeUrlAbsolute($baseUrl, $relativeUrl)
|
||||
{
|
||||
if (\is_string($baseUrl)) {
|
||||
$baseUrl = UriHttp::createFromString($baseUrl);
|
||||
}
|
||||
|
||||
if (\is_string($relativeUrl)) {
|
||||
$relativeUrl = UriHttp::createFromString($relativeUrl);
|
||||
}
|
||||
|
||||
$newUri = UriResolver::resolve($relativeUrl, $baseUrl);
|
||||
|
||||
return (string) $newUri;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user