new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Helper;
|
||||
|
||||
class Casing
|
||||
{
|
||||
/**
|
||||
* Casing
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $type = 'lower'
|
||||
* @param string $encoding = 'utf-8'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function use(string $str, string $type = 'lower', string $encoding = 'utf-8') : string
|
||||
{
|
||||
return mb_convert_case($str, Helper::toConstant($type, 'MB_CASE_'), $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upper
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $encoding = 'utf-8'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function upper(string $str, string $encoding = 'utf-8') : string
|
||||
{
|
||||
return self::use($str, __FUNCTION__, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $encoding = 'utf-8'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function lower(string $str, string $encoding = 'utf-8') : string
|
||||
{
|
||||
return self::use($str, __FUNCTION__, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Title
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $encoding = 'utf-8'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function title(string $str, string $encoding = 'utf-8') : string
|
||||
{
|
||||
return self::use($str, __FUNCTION__, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Camel
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function camel(string $str) : string
|
||||
{
|
||||
$string = self::title(trim($str));
|
||||
|
||||
$string[0] = self::lower($string);
|
||||
|
||||
return Trim::middle($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pascal
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pascal(string $str) : string
|
||||
{
|
||||
$string = self::title(trim($str));
|
||||
|
||||
return Trim::middle($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Underscore
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function underscore(string $str) : string
|
||||
{
|
||||
return preg_replace('/(\s+)/', '_', strtolower($str));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Element
|
||||
{
|
||||
/**
|
||||
* Remove First Element
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $separator = '/'
|
||||
* @param int $index = 0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removeFirst(string $str, string $separator = '/', int $index = 0) : string
|
||||
{
|
||||
return self::remove($str, $separator, abs($index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Last Element
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $separator = '/'
|
||||
* @param int $index = 0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removeLast(string $str, string $separator = '/', int $index = 0) : string
|
||||
{
|
||||
return self::remove($str, $separator, -abs($index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Element
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $separator = '/'
|
||||
* @param int $index = 0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function remove(string $str, string $separator = '/', int $index = 0) : string
|
||||
{
|
||||
$strEx = explode($separator, $str);
|
||||
|
||||
if( ($countStr = count($strEx)) === 1 ) return $str;
|
||||
|
||||
$count = abs($index);
|
||||
|
||||
if( $countStr < $count ) $count = $countStr;
|
||||
|
||||
if( $count > 0 ) for( $start = 1; $start <= $count; $start++ )
|
||||
{
|
||||
($index < 0 ? 'array_pop' : 'array_shift')($strEx);
|
||||
}
|
||||
|
||||
return implode($separator, $strEx);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Search
|
||||
{
|
||||
/**
|
||||
* Finds the expression between two statements.
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $start
|
||||
* @param string $end
|
||||
* @param bool $case = true [optional]
|
||||
* @param bool $both = false [optional]
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function between(string $str, string $start, string $end, bool $case = true, bool $both = false)
|
||||
{
|
||||
if( preg_match('/(?<start>' . preg_quote($start, '/') . ')(?<search>.*?)(?<end>' . preg_quote($end, '/') . ')/' . ( $case === true ? NULL : 'i' ), $str, $match) )
|
||||
{
|
||||
if( $both === false )
|
||||
{
|
||||
return $match['search'];
|
||||
}
|
||||
|
||||
return $match['start'] . $match['search'] . $match['end'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the expression between two expressions, including parameters.
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $start
|
||||
* @param string $end
|
||||
* @param bool $case = true [optional]
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function betweenBoth(string $str, string $start, string $end, bool $case = true)
|
||||
{
|
||||
return self::between($str, $start, $end, $case, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $needle
|
||||
* @param string $type = 'string' - options[string|position]
|
||||
* @param bool $case = true
|
||||
*/
|
||||
public static function use(string $str, string $needle, string $type = 'string', bool $case = true)
|
||||
{
|
||||
if( $type === 'string' )
|
||||
{
|
||||
if( $case === true )
|
||||
{
|
||||
$function = 'mb_strstr';
|
||||
}
|
||||
else
|
||||
{
|
||||
$function = 'mb_stristr'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $function($str, $needle);
|
||||
}
|
||||
|
||||
if( $type === 'position' )
|
||||
{
|
||||
if( $case === true )
|
||||
{
|
||||
$function = 'mb_strpos';
|
||||
}
|
||||
else
|
||||
{
|
||||
$function = 'mb_stripos';
|
||||
}
|
||||
|
||||
return $function($str, $needle);
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Position
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $needle
|
||||
* @param bool $case = true
|
||||
*/
|
||||
public static function position(string $str, string $needle, bool $case = true)
|
||||
{
|
||||
return self::use($str, $needle, __FUNCTION__, $case);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search String
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $needle
|
||||
* @param bool $case = true
|
||||
*/
|
||||
public static function string(string $str, string $needle, bool $case = true) : string
|
||||
{
|
||||
return self::use($str, $needle, __FUNCTION__, $case);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Section
|
||||
{
|
||||
/**
|
||||
* Section
|
||||
*
|
||||
* @param string $str
|
||||
* @param int $starting = 0
|
||||
* @param int $count = NULL
|
||||
* @param string $encoding = 'utf-8'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function use(string $str, int $starting = 0, ?int $count = NULL, string $encoding = 'utf-8') : string
|
||||
{
|
||||
return mb_substr($str, $starting, $count, $encoding);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Security
|
||||
{
|
||||
/**
|
||||
* Add Slashes
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $addDifferentChars = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function addSlashes(string $string, ?string $addDifferentChars = NULL) : string
|
||||
{
|
||||
$return = addslashes($string);
|
||||
|
||||
if( ! empty($addDifferentChars) )
|
||||
{
|
||||
$return = addcslashes($return, $addDifferentChars);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Slashes
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removeSlashes(string $string) : string
|
||||
{
|
||||
return stripslashes(stripcslashes($string));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
use ZN\Datatype;
|
||||
|
||||
class Split
|
||||
{
|
||||
/**
|
||||
* Split Upper Case
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function upperCase(string $string) : array
|
||||
{
|
||||
return Datatype::splitUpperCase($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apportion
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $length = 76
|
||||
* @param string $end = PHP_EOL
|
||||
*/
|
||||
public static function apportion(string $string, int $length = 76, string $end = PHP_EOL) : string
|
||||
{
|
||||
$arrayChunk = array_chunk(preg_split("//u", $string, -1, PREG_SPLIT_NO_EMPTY), $length);
|
||||
|
||||
$string = '';
|
||||
|
||||
foreach( $arrayChunk as $chunk )
|
||||
{
|
||||
$string .= implode('', $chunk) . $end;
|
||||
}
|
||||
|
||||
return Base::removeSuffix($string, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide
|
||||
*
|
||||
* @param string $str = NULL
|
||||
* @param string $separator = '|'
|
||||
* @param string $index = '0'
|
||||
* @param string $count = '1' - added[5.6.02]
|
||||
*/
|
||||
public static function divide(?string $str = NULL, string $separator = '|', string $index = '0', string $count = '1')
|
||||
{
|
||||
return Datatype::divide($str, $separator, $index, $count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Substitution
|
||||
{
|
||||
/**
|
||||
* Reshuffle
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $shuffle
|
||||
* @param string $reshuffle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function reshuffle(string $str, string $shuffle, string $reshuffle) : string
|
||||
{
|
||||
$shuffleEx = explode($shuffle, $str);
|
||||
|
||||
$newstr = '';
|
||||
|
||||
foreach( $shuffleEx as $v )
|
||||
{
|
||||
$newstr .= str_replace($reshuffle, $shuffle, $v).$reshuffle;
|
||||
}
|
||||
|
||||
return substr($newstr, 0, -strlen($reshuffle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Placement
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $delimiter
|
||||
* @param array $array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function placement(string $str, string $delimiter, array $array) : string
|
||||
{
|
||||
if( ! empty($delimiter) )
|
||||
{
|
||||
$strex = explode($delimiter, $str);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
if( (count($strex) - 1) !== count($array) )
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
$newstr = '';
|
||||
|
||||
for( $i = 0; $i < count($array); $i++ )
|
||||
{
|
||||
$newstr .= $strex[$i].$array[$i];
|
||||
}
|
||||
|
||||
return $newstr.$strex[count($array)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace
|
||||
*
|
||||
* @param string $string
|
||||
* @param mixed $oldChar
|
||||
* @param mixed $newChar
|
||||
* @param bool $case = true
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function replace(string $string, $oldChar, $newChar = NULL, bool $case = true) : string
|
||||
{
|
||||
if( $case === true )
|
||||
{
|
||||
$function = 'str_replace';
|
||||
}
|
||||
else
|
||||
{
|
||||
$function = 'str_ireplace';
|
||||
}
|
||||
|
||||
return $function($oldChar ?? '', $newChar ?? '', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeat Complate
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $completeCount
|
||||
* @param string $completeSymbol = '0'
|
||||
* @param string $direction = 'left' - options[left|right]
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function repeatComplete(string $string, int $completeCount, string $completeSymbol = '0', string $direction = 'left') : string
|
||||
{
|
||||
$length = strlen($string);
|
||||
|
||||
$diff = $completeCount - $length;
|
||||
|
||||
if( $direction === 'left' )
|
||||
{
|
||||
$end = $string;
|
||||
}
|
||||
else
|
||||
{
|
||||
$start = $string;
|
||||
}
|
||||
|
||||
if( $diff > 0 )
|
||||
{
|
||||
$fix = str_repeat($completeSymbol, $diff);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fix = '';
|
||||
}
|
||||
|
||||
return $start . $fix . $end;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php namespace ZN\DataTypes\Strings;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
|
||||
class Trim
|
||||
{
|
||||
/**
|
||||
* Middle
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function middle(string $str) : string
|
||||
{
|
||||
$str = preg_replace
|
||||
(
|
||||
['/\s+/', '/ /', "/\n/", "/\r/", "/\t/"],
|
||||
['', '', '', '', ''],
|
||||
$str
|
||||
);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Slashes
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function slashes(string $str) : string
|
||||
{
|
||||
$str = trim($str, "/");
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an expression in begin of a string.,
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removePrefix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
return Base::removePrefix($data, $fix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an expression in begin of a string.,
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removeSuffix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
return Base::removeSuffix($data, $fix);
|
||||
}
|
||||
|
||||
/**
|
||||
* It removes an expression from both sides of a string.
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function removePresuffix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
return Base::removePresuffix($data, $fix);
|
||||
}
|
||||
|
||||
/**
|
||||
* suffix
|
||||
*
|
||||
* It is used to append a suffix to any string.
|
||||
*
|
||||
* @param string = NULL
|
||||
* @param string = $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function suffix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
return Base::suffix($data, $fix);
|
||||
}
|
||||
|
||||
/**
|
||||
* prefix
|
||||
*
|
||||
* It is used to append a prefix to any string.
|
||||
*
|
||||
* @param string = NULL
|
||||
* @param string = $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function prefix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
return Base::prefix($data, $fix);
|
||||
}
|
||||
|
||||
/**
|
||||
* prefix
|
||||
*
|
||||
* Used to append both suffixes and prefixes to any string.
|
||||
*
|
||||
* @param string = NULL
|
||||
* @param string = $fix = '/'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function presuffix(?string $data = NULL, string $fix = '/') : string
|
||||
{
|
||||
return Base::presuffix($data, $fix);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user