当前位置: 首页>>代码示例>>PHP>>正文


PHP StringUtils::getWrapper方法代码示例

本文整理汇总了PHP中Zend\Stdlib\StringUtils::getWrapper方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtils::getWrapper方法的具体用法?PHP StringUtils::getWrapper怎么用?PHP StringUtils::getWrapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Stdlib\StringUtils的用法示例。


在下文中一共展示了StringUtils::getWrapper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getUtf8StringWrapper

 /**
  * Get the string wrapper supporting UTF-8 character encoding
  *
  * @return StringWrapperInterface
  */
 public function getUtf8StringWrapper()
 {
     if (!$this->utf8StringWrapper) {
         $this->utf8StringWrapper = StringUtils::getWrapper('UTF-8');
     }
     return $this->utf8StringWrapper;
 }
开发者ID:Flesh192,项目名称:magento,代码行数:12,代码来源:Code128.php

示例2: validateLength

 /**
  * Validator callback for new group name - check length if necessary
  *
  * @param string $value
  * @param array $context
  * @param integer $min
  * @param integer $max
  * @return bool
  * @internal
  */
 public function validateLength($value, $context, $min, $max)
 {
     if ($context['Where'] == 'new') {
         $length = \Zend\Stdlib\StringUtils::getWrapper('UTF-8')->strlen($value);
         $result = ($length >= $min and $length <= $max);
     } else {
         $result = true;
         // Field is ignored for existing groups
     }
     return $result;
 }
开发者ID:hschletz,项目名称:braintacle,代码行数:21,代码来源:AddToGroup.php

