seeder-migration-issues

This commit is contained in:
RafficMohammed
2023-01-30 14:23:34 +05:30
parent 4d918c722f
commit 2ec836b447
3628 changed files with 116006 additions and 187 deletions

View File

@@ -0,0 +1,269 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Stdlib\StringWrapper;
use Zend\Stdlib\Exception;
use Zend\Stdlib\StringUtils;
abstract class AbstractStringWrapper implements StringWrapperInterface
{
/**
* The character encoding working on
* @var string|null
*/
protected $encoding = 'UTF-8';
/**
* An optionally character encoding to convert to
* @var string|null
*/
protected $convertEncoding;
/**
* Check if the given character encoding is supported by this wrapper
* and the character encoding to convert to is also supported.
*
* @param string $encoding
* @param string|null $convertEncoding
* @return bool
*/
public static function isSupported($encoding, $convertEncoding = null)
{
$supportedEncodings = static::getSupportedEncodings();
if (!in_array(strtoupper($encoding), $supportedEncodings)) {
return false;
}
if ($convertEncoding !== null && !in_array(strtoupper($convertEncoding), $supportedEncodings)) {
return false;
}
return true;
}
/**
* Set character encoding working with and convert to
*
* @param string $encoding The character encoding to work with
* @param string|null $convertEncoding The character encoding to convert to
* @return StringWrapperInterface
*/
public function setEncoding($encoding, $convertEncoding = null)
{
$supportedEncodings = static::getSupportedEncodings();
$encodingUpper = strtoupper($encoding);
if (!in_array($encodingUpper, $supportedEncodings)) {
throw new Exception\InvalidArgumentException(
'Wrapper doesn\'t support character encoding "' . $encoding . '"'
);
}
if ($convertEncoding !== null) {
$convertEncodingUpper = strtoupper($convertEncoding);
if (!in_array($convertEncodingUpper, $supportedEncodings)) {
throw new Exception\InvalidArgumentException(
'Wrapper doesn\'t support character encoding "' . $convertEncoding . '"'
);
}
$this->convertEncoding = $convertEncodingUpper;
} else {
$this->convertEncoding = null;
}
$this->encoding = $encodingUpper;
return $this;
}
/**
* Get the defined character encoding to work with
*
* @return string
* @throws Exception\LogicException If no encoding was defined
*/
public function getEncoding()
{
return $this->encoding;
}
/**
* Get the defined character encoding to convert to
*
* @return string|null
*/
public function getConvertEncoding()
{
return $this->convertEncoding;
}
/**
* Convert a string from defined character encoding to the defined convert encoding
*
* @param string $str
* @param bool $reverse
* @return string|false
*/
public function convert($str, $reverse = false)
{
$encoding = $this->getEncoding();
$convertEncoding = $this->getConvertEncoding();
if ($convertEncoding === null) {
throw new Exception\LogicException(
'No convert encoding defined'
);
}
if ($encoding === $convertEncoding) {
return $str;
}
$from = $reverse ? $convertEncoding : $encoding;
$to = $reverse ? $encoding : $convertEncoding;
throw new Exception\RuntimeException(sprintf(
'Converting from "%s" to "%s" isn\'t supported by this string wrapper',
$from,
$to
));
}
/**
* Wraps a string to a given number of characters
*
* @param string $string
* @param int $width
* @param string $break
* @param bool $cut
* @return string|false
*/
public function wordWrap($string, $width = 75, $break = "\n", $cut = false)
{
$string = (string) $string;
if ($string === '') {
return '';
}
$break = (string) $break;
if ($break === '') {
throw new Exception\InvalidArgumentException('Break string cannot be empty');
}
$width = (int) $width;
if ($width === 0 && $cut) {
throw new Exception\InvalidArgumentException('Cannot force cut when width is zero');
}
if (StringUtils::isSingleByteEncoding($this->getEncoding())) {
return wordwrap($string, $width, $break, $cut);
}
$stringWidth = $this->strlen($string);
$breakWidth = $this->strlen($break);
$result = '';
$lastStart = $lastSpace = 0;
for ($current = 0; $current < $stringWidth; $current++) {
$char = $this->substr($string, $current, 1);
$possibleBreak = $char;
if ($breakWidth !== 1) {
$possibleBreak = $this->substr($string, $current, $breakWidth);
}
if ($possibleBreak === $break) {
$result .= $this->substr($string, $lastStart, $current - $lastStart + $breakWidth);
$current += $breakWidth - 1;
$lastStart = $lastSpace = $current + 1;
continue;
}
if ($char === ' ') {
if ($current - $lastStart >= $width) {
$result .= $this->substr($string, $lastStart, $current - $lastStart) . $break;
$lastStart = $current + 1;
}
$lastSpace = $current;
continue;
}
if ($current - $lastStart >= $width && $cut && $lastStart >= $lastSpace) {
$result .= $this->substr($string, $lastStart, $current - $lastStart) . $break;
$lastStart = $lastSpace = $current;
continue;
}
if ($current - $lastStart >= $width && $lastStart < $lastSpace) {
$result .= $this->substr($string, $lastStart, $lastSpace - $lastStart) . $break;
$lastStart = $lastSpace = $lastSpace + 1;
continue;
}
}
if ($lastStart !== $current) {
$result .= $this->substr($string, $lastStart, $current - $lastStart);
}
return $result;
}
/**
* Pad a string to a certain length with another string
*
* @param string $input
* @param int $padLength
* @param string $padString
* @param int $padType
* @return string
*/
public function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT)
{
if (StringUtils::isSingleByteEncoding($this->getEncoding())) {
return str_pad($input, $padLength, $padString, $padType);
}
$lengthOfPadding = $padLength - $this->strlen($input);
if ($lengthOfPadding <= 0) {
return $input;
}
$padStringLength = $this->strlen($padString);
if ($padStringLength === 0) {
return $input;
}
$repeatCount = floor($lengthOfPadding / $padStringLength);
if ($padType === STR_PAD_BOTH) {
$repeatCountLeft = $repeatCountRight = ($repeatCount - $repeatCount % 2) / 2;
$lastStringLength = $lengthOfPadding - 2 * $repeatCountLeft * $padStringLength;
$lastStringLeftLength = $lastStringRightLength = floor($lastStringLength / 2);
$lastStringRightLength += $lastStringLength % 2;
$lastStringLeft = $this->substr($padString, 0, $lastStringLeftLength);
$lastStringRight = $this->substr($padString, 0, $lastStringRightLength);
return str_repeat($padString, $repeatCountLeft) . $lastStringLeft
. $input
. str_repeat($padString, $repeatCountRight) . $lastStringRight;
}
$lastString = $this->substr($padString, 0, $lengthOfPadding % $padStringLength);
if ($padType === STR_PAD_LEFT) {
return str_repeat($padString, $repeatCount) . $lastString . $input;
}
return $input . str_repeat($padString, $repeatCount) . $lastString;
}
}

