Some Helper Changes

This commit is contained in:
Atish Amte 2019-03-10 17:48:18 +05:30
parent f53dc688b6
commit 3334af2ebf
No known key found for this signature in database
GPG Key ID: 8D04229F36B2886E
7 changed files with 72 additions and 50 deletions

View File

@ -247,9 +247,9 @@ if (! function_exists('form_upload'))
*
* Identical to the input function but adds the "file" type
*
* @param mixed
* @param string
* @param mixed
* @param mixed $data
* @param string $value
* @param mixed $extra
*
* @return string
*/
@ -309,10 +309,10 @@ if (! function_exists('form_multiselect'))
/**
* Multi-select menu
*
* @param string
* @param array
* @param mixed
* @param mixed
* @param string $name
* @param array $options
* @param array $selected
* @param mixed $extra
*
* @return string
*/
@ -620,7 +620,7 @@ if (! function_exists('form_datalist'))
*
* @return string
*/
function form_datalist($name, $value, $options)
function form_datalist(string $name, string $value, array $options): string
{
$data = [
'type' => 'text',
@ -905,12 +905,12 @@ if (! function_exists('parse_form_attributes'))
*
* Helper function used by some of the form helpers
*
* @param array $attributes List of attributes
* @param array $default Default values
* @param string|array $attributes List of attributes
* @param array $default Default values
*
* @return string
*/
function parse_form_attributes($attributes, $default): string
function parse_form_attributes($attributes, array $default): string
{
if (is_array($attributes))
{

View File

@ -331,7 +331,7 @@ if (! function_exists('video'))
/**
* Video
*
* Geneartes a video element to embed videos. The video element can
* Generates a video element to embed videos. The video element can
* contain one or more video sources
*
* @param mixed $src Either a source string or an array of sources
@ -461,6 +461,18 @@ if (! function_exists('audio'))
if (! function_exists('_media'))
{
/**
*
* Generate media based tag
*
* @param string $name
* @param array $types
* @param string $unsupportedMessage
* @param string $attributes
* @param array $tracks
*
* @return string
*/
function _media(string $name, array $types = [], string $unsupportedMessage = '', string $attributes = '', array $tracks = []): string
{
$media = '<' . $name;
@ -687,7 +699,12 @@ if (! function_exists('embed'))
if (! function_exists('_has_protocol'))
{
function _has_protocol($url)
/**
* @param string $url
*
* @return false|int
*/
function _has_protocol(string $url)
{
return preg_match('#^([a-z]+:)?//#i', $url);
}
@ -697,7 +714,12 @@ if (! function_exists('_has_protocol'))
if (! function_exists('_space_indent'))
{
function _space_indent($depth = 2)
/**
* @param int $depth
*
* @return string
*/
function _space_indent($depth = 2): string
{
return str_repeat(' ', $depth);
}

View File

@ -257,11 +257,11 @@ if (! function_exists('number_to_roman'))
/**
* Convert a number to a roman numeral.
*
* @param integer $num it will convert to int
* @param string $num it will convert to int
*
* @return string|null
*/
function number_to_roman($num)
function number_to_roman(string $num): ?string
{
$num = (int) $num;
if ($num < 1 || $num > 3999)

View File

@ -264,14 +264,14 @@ if (! function_exists('word_censor'))
* word you've submitted.
*
* @param string $str the text string
* @param string $censored the array of censored words
* @param array $censored the array of censored words
* @param string $replacement the optional replacement value
*
* @return string
*/
function word_censor(string $str, $censored, string $replacement = ''): string
function word_censor(string $str, array $censored, string $replacement = ''): string
{
if (! is_array($censored))
if (empty($censored))
{
return $str;
}

View File

@ -40,18 +40,18 @@ if (! function_exists('site_url'))
/**
* Return a site URL to use in views
*
* @param string|array $path
* @param string|null $scheme
* @param mixed $uri URI string or array of URI segments
* @param string|null $protocol
* @param \Config\App|null $altConfig Alternate configuration to use
*
* @return string
*/
function site_url($path = '', string $scheme = null, \Config\App $altConfig = null): string
function site_url($uri = '', string $protocol = null, \Config\App $altConfig = null): string
{
// convert segment array to string
if (is_array($path))
if (is_array($uri))
{
$path = implode('/', $path);
$uri = implode('/', $uri);
}
// use alternate config if provided, else default one
@ -64,17 +64,17 @@ if (! function_exists('site_url'))
{
$fullPath .= rtrim($config->indexPage, '/');
}
if (! empty($path))
if (! empty($uri))
{
$fullPath .= '/' . $path;
$fullPath .= '/' . $uri;
}
$url = new \CodeIgniter\HTTP\URI($fullPath);
// allow the scheme to be over-ridden; else, use default
if (! empty($scheme))
if (! empty($protocol))
{
$url->setScheme($scheme);
$url->setScheme($protocol);
}
return (string) $url;
@ -88,16 +88,16 @@ if (! function_exists('base_url'))
/**
* Return the base URL to use in views
*
* @param string|array $path
* @param string $scheme
* @param mixed $uri URI string or array of URI segments
* @param string $protocol
* @return string
*/
function base_url($path = '', string $scheme = null): string
function base_url($uri = '', string $protocol = null): string
{
// convert segment array to string
if (is_array($path))
if (is_array($uri))
{
$path = implode('/', $path);
$uri = implode('/', $uri);
}
// We should be using the configured baseURL that the user set;
@ -108,21 +108,21 @@ if (! function_exists('base_url'))
unset($config);
// Merge in the path set by the user, if any
if (! empty($path))
if (! empty($uri))
{
$url = $url->resolveRelativeURI($path);
$url = $url->resolveRelativeURI($uri);
}
// If the scheme wasn't provided, check to
// see if it was a secure request
if (empty($scheme) && \CodeIgniter\Config\Services::request()->isSecure())
if (empty($protocol) && \CodeIgniter\Config\Services::request()->isSecure())
{
$scheme = 'https';
$protocol = 'https';
}
if (! empty($scheme))
if (! empty($protocol))
{
$url->setScheme($scheme);
$url->setScheme($protocol);
}
return (string) $url;
@ -223,7 +223,7 @@ if (! function_exists('anchor'))
*
* Creates an anchor based on the local URL.
*
* @param string $uri The URL
* @param mixed $uri URI string or array of URI segments
* @param string $title The link title
* @param mixed $attributes Any attributes
* @param \Config\App|null $altConfig Alternate configuration to use
@ -332,7 +332,7 @@ if (! function_exists('mailto'))
*
* @return string
*/
function mailto($email, string $title = '', $attributes = ''): string
function mailto(string $email, string $title = '', $attributes = ''): string
{
if (trim($title) === '')
{
@ -358,7 +358,7 @@ if (! function_exists('safe_mailto'))
*
* @return string
*/
function safe_mailto($email, string $title = '', $attributes = ''): string
function safe_mailto(string $email, string $title = '', $attributes = ''): string
{
if (trim($title) === '')
{
@ -470,7 +470,7 @@ if (! function_exists('auto_link'))
*
* @return string
*/
function auto_link($str, $type = 'both', $popup = false): string
function auto_link(string $str, string $type = 'both', bool $popup = false): string
{
// Find and replace any URLs.
if ($type !== 'email' && preg_match_all('#(\w*://|www\.)[^\s()<>;]+\w#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER))
@ -522,7 +522,7 @@ if (! function_exists('prep_url'))
* @param string the URL
* @return string
*/
function prep_url($str = ''): string
function prep_url(string $str = ''): string
{
if ($str === 'http://' || $str === '')
{
@ -556,7 +556,7 @@ if (! function_exists('url_title'))
* @param boolean $lowercase Whether to transform the output string to lowercase
* @return string
*/
function url_title($str, $separator = '-', $lowercase = false): string
function url_title(string $str, string $separator = '-', bool $lowercase = false): string
{
$q_separator = preg_quote($separator, '#');

View File

@ -40,11 +40,11 @@ if (! function_exists('xml_convert'))
/**
* Convert Reserved XML characters to Entities
*
* @param string
* @param boolean
* @param string $str
* @param boolean $protect_all
* @return string
*/
function xml_convert(string $str, $protect_all = false): string
function xml_convert(string $str, bool $protect_all = false): string
{
$temp = '__TEMP_AMPERSANDS__';

View File

@ -23,7 +23,7 @@ The following functions are available:
.. php:function:: site_url([$uri = ''[, $protocol = NULL[, $altConfig = NULL]]])
:param string $uri: URI string
:param mixed $uri: URI string or array of URI segments
:param string $protocol: Protocol, e.g. 'http' or 'https'
:param \\Config\\App $altConfig: Alternate configuration to use
:returns: Site URL
@ -57,7 +57,7 @@ The following functions are available:
.. php:function:: base_url([$uri = ''[, $protocol = NULL]])
:param string $uri: URI string
:param mixed $uri: URI string or array of URI segments
:param string $protocol: Protocol, e.g. 'http' or 'https'
:returns: Base URL
:rtype: string