示例3: getWrapper

 /**
  * Get string wrapper
  *
  * @param string $encoding
  *
  * @return StringWrapperInterface
  */
 public function getWrapper($encoding = '')
 {
     $encoding = strtoupper($encoding ?: Pi::config('charset'));
     if (!isset($this->stringWrapper[$encoding])) {
         try {
             $stringWrapper = StringUtils::getWrapper(Pi::config('charset'));
         } catch (\Exception $e) {
             $stringWrapper = false;
         }
         $this->stringWrapper[$encoding] = $stringWrapper;
     }
     return $this->stringWrapper[$encoding];
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:20,代码来源:String.php

示例4: __construct

 /**
  * Constructor for the integer validator
  *
  * @param array|Traversable $options
  * @throws Exception\ExtensionNotLoadedException if ext/intl is not present
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('intl')) {
         throw new I18nException\ExtensionNotLoadedException(sprintf('%s component requires the intl PHP extension', __NAMESPACE__));
     }
     $this->wrapper = StringUtils::getWrapper();
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (array_key_exists('locale', $options)) {
         $this->setLocale($options['locale']);
     }
     parent::__construct($options);
 }
开发者ID:ErR163,项目名称:torrentpier,代码行数:20,代码来源:Float.php

示例5: testGetWrapper

 public function testGetWrapper()
 {
     $wrapper = StringUtils::getWrapper('ISO-8859-1');
     if (extension_loaded('mbstring')) {
         $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\MbString', $wrapper);
     } elseif (extension_loaded('iconv')) {
         $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\Iconv', $wrapper);
     } else {
         $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\Native', $wrapper);
     }
     try {
         $wrapper = StringUtils::getWrapper('UTF-8');
         if (extension_loaded('intl')) {
             $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\Intl', $wrapper);
         } elseif (extension_loaded('mbstring')) {
             $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\MbString', $wrapper);
         } elseif (extension_loaded('iconv')) {
             $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\Iconv', $wrapper);
         }
     } catch (Exception $e) {
         if (extension_loaded('intl') || extension_loaded('mbstring') || extension_loaded('iconv')) {
             $this->fail("Failed to get intl, mbstring or iconv wrapper for UTF-8");
         }
     }
     try {
         $wrapper = StringUtils::getWrapper('UTF-8', 'ISO-8859-1');
         if (extension_loaded('mbstring')) {
             $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\MbString', $wrapper);
         } elseif (extension_loaded('iconv')) {
             $this->assertInstanceOf('Zend\\Stdlib\\StringWrapper\\Iconv', $wrapper);
         }
     } catch (Exception $e) {
         if (extension_loaded('mbstring') || extension_loaded('iconv')) {
             $this->fail("Failed to get mbstring or iconv wrapper for UTF-8 and ISO-8859-1");
         }
     }
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:37,代码来源:StringUtilsTest.php

示例6: setEncoding

 /**
  * Set feed encoding
  *
  * @param  string $enc
  * @return Entry
  */
 public function setEncoding($enc)
 {
     $this->stringWrapper = StringUtils::getWrapper($enc);
     $this->encoding = $enc;
     return $this;
 }
开发者ID:totolouis,项目名称:ZF2-Auth,代码行数:12,代码来源:Entry.php

示例7: renderTable

 /**
  * Render a text table containing the data provided, that will fit inside console window's width.
  *
  * @param  $data
  * @param  $cols
  * @param  $consoleWidth
  * @return string
  */
 protected function renderTable($data, $cols, $consoleWidth)
 {
     $result = '';
     $padding = 2;
     // If there is only 1 column, just concatenate it
     if ($cols == 1) {
         foreach ($data as $row) {
             $result .= $row[0] . "\n";
         }
         return $result;
     }
     // Get the string wrapper supporting UTF-8 character encoding
     $strWrapper = StringUtils::getWrapper('UTF-8');
     // Determine max width for each column
     $maxW = array();
     for ($x = 1; $x <= $cols; $x += 1) {
         $maxW[$x] = 0;
         foreach ($data as $row) {
             $maxW[$x] = max($maxW[$x], $strWrapper->strlen($row[$x - 1]) + $padding * 2);
         }
     }
     /*
      * Check if the sum of x-1 columns fit inside console window width - 10
      * chars. If columns do not fit inside console window, then we'll just
      * concatenate them and output as is.
      */
     $width = 0;
     for ($x = 1; $x < $cols; $x += 1) {
         $width += $maxW[$x];
     }
     if ($width >= $consoleWidth - 10) {
         foreach ($data as $row) {
             $result .= implode("    ", $row) . "\n";
         }
         return $result;
     }
     /*
      * Use Zend\Text\Table to render the table.
      * The last column will use the remaining space in console window
      * (minus 1 character to prevent double wrapping at the edge of the
      * screen).
      */
     $maxW[$cols] = $consoleWidth - $width - 1;
     $table = new Table\Table();
     $table->setColumnWidths($maxW);
     $table->setDecorator(new Table\Decorator\Blank());
     $table->setPadding(2);
     foreach ($data as $row) {
         $table->appendRow($row);
     }
     return $table->render();
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:60,代码来源:RouteNotFoundStrategy.php

示例8: isValid

 /**
  * Defined by Interface
  *
  * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  *
  * @param  string $value
  * @return bool
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     // Check input against IP address schema
     if ((preg_match('/^[0-9.]*$/', $value) && strpos($value, '.') !== false || preg_match('/^[0-9a-f:.]*$/i', $value) && strpos($value, ':') !== false) && $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value)) {
         if (!($this->getAllow() & self::ALLOW_IP)) {
             $this->error(self::IP_ADDRESS_NOT_ALLOWED);
             return false;
         }
         return true;
     }
     // Local hostnames are allowed to be partial (ending '.')
     if ($this->getAllow() & self::ALLOW_LOCAL) {
         if (substr($value, -1) === '.') {
             $value = substr($value, 0, -1);
             if (substr($value, -1) === '.') {
                 // Empty hostnames (ending '..') are not allowed
                 $this->error(self::INVALID_LOCAL_NAME);
                 return false;
             }
         }
     }
     $domainParts = explode('.', $value);
     // Prevent partial IP V4 addresses (ending '.')
     if (count($domainParts) == 4 && preg_match('/^[0-9.a-e:.]*$/i', $value) && $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value)) {
         $this->error(self::INVALID_LOCAL_NAME);
     }
     $utf8StrWrapper = StringUtils::getWrapper('UTF-8');
     // Check input against DNS hostname schema
     if (count($domainParts) > 1 && $utf8StrWrapper->strlen($value) >= 4 && $utf8StrWrapper->strlen($value) <= 254) {
         $status = false;
         do {
             // First check TLD
             $matches = [];
             if (preg_match('/([^.]{2,63})$/u', end($domainParts), $matches) || array_key_exists(end($domainParts), $this->validIdns)) {
                 reset($domainParts);
                 // Hostname characters are: *(label dot)(label dot label); max 254 chars
                 // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
                 // id-prefix: alpha / digit
                 // ldh: alpha / digit / dash
                 // Match TLD against known list
                 $this->tld = strtoupper($matches[1]);
                 if ($this->getTldCheck()) {
                     if (!in_array(strtolower($this->tld), $this->validTlds) && !in_array($this->tld, $this->validTlds)) {
                         $this->error(self::UNKNOWN_TLD);
                         $status = false;
                         break;
                     }
                     // We have already validated that the TLD is fine. We don't want it to go through the below
                     // checks as new UTF-8 TLDs will incorrectly fail if there is no IDN regex for it.
                     array_pop($domainParts);
                 }
                 /**
                  * Match against IDN hostnames
                  * Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
                  *
                  * @see Hostname\Interface
                  */
                 $regexChars = [0 => '/^[a-z0-9\\x2d]{1,63}$/i'];
                 if ($this->getIdnCheck() && isset($this->validIdns[$this->tld])) {
                     if (is_string($this->validIdns[$this->tld])) {
                         $regexChars += (include __DIR__ . '/' . $this->validIdns[$this->tld]);
                     } else {
                         $regexChars += $this->validIdns[$this->tld];
                     }
                 }
                 // Check each hostname part
                 $check = 0;
                 foreach ($domainParts as $domainPart) {
                     // Decode Punycode domain names to IDN
                     if (strpos($domainPart, 'xn--') === 0) {
                         $domainPart = $this->decodePunycode(substr($domainPart, 4));
                         if ($domainPart === false) {
                             return false;
                         }
                     }
                     // Check dash (-) does not start, end or appear in 3rd and 4th positions
                     if ($utf8StrWrapper->strpos($domainPart, '-') === 0 || $utf8StrWrapper->strlen($domainPart) > 2 && $utf8StrWrapper->strpos($domainPart, '-', 2) == 2 && $utf8StrWrapper->strpos($domainPart, '-', 3) == 3 || $utf8StrWrapper->strpos($domainPart, '-') === $utf8StrWrapper->strlen($domainPart) - 1) {
                         $this->error(self::INVALID_DASH);
                         $status = false;
                         break 2;
                     }
                     // Check each domain part
                     $checked = false;
                     foreach ($regexChars as $regexKey => $regexChar) {
                         $status = preg_match($regexChar, $domainPart);
                         if ($status > 0) {
                             $length = 63;
//.........这里部分代码省略.........
开发者ID:Alex--Jin,项目名称:homerapi,代码行数:101,代码来源:Hostname.php

示例9: writeBox

 /**
  * Write a box at the specified coordinates.
  * If X or Y coordinate value is negative, it will be calculated as the distance from far right or bottom edge
  * of the console (respectively).
  *
  * @param int      $x1           Top-left corner X coordinate (column)
  * @param int      $y1           Top-left corner Y coordinate (row)
  * @param int      $x2           Bottom-right corner X coordinate (column)
  * @param int      $y2           Bottom-right corner Y coordinate (row)
  * @param int      $lineStyle    (optional) Box border style.
  * @param int      $fillStyle    (optional) Box fill style or a single character to fill it with.
  * @param int      $color        (optional) Foreground color
  * @param int      $bgColor      (optional) Background color
  * @param null|int $fillColor    (optional) Foreground color of box fill
  * @param null|int $fillBgColor  (optional) Background color of box fill
  * @throws Exception\BadMethodCallException if coordinates are invalid
  */
 public function writeBox($x1, $y1, $x2, $y2, $lineStyle = self::LINE_SINGLE, $fillStyle = self::FILL_NONE, $color = null, $bgColor = null, $fillColor = null, $fillBgColor = null)
 {
     // Sanitize coordinates
     $x1 = (int) $x1;
     $y1 = (int) $y1;
     $x2 = (int) $x2;
     $y2 = (int) $y2;
     // Translate negative coordinates
     if ($x2 < 0) {
         $x2 = $this->getWidth() - $x2;
     }
     if ($y2 < 0) {
         $y2 = $this->getHeight() - $y2;
     }
     // Validate coordinates
     if ($x1 < 0 || $y1 < 0 || $x2 < $x1 || $y2 < $y1) {
         throw new Exception\BadMethodCallException('Supplied X,Y coordinates are invalid.');
     }
     // Determine charset and dimensions
     $charset = $this->getCharset();
     $width = $x2 - $x1 + 1;
     if ($width <= 2) {
         $lineStyle = static::LINE_NONE;
     }
     // Activate line drawing
     $this->write($charset::ACTIVATE);
     // Draw horizontal lines
     if ($lineStyle !== static::LINE_NONE) {
         switch ($lineStyle) {
             case static::LINE_SINGLE:
                 $lineChar = $charset::LINE_SINGLE_EW;
                 break;
             case static::LINE_DOUBLE:
                 $lineChar = $charset::LINE_DOUBLE_EW;
                 break;
             case static::LINE_BLOCK:
             default:
                 $lineChar = $charset::LINE_BLOCK_EW;
                 break;
         }
         $this->setPos($x1 + 1, $y1);
         $this->write(str_repeat($lineChar, $width - 2), $color, $bgColor);
         $this->setPos($x1 + 1, $y2);
         $this->write(str_repeat($lineChar, $width - 2), $color, $bgColor);
     }
     // Draw vertical lines and fill
     if (is_numeric($fillStyle) && $fillStyle !== static::FILL_NONE) {
         switch ($fillStyle) {
             case static::FILL_SHADE_LIGHT:
                 $fillChar = $charset::SHADE_LIGHT;
                 break;
             case static::FILL_SHADE_MEDIUM:
                 $fillChar = $charset::SHADE_MEDIUM;
                 break;
             case static::FILL_SHADE_DARK:
                 $fillChar = $charset::SHADE_DARK;
                 break;
             case static::FILL_BLOCK:
             default:
                 $fillChar = $charset::BLOCK;
                 break;
         }
     } elseif ($fillStyle) {
         $fillChar = StringUtils::getWrapper()->substr($fillStyle, 0, 1);
     } else {
         $fillChar = ' ';
     }
     if ($lineStyle === static::LINE_NONE) {
         for ($y = $y1; $y <= $y2; $y++) {
             $this->setPos($x1, $y);
             $this->write(str_repeat($fillChar, $width), $fillColor, $fillBgColor);
         }
     } else {
         switch ($lineStyle) {
             case static::LINE_DOUBLE:
                 $lineChar = $charset::LINE_DOUBLE_NS;
                 break;
             case static::LINE_BLOCK:
                 $lineChar = $charset::LINE_BLOCK_NS;
                 break;
             case static::LINE_SINGLE:
             default:
                 $lineChar = $charset::LINE_SINGLE_NS;
//.........这里部分代码省略.........
开发者ID:Flesh192,项目名称:magento,代码行数:101,代码来源:AbstractAdapter.php

示例10: strPad

 /**
  * String padding
  *
  * @param  string  $input
  * @param  int $padLength
  * @param  string  $padString
  * @param  int $padType
  * @param  string  $charset
  * @return string
  * @deprecated Please use Zend\Stdlib\StringUtils instead
  */
 public static function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT, $charset = 'utf-8')
 {
     trigger_error(sprintf("This method is deprecated, please use '%s' instead", 'Zend\\Stdlib\\StringUtils::getWrapper(<charset>)->strPad'), E_USER_DEPRECATED);
     return StringUtils::getWrapper($charset)->strPad($input, $padLength, $padString, $padType);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:16,代码来源:MultiByte.php

示例11: testMultibytePadFixedWidth

 /**
  * @group 6012
  */
 public function testMultibytePadFixedWidth()
 {
     $outputWidth = 50;
     $adapter = new ConsoleStub(array('width' => $outputWidth, 'elements' => array(Adapter\Console::ELEMENT_PERCENT, Adapter\Console::ELEMENT_BAR, Adapter\Console::ELEMENT_ETA, Adapter\Console::ELEMENT_TEXT)));
     $adapter->notify(21, 100, 0.21, 60, 60, '這是');
     $this->assertEquals(' 21% [##-------] ETA 00:01:00 這是                  ', $adapter->getLastOutput());
     $wrapper = StringUtils::getWrapper($adapter->getCharset());
     $this->assertEquals($outputWidth, $wrapper->strlen($adapter->getLastOutput()));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:12,代码来源:ConsoleTest.php

示例12: render

 /**
  * Render a FIGlet text
  *
  * @param  string $text     Text to convert to a figlet text
  * @param  string $encoding Encoding of the input string
  * @throws Exception\InvalidArgumentException When $text is not a string
  * @throws Exception\UnexpectedValueException When $text it not properly encoded
  * @return string
  */
 public function render($text, $encoding = 'UTF-8')
 {
     if (!is_string($text)) {
         throw new Exception\InvalidArgumentException('$text must be a string');
     }
     // Get the string wrapper supporting UTF-8 character encoding and the input encoding
     $strWrapper = StringUtils::getWrapper($encoding, 'UTF-8');
     // Convert $text to UTF-8 and check encoding
     $text = $strWrapper->convert($text);
     if (!StringUtils::isValidUtf8($text)) {
         throw new Exception\UnexpectedValueException('$text is not encoded with ' . $encoding);
     }
     $strWrapper = StringUtils::getWrapper('UTF-8');
     $this->output = '';
     $this->outputLine = array();
     $this->_clearLine();
     $this->outlineLengthLimit = $this->outputWidth - 1;
     $this->inCharLineLengthLimit = $this->outputWidth * 4 + 100;
     $wordBreakMode = 0;
     $lastCharWasEol = false;
     $textLength = $strWrapper->strlen($text);
     for ($charNum = 0; $charNum < $textLength; $charNum++) {
         // Handle paragraphs
         $char = $strWrapper->substr($text, $charNum, 1);
         if ($char === "\n" && $this->handleParagraphs && !$lastCharWasEol) {
             $nextChar = $strWrapper->substr($text, $charNum + 1, 1);
             if (!$nextChar) {
                 $nextChar = null;
             }
             $char = ctype_space($nextChar) ? "\n" : ' ';
         }
         $lastCharWasEol = ctype_space($char) && $char !== "\t" && $char !== ' ';
         if (ctype_space($char)) {
             $char = $char === "\t" || $char === ' ' ? ' ' : "\n";
         }
         // Skip unprintable characters
         $ordChar = $this->_uniOrd($char);
         if ($ordChar > 0 && $ordChar < 32 && $char !== "\n" || $ordChar === 127) {
             continue;
         }
         // Build the character
         // Note: The following code is complex and thoroughly tested.
         // Be careful when modifying!
         do {
             $charNotAdded = false;
             if ($wordBreakMode === -1) {
                 if ($char === ' ') {
                     break;
                 } elseif ($char === "\n") {
                     $wordBreakMode = 0;
                     break;
                 }
                 $wordBreakMode = 0;
             }
             if ($char === "\n") {
                 $this->_appendLine();
                 $wordBreakMode = false;
             } elseif ($this->_addChar($char)) {
                 if ($char !== ' ') {
                     $wordBreakMode = $wordBreakMode >= 2 ? 3 : 1;
                 } else {
                     $wordBreakMode = $wordBreakMode > 0 ? 2 : 0;
                 }
             } elseif ($this->outlineLength === 0) {
                 for ($i = 0; $i < $this->charHeight; $i++) {
                     if ($this->rightToLeft === 1 && $this->outputWidth > 1) {
                         $offset = strlen($this->currentChar[$i]) - $this->outlineLengthLimit;
                         $this->_putString(substr($this->currentChar[$i], $offset));
                     } else {
                         $this->_putString($this->currentChar[$i]);
                     }
                 }
                 $wordBreakMode = -1;
             } elseif ($char === ' ') {
                 if ($wordBreakMode === 2) {
                     $this->_splitLine();
                 } else {
                     $this->_appendLine();
                 }
                 $wordBreakMode = -1;
             } else {
                 if ($wordBreakMode >= 2) {
                     $this->_splitLine();
                 } else {
                     $this->_appendLine();
                 }
                 $wordBreakMode = $wordBreakMode === 3 ? 1 : 0;
                 $charNotAdded = true;
             }
         } while ($charNotAdded);
     }
//.........这里部分代码省略.........
开发者ID:eltonoliveira,项目名称:jenkins,代码行数:101,代码来源:Figlet.php

示例13: render

 /**
  * Render the column width the given column width
  *
  * @param  int $columnWidth The width of the column
  * @param  int $padding     The padding for the column
  * @throws Exception\InvalidArgumentException When $columnWidth is lower than 1
  * @throws Exception\OutOfBoundsException When padding is greater than columnWidth
  * @return string
  */
 public function render($columnWidth, $padding = 0)
 {
     if (is_int($columnWidth) === false or $columnWidth < 1) {
         throw new Exception\InvalidArgumentException('$columnWidth must be an integer and greater than 0');
     }
     $columnWidth -= $padding * 2;
     if ($columnWidth < 1) {
         throw new Exception\OutOfBoundsException('Padding (' . $padding . ') is greater than column width');
     }
     switch ($this->align) {
         case self::ALIGN_LEFT:
             $padMode = STR_PAD_RIGHT;
             break;
         case self::ALIGN_CENTER:
             $padMode = STR_PAD_BOTH;
             break;
         case self::ALIGN_RIGHT:
             $padMode = STR_PAD_LEFT;
             break;
         default:
             // This can never happen, but the CS tells I have to have it ...
             break;
     }
     $outputCharset = Table::getOutputCharset();
     $strWrapper = StringUtils::getWrapper($outputCharset);
     $lines = explode("\n", $strWrapper->wordWrap($this->content, $columnWidth, "\n", true));
     $paddedLines = array();
     foreach ($lines as $line) {
         $paddedLines[] = str_repeat(' ', $padding) . $strWrapper->strPad($line, $columnWidth, ' ', $padMode) . str_repeat(' ', $padding);
     }
     $result = implode("\n", $paddedLines);
     return $result;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:42,代码来源:Column.php

示例14: validateField

 /**
  * Validator callback
  *
  * @internal
  * @param string $value
  * @param array $context
  * @param string $type Field datatype
  * @return bool TRUE if $value is valid for given type
  */
 public function validateField($value, $context, $type)
 {
     switch ($type) {
         case 'text':
             $result = \Zend\Stdlib\StringUtils::getWrapper('UTF-8')->strlen($value) <= 255;
             break;
         case 'integer':
         case 'float':
         case 'date':
             $result = $this->validateType($value, $context, $type);
             break;
         default:
             $result = true;
     }
     return $result;
 }
开发者ID:hschletz,项目名称:braintacle,代码行数:25,代码来源:CustomFields.php

示例15: importCsv

 public function importCsv($csv, User $user, $bankCode)
 {
     if ($csv['error'] != 0) {
         throw new \InvalidArgumentException('System has errors with uploaded file');
     }
     if (!$user) {
         return;
     }
     $counts = array(0, 0);
     if (($handle = fopen($csv['tmp_name'], 'r')) !== false) {
         // 			fgets($handle, 4096);
         $data = fgets($handle, 4096);
         $delimiter = ',';
         if (count(explode(';', $data)) > 8) {
             $delimiter = ';';
         }
         rewind($handle);
         $data = fgetcsv($handle, 4096, $delimiter);
         if (in_array($data[0], array('Konto', 'Kliendi konto'))) {
             $data = fgetcsv($handle, 4096, $delimiter);
         }
         rewind($handle);
         while (($data = fgetcsv($handle, 4096, $delimiter)) !== false) {
             if (in_array($data[0], array('Konto', 'Kliendi konto'))) {
                 continue;
             }
             if ($bankCode == BankTransaction::BANK_KREDIIDIPANK) {
                 //valjavote.csv
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[14]));
                 $referenceNumber = trim($data[22]);
                 $sum = str_replace(',', '.', trim($data[3]));
                 $paymentDate = \DateTime::createFromFormat('d.m.Y', $data[0]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[21]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[1]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[16]));
             } elseif ($bankCode == BankTransaction::BANK_SEB) {
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[4]));
                 $referenceNumber = trim($data[9]);
                 $sum = str_replace(',', '.', (trim($data[7] == 'D') ? -1 : 1) * trim(str_replace(',', '.', $data[8])));
                 $paymentDate = \DateTime::createFromFormat('d.m.Y', $data[2]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[11]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[10]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[3]));
             } elseif ($bankCode == BankTransaction::BANK_SWED) {
                 //toimingud.csv
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[4]));
                 $referenceNumber = trim($data[9]);
                 $sum = str_replace(',', '.', trim($data[8]));
                 $paymentDate = \DateTime::createFromFormat('d-m-Y', $data[2]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[11]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[10]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[3]));
             } elseif ($bankCode == BankTransaction::BANK_NORDEA) {
                 $name = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[4]));
                 $referenceNumber = trim($data[7]);
                 $sum = str_replace(',', '.', (trim($data[5] == 'D') ? -1 : 1) * trim(str_replace(',', '.', $data[6])));
                 $paymentDate = \DateTime::createFromFormat('d.m.Y', $data[2]);
                 $description = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[9]));
                 $archiveSign = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[8]));
                 $payerIban = StringUtils::getWrapper('ISO-8859-1', 'UTF-8')->convert(trim($data[3]));
             }
             if ($name == null || $paymentDate === false) {
                 continue;
             }
             $paymentDate->setTime(0, 0, 0);
             if ($archiveSign !== null && $archiveSign !== '') {
                 $transaction = $this->entityManager->getRepository(BankTransaction::getClass())->findOneBy(array('name' => $name, 'referenceNumber' => $referenceNumber, 'sum' => $sum, 'paymentDate' => $paymentDate, 'description' => $description, 'archiveSign' => $archiveSign));
                 if ($transaction != null) {
                     continue;
                 }
             }
             $transaction = new BankTransaction();
             $transaction->setName($name);
             $transaction->setReferenceNumber($referenceNumber);
             $transaction->setSum($sum);
             $transaction->setType($sum < 0 ? BankTransaction::TYPE_OUTGOING : BankTransaction::TYPE_INCOMING);
             $transaction->setPaymentDate($paymentDate);
             $transaction->setDescription($description);
             $transaction->setArchiveSign($archiveSign);
             $transaction->setPayerIban($payerIban);
             $transaction->setPaymentType(BankTransaction::PAYMENT_TYPE_TRANSFER);
             $transaction->setUser($user);
             $this->saveTransaction($transaction);
             if ($sum > 0) {
                 $counts[1]++;
                 $this->autoAssociateIncoming($transaction);
             } else {
                 $counts[0]++;
             }
         }
         fclose($handle);
     }
     return $counts;
 }
开发者ID:kristjanAnd,项目名称:SimpleIV,代码行数:94,代码来源:BankService.php


注:本文中的Zend\Stdlib\StringUtils::getWrapper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。