View File

@@ -0,0 +1,289 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Stdlib\StringWrapper;
use Zend\Stdlib\Exception;
class Iconv extends AbstractStringWrapper
{
/**
* List of supported character sets (upper case)
*
* @var string[]
* @link http://www.gnu.org/software/libiconv/
*/
protected static $encodings = [
// European languages
'ASCII',
'ISO-8859-1',
'ISO-8859-2',
'ISO-8859-3',
'ISO-8859-4',
'ISO-8859-5',
'ISO-8859-7',
'ISO-8859-9',
'ISO-8859-10',
'ISO-8859-13',
'ISO-8859-14',
'ISO-8859-15',
'ISO-8859-16',
'KOI8-R',
'KOI8-U',
'KOI8-RU',
'CP1250',
'CP1251',
'CP1252',
'CP1253',
'CP1254',
'CP1257',
'CP850',
'CP866',
'CP1131',
'MACROMAN',
'MACCENTRALEUROPE',
'MACICELAND',
'MACCROATIAN',
'MACROMANIA',
'MACCYRILLIC',
'MACUKRAINE',
'MACGREEK',
'MACTURKISH',
'MACINTOSH',
// Semitic languages
'ISO-8859-6',
'ISO-8859-8',
'CP1255',
'CP1256',
'CP862',
'MACHEBREW',
'MACARABIC',
// Japanese
'EUC-JP',
'SHIFT_JIS',
'CP932',
'ISO-2022-JP',
'ISO-2022-JP-2',
'ISO-2022-JP-1',
// Chinese
'EUC-CN',
'HZ',
'GBK',
'CP936',
'GB18030',
'EUC-TW',
'BIG5',
'CP950',
'BIG5-HKSCS',
'BIG5-HKSCS:2004',
'BIG5-HKSCS:2001',
'BIG5-HKSCS:1999',
'ISO-2022-CN',
'ISO-2022-CN-EXT',
// Korean
'EUC-KR',
'CP949',
'ISO-2022-KR',
'JOHAB',
// Armenian
'ARMSCII-8',
// Georgian
'GEORGIAN-ACADEMY',
'GEORGIAN-PS',
// Tajik
'KOI8-T',
// Kazakh
'PT154',
'RK1048',
// Thai
'ISO-8859-11',
'TIS-620',
'CP874',
'MACTHAI',
// Laotian
'MULELAO-1',
'CP1133',
// Vietnamese
'VISCII',
'TCVN',
'CP1258',
// Platform specifics
'HP-ROMAN8',
'NEXTSTEP',
// Full Unicode
'UTF-8',
'UCS-2',
'UCS-2BE',
'UCS-2LE',
'UCS-4',
'UCS-4BE',
'UCS-4LE',
'UTF-16',
'UTF-16BE',
'UTF-16LE',
'UTF-32',
'UTF-32BE',
'UTF-32LE',
'UTF-7',
'C99',
'JAVA',
/* Commented out because that's internal encodings not existing in real world
// Full Unicode, in terms of uint16_t or uint32_t (with machine dependent endianness and alignment)
'UCS-2-INTERNAL',
'UCS-4-INTERNAL',
// Locale dependent, in terms of `char' or `wchar_t' (with machine dependent endianness and alignment,
// and with OS and locale dependent semantics)
'char',
'wchar_t',
'', // The empty encoding name is equivalent to "char": it denotes the locale dependent character encoding.
*/
// When configured with the option --enable-extra-encodings,
// it also provides support for a few extra encodings:
// European languages
'CP437',
'CP737',
'CP775',
'CP852',
'CP853',
'CP855',
'CP857',
'CP858',
'CP860',
'CP861',
'CP863',
'CP865',
'CP869',
'CP1125',
// Semitic languages
'CP864',
// Japanese
'EUC-JISX0213',
'Shift_JISX0213',
'ISO-2022-JP-3',
// Chinese
'BIG5-2003', // (experimental)
// Turkmen
'TDS565',
// Platform specifics
'ATARIST',
'RISCOS-LATIN1',
];
/**
* Get a list of supported character encodings
*
* @return string[]
*/
public static function getSupportedEncodings()
{
return static::$encodings;
}
/**
* Constructor
*
* @throws Exception\ExtensionNotLoadedException
*/
public function __construct()
{
if (!extension_loaded('iconv')) {
throw new Exception\ExtensionNotLoadedException(
'PHP extension "iconv" is required for this wrapper'
);
}
}
/**
* Returns the length of the given string
*
* @param string $str
* @return int|false
*/
public function strlen($str)
{
return iconv_strlen($str, $this->getEncoding());
}
/**
* Returns the portion of string specified by the start and length parameters
*
* @param string $str
* @param int $offset
* @param int|null $length
* @return string|false
*/
public function substr($str, $offset = 0, $length = null)
{
return iconv_substr($str, $offset, $length, $this->getEncoding());
}
/**
* Find the position of the first occurrence of a substring in a string
*
* @param string $haystack
* @param string $needle
* @param int $offset
* @return int|false
*/
public function strpos($haystack, $needle, $offset = 0)
{
return iconv_strpos($haystack, $needle, $offset, $this->getEncoding());
}
/**
* Convert a string from defined encoding to the defined convert encoding
*
* @param string $str
* @param bool $reverse
* @return string|false
*/
public function convert($str, $reverse = false)
{
$encoding = $this->getEncoding();
$convertEncoding = $this->getConvertEncoding();
if ($convertEncoding === null) {
throw new Exception\LogicException(
'No convert encoding defined'
);
}
if ($encoding === $convertEncoding) {
return $str;
}
$fromEncoding = $reverse ? $convertEncoding : $encoding;
$toEncoding = $reverse ? $encoding : $convertEncoding;
// automatically add "//IGNORE" to not stop converting on invalid characters
// invalid characters triggers a notice anyway
return iconv($fromEncoding, $toEncoding . '//IGNORE', $str);
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Stdlib\StringWrapper;
use Zend\Stdlib\Exception;
class Intl extends AbstractStringWrapper
{
/**
* List of supported character sets (upper case)
*
* @var string[]
*/
protected static $encodings = ['UTF-8'];
/**
* Get a list of supported character encodings
*
* @return string[]
*/
public static function getSupportedEncodings()
{
return static::$encodings;
}
/**
* Constructor
*
* @throws Exception\ExtensionNotLoadedException
*/
public function __construct()
{
if (!extension_loaded('intl')) {
throw new Exception\ExtensionNotLoadedException(
'PHP extension "intl" is required for this wrapper'
);
}
}
/**
* Returns the length of the given string
*
* @param string $str
* @return int|false
*/
public function strlen($str)
{
return grapheme_strlen($str);
}
/**
* Returns the portion of string specified by the start and length parameters
*
* @param string $str
* @param int $offset
* @param int|null $length
* @return string|false
*/
public function substr($str, $offset = 0, $length = null)
{
// Due fix of PHP #62759 The third argument returns an empty string if is 0 or null.
if ($length !== null) {
return grapheme_substr($str, $offset, $length);
}
return grapheme_substr($str, $offset);
}
/**
* Find the position of the first occurrence of a substring in a string
*
* @param string $haystack
* @param string $needle
* @param int $offset
* @return int|false
*/
public function strpos($haystack, $needle, $offset = 0)
{
return grapheme_strpos($haystack, $needle, $offset);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Stdlib\StringWrapper;
use Zend\Stdlib\Exception;
class MbString extends AbstractStringWrapper
{
/**
* List of supported character sets (upper case)
*
* @var null|string[]
* @link http://php.net/manual/mbstring.supported-encodings.php
*/
protected static $encodings = null;
/**
* Get a list of supported character encodings
*
* @return string[]
*/
public static function getSupportedEncodings()
{
if (static::$encodings === null) {
static::$encodings = array_map('strtoupper', mb_list_encodings());
// FIXME: Converting € (UTF-8) to ISO-8859-16 gives a wrong result
$indexIso885916 = array_search('ISO-8859-16', static::$encodings, true);
if ($indexIso885916 !== false) {
unset(static::$encodings[$indexIso885916]);
}
}
return static::$encodings;
}
/**
* Constructor
*
* @throws Exception\ExtensionNotLoadedException
*/
public function __construct()
{
if (!extension_loaded('mbstring')) {
throw new Exception\ExtensionNotLoadedException(
'PHP extension "mbstring" is required for this wrapper'
);
}
}
/**
* Returns the length of the given string
*
* @param string $str
* @return int|false
*/
public function strlen($str)
{
return mb_strlen($str, $this->getEncoding());
}
/**
* Returns the portion of string specified by the start and length parameters
*
* @param string $str
* @param int $offset
* @param int|null $length
* @return string|false
*/
public function substr($str, $offset = 0, $length = null)
{
return mb_substr($str, $offset, $length, $this->getEncoding());
}
/**
* Find the position of the first occurrence of a substring in a string
*
* @param string $haystack
* @param string $needle
* @param int $offset
* @return int|false
*/
public function strpos($haystack, $needle, $offset = 0)
{
return mb_strpos($haystack, $needle, $offset, $this->getEncoding());
}
/**
* Convert a string from defined encoding to the defined convert encoding
*
* @param string $str
* @param bool $reverse
* @return string|false
*/
public function convert($str, $reverse = false)
{
$encoding = $this->getEncoding();
$convertEncoding = $this->getConvertEncoding();
if ($convertEncoding === null) {
throw new Exception\LogicException(
'No convert encoding defined'
);
}
if ($encoding === $convertEncoding) {
return $str;
}
$fromEncoding = $reverse ? $convertEncoding : $encoding;
$toEncoding = $reverse ? $encoding : $convertEncoding;
return mb_convert_encoding($str, $toEncoding, $fromEncoding);
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Stdlib\StringWrapper;
use Zend\Stdlib\Exception;
use Zend\Stdlib\StringUtils;
class Native extends AbstractStringWrapper
{
/**
* The character encoding working on
* (overwritten to change defaut encoding)
*
* @var string
*/
protected $encoding = 'ASCII';
/**
* Check if the given character encoding is supported by this wrapper
* and the character encoding to convert to is also supported.
*
* @param string $encoding
* @param string|null $convertEncoding
* @return bool
*/
public static function isSupported($encoding, $convertEncoding = null)
{
$encodingUpper = strtoupper($encoding);
$supportedEncodings = static::getSupportedEncodings();
if (!in_array($encodingUpper, $supportedEncodings)) {
return false;
}
// This adapter doesn't support to convert between encodings
if ($convertEncoding !== null && $encodingUpper !== strtoupper($convertEncoding)) {
return false;
}
return true;
}
/**
* Get a list of supported character encodings
*
* @return string[]
*/
public static function getSupportedEncodings()
{
return StringUtils::getSingleByteEncodings();
}
/**
* Set character encoding working with and convert to
*
* @param string $encoding The character encoding to work with
* @param string|null $convertEncoding The character encoding to convert to
* @return StringWrapperInterface
*/
public function setEncoding($encoding, $convertEncoding = null)
{
$supportedEncodings = static::getSupportedEncodings();
$encodingUpper = strtoupper($encoding);
if (!in_array($encodingUpper, $supportedEncodings)) {
throw new Exception\InvalidArgumentException(
'Wrapper doesn\'t support character encoding "' . $encoding . '"'
);
}
if ($encodingUpper !== strtoupper($convertEncoding)) {
$this->convertEncoding = $encodingUpper;
}
if ($convertEncoding !== null) {
if ($encodingUpper !== strtoupper($convertEncoding)) {
throw new Exception\InvalidArgumentException(
'Wrapper doesn\'t support to convert between character encodings'
);
}
$this->convertEncoding = $encodingUpper;
} else {
$this->convertEncoding = null;
}
$this->encoding = $encodingUpper;
return $this;
}
/**
* Returns the length of the given string
*
* @param string $str
* @return int|false
*/
public function strlen($str)
{
return strlen($str);
}
/**
* Returns the portion of string specified by the start and length parameters
*
* @param string $str
* @param int $offset
* @param int|null $length
* @return string|false
*/
public function substr($str, $offset = 0, $length = null)
{
return substr($str, $offset, $length);
}
/**
* Find the position of the first occurrence of a substring in a string
*
* @param string $haystack
* @param string $needle
* @param int $offset
* @return int|false
*/
public function strpos($haystack, $needle, $offset = 0)
{
return strpos($haystack, $needle, $offset);
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Stdlib\StringWrapper;
interface StringWrapperInterface
{
/**
* Check if the given character encoding is supported by this wrapper
* and the character encoding to convert to is also supported.
*
* @param string $encoding
* @param string|null $convertEncoding
*/
public static function isSupported($encoding, $convertEncoding = null);
/**
* Get a list of supported character encodings
*
* @return string[]
*/
public static function getSupportedEncodings();
/**
* Set character encoding working with and convert to
*
* @param string $encoding The character encoding to work with
* @param string|null $convertEncoding The character encoding to convert to
* @return StringWrapperInterface
*/
public function setEncoding($encoding, $convertEncoding = null);
/**
* Get the defined character encoding to work with (upper case)
*
* @return string
*/
public function getEncoding();
/**
* Get the defined character encoding to convert to (upper case)
*
* @return string|null
*/
public function getConvertEncoding();
/**
* Returns the length of the given string
*
* @param string $str
* @return int|false
*/
public function strlen($str);
/**
* Returns the portion of string specified by the start and length parameters
*
* @param string $str
* @param int $offset
* @param int|null $length
* @return string|false
*/
public function substr($str, $offset = 0, $length = null);
/**
* Find the position of the first occurrence of a substring in a string
*
* @param string $haystack
* @param string $needle
* @param int $offset
* @return int|false
*/
public function strpos($haystack, $needle, $offset = 0);
/**
* Convert a string from defined encoding to the defined convert encoding
*
* @param string $str
* @param bool $reverse
* @return string|false
*/
public function convert($str, $reverse = false);
/**
* Wraps a string to a given number of characters
*
* @param string $str
* @param int $width
* @param string $break
* @param bool $cut
* @return string
*/
public function wordWrap($str, $width = 75, $break = "\n", $cut = false);
/**
* Pad a string to a certain length with another string
*
* @param string $input
* @param int $padLength
* @param string $padString
* @param int $padType
* @return string
*/
public function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT);
}