Browse Source

Renamed String class to Text

String may become invalid class name on PHP 7+, so avoiding issues upfront.
Juan Basso 11 years ago
parent
commit
c7b1013f54

+ 3 - 0
config/bootstrap.php

@@ -15,4 +15,7 @@
 
 define('TIME_START', microtime(true));
 
+// @deprecated Backward compatibility with 2.x series
+class_alias('Cake\Utility\Text', 'Cake\Utility\String');
+
 require CAKE . 'basics.php';

+ 6 - 6
src/Console/HelpFormatter.php

@@ -14,7 +14,7 @@
  */
 namespace Cake\Console;
 
-use Cake\Utility\String;
+use Cake\Utility\Text;
 
 /**
  * HelpFormatter formats help for console shells. Can format to either
@@ -64,7 +64,7 @@ class HelpFormatter
         $out = [];
         $description = $parser->description();
         if (!empty($description)) {
-            $out[] = String::wrap($description, $width);
+            $out[] = Text::wrap($description, $width);
             $out[] = '';
         }
         $out[] = '<info>Usage:</info>';
@@ -76,7 +76,7 @@ class HelpFormatter
             $out[] = '';
             $max = $this->_getMaxLength($subcommands) + 2;
             foreach ($subcommands as $command) {
-                $out[] = String::wrap($command->help($max), [
+                $out[] = Text::wrap($command->help($max), [
                     'width' => $width,
                     'indent' => str_repeat(' ', $max),
                     'indentAt' => 1
@@ -93,7 +93,7 @@ class HelpFormatter
             $out[] = '<info>Options:</info>';
             $out[] = '';
             foreach ($options as $option) {
-                $out[] = String::wrap($option->help($max), [
+                $out[] = Text::wrap($option->help($max), [
                     'width' => $width,
                     'indent' => str_repeat(' ', $max),
                     'indentAt' => 1
@@ -108,7 +108,7 @@ class HelpFormatter
             $out[] = '<info>Arguments:</info>';
             $out[] = '';
             foreach ($arguments as $argument) {
-                $out[] = String::wrap($argument->help($max), [
+                $out[] = Text::wrap($argument->help($max), [
                     'width' => $width,
                     'indent' => str_repeat(' ', $max),
                     'indentAt' => 1
@@ -118,7 +118,7 @@ class HelpFormatter
         }
         $epilog = $parser->epilog();
         if (!empty($epilog)) {
-            $out[] = String::wrap($epilog, $width);
+            $out[] = Text::wrap($epilog, $width);
             $out[] = '';
         }
         return implode("\n", $out);

+ 3 - 3
src/Console/Shell.php

@@ -23,7 +23,7 @@ use Cake\Filesystem\File;
 use Cake\Log\LogTrait;
 use Cake\Utility\Inflector;
 use Cake\Utility\MergeVariablesTrait;
-use Cake\Utility\String;
+use Cake\Utility\Text;
 
 /**
  * Base class for command-line utilities for automating programmer chores.
@@ -490,12 +490,12 @@ class Shell
      * @param string $text Text the text to format.
      * @param int|array $options Array of options to use, or an integer to wrap the text to.
      * @return string Wrapped / indented text
-     * @see String::wrap()
+     * @see \Cake\Utility\Text::wrap()
      * @link http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::wrapText
      */
     public function wrapText($text, $options = [])
     {
-        return String::wrap($text, $options);
+        return Text::wrap($text, $options);
     }
 
     /**

+ 2 - 2
src/Controller/Component/CsrfComponent.php

@@ -20,7 +20,7 @@ use Cake\Network\Exception\ForbiddenException;
 use Cake\Network\Request;
 use Cake\Network\Response;
 use Cake\Utility\Security;
-use Cake\Utility\String;
+use Cake\Utility\Text;
 
 /**
  * Provides CSRF protection & validation.
@@ -120,7 +120,7 @@ class CsrfComponent extends Component
      */
     protected function _setCookie(Request $request, Response $response)
     {
-        $value = Security::hash(String::uuid(), 'sha1', true);
+        $value = Security::hash(Text::uuid(), 'sha1', true);
         $request->params['_csrfToken'] = $value;
         $response->cookie([
             'name' => $this->_config['cookieName'],

+ 2 - 2
src/Database/Type/UuidType.php

@@ -15,7 +15,7 @@
 namespace Cake\Database\Type;
 
 use Cake\Database\Driver;
-use Cake\Utility\String;
+use Cake\Utility\Text;
 use PDO;
 
 /**
@@ -76,6 +76,6 @@ class UuidType extends \Cake\Database\Type
      */
     public function newId()
     {
-        return String::uuid();
+        return Text::uuid();
     }
 }

+ 6 - 6
src/Error/Debugger.php

@@ -17,7 +17,7 @@ namespace Cake\Error;
 use Cake\Log\Log;
 use Cake\Utility\Hash;
 use Cake\Utility\Security;
-use Cake\Utility\String;
+use Cake\Utility\Text;
 use Exception;
 use InvalidArgumentException;
 
@@ -272,7 +272,7 @@ class Debugger
                 $trace['path'] = static::trimPath($trace['file']);
                 $trace['reference'] = $reference;
                 unset($trace['object'], $trace['args']);
-                $back[] = String::insert($tpl, $trace, ['before' => '{:', 'after' => '}']);
+                $back[] = Text::insert($tpl, $trace, ['before' => '{:', 'after' => '}']);
             }
         }
 
@@ -577,7 +577,7 @@ class Debugger
      *
      * `Debugger::addFormat('custom', $data);`
      *
-     * Where $data is an array of strings that use String::insert() variable
+     * Where $data is an array of strings that use Text::insert() variable
      * replacement. The template vars should be in a `{:id}` style.
      * An error formatter can have the following keys:
      *
@@ -685,7 +685,7 @@ class Debugger
 
         if (isset($tpl['links'])) {
             foreach ($tpl['links'] as $key => $val) {
-                $links[$key] = String::insert($val, $data, $insertOpts);
+                $links[$key] = Text::insert($val, $data, $insertOpts);
             }
         }
 
@@ -701,14 +701,14 @@ class Debugger
             if (is_array($value)) {
                 $value = implode("\n", $value);
             }
-            $info .= String::insert($tpl[$key], [$key => $value] + $data, $insertOpts);
+            $info .= Text::insert($tpl[$key], [$key => $value] + $data, $insertOpts);
         }
         $links = implode(' ', $links);
 
         if (isset($tpl['callback']) && is_callable($tpl['callback'])) {
             return call_user_func($tpl['callback'], $data, compact('links', 'info'));
         }
-        echo String::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts);
+        echo Text::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts);
     }
 
     /**

+ 2 - 2
src/Log/Engine/FileLog.php

@@ -16,7 +16,7 @@ namespace Cake\Log\Engine;
 
 use Cake\Core\Configure;
 use Cake\Log\Engine\BaseLog;
-use Cake\Utility\String;
+use Cake\Utility\Text;
 
 /**
  * File Storage stream for Logging. Writes logs to different files
@@ -106,7 +106,7 @@ class FileLog extends BaseLog
             if (is_numeric($this->_config['size'])) {
                 $this->_size = (int)$this->_config['size'];
             } else {
-                $this->_size = String::parseFileSize($this->_config['size']);
+                $this->_size = Text::parseFileSize($this->_config['size']);
             }
         }
     }

+ 2 - 2
src/Network/Email/Email.php

@@ -22,7 +22,7 @@ use Cake\Filesystem\File;
 use Cake\Log\Log;
 use Cake\Network\Http\FormData\Part;
 use Cake\Utility\Hash;
-use Cake\Utility\String;
+use Cake\Utility\Text;
 use InvalidArgumentException;
 use LogicException;
 
@@ -809,7 +809,7 @@ class Email
         }
         if ($this->_messageId !== false) {
             if ($this->_messageId === true) {
-                $headers['Message-ID'] = '<' . str_replace('-', '', String::UUID()) . '@' . $this->_domain . '>';
+                $headers['Message-ID'] = '<' . str_replace('-', '', Text::uuid()) . '@' . $this->_domain . '>';
             } else {
                 $headers['Message-ID'] = $this->_messageId;
             }

+ 3 - 3
src/Utility/Hash.php

@@ -125,7 +125,7 @@ class Hash
             }
             $tokens = explode('.', $path);
         } else {
-            $tokens = String::tokenize($path, '.', '[', ']');
+            $tokens = Text::tokenize($path, '.', '[', ']');
         }
 
         $_key = '__set_item__';
@@ -282,7 +282,7 @@ class Hash
         if ($noTokens) {
             $tokens = explode('.', $path);
         } else {
-            $tokens = String::tokenize($path, '.', '[', ']');
+            $tokens = Text::tokenize($path, '.', '[', ']');
         }
 
         if ($noTokens && strpos($path, '{') === false) {
@@ -374,7 +374,7 @@ class Hash
             return $data;
         }
 
-        $tokens = $noTokens ? explode('.', $path) : String::tokenize($path, '.', '[', ']');
+        $tokens = $noTokens ? explode('.', $path) : Text::tokenize($path, '.', '[', ']');
 
         if ($noExpansion && $noTokens) {
             return static::_simpleOp('remove', $data, $tokens);

+ 2 - 2
src/Utility/README.md

@@ -40,14 +40,14 @@ Check the [official Inflector class documentation](http://book.cakephp.org/3.0/e
 The String class includes convenience methods for creating and manipulating strings.
 
 ```php
-String::insert(
+Text::insert(
     'My name is :name and I am :age years old.',
     ['name' => 'Bob', 'age' => '65']
 );
 // Returns: "My name is Bob and I am 65 years old."
 
 $text = 'This is the song that never ends.';
-$result = String::wrap($text, 22);
+$result = Text::wrap($text, 22);
 
 // Returns
 This is the song

+ 1 - 1
src/Utility/Security.php

@@ -54,7 +54,7 @@ class Security
      */
     public static function generateAuthKey()
     {
-        return Security::hash(String::uuid());
+        return Security::hash(Text::uuid());
     }
 
     /**

+ 11 - 11
src/Utility/String.php

@@ -17,10 +17,10 @@ namespace Cake\Utility;
 use InvalidArgumentException;
 
 /**
- * String handling methods.
+ * Text handling methods.
  *
  */
-class String
+class Text
 {
 
     /**
@@ -132,7 +132,7 @@ class String
     /**
      * Replaces variable placeholders inside a $str with any given $data. Each key in the $data array
      * corresponds to a variable placeholder name in $str.
-     * Example: `String::insert(':name is :age years old.', ['name' => 'Bob', '65']);`
+     * Example: `Text::insert(':name is :age years old.', ['name' => 'Bob', '65']);`
      * Returns: Bob is 65 years old.
      *
      * Available $options are:
@@ -142,7 +142,7 @@ class String
      * - escape: The character or string used to escape the before character / string (Defaults to `\`)
      * - format: A regex to use for matching variable placeholders. Default is: `/(?<!\\)\:%s/`
      *   (Overwrites before, after, breaks escape / clean)
-     * - clean: A boolean or array with instructions for String::cleanInsert
+     * - clean: A boolean or array with instructions for Text::cleanInsert
      *
      * @param string $str A string containing variable placeholders
      * @param array $data A key => val array where each key stands for a placeholder variable name
@@ -159,7 +159,7 @@ class String
         $format = $options['format'];
         $data = (array)$data;
         if (empty($data)) {
-            return ($options['clean']) ? String::cleanInsert($str, $options) : $str;
+            return ($options['clean']) ? static::cleanInsert($str, $options) : $str;
         }
 
         if (!isset($format)) {
@@ -178,7 +178,7 @@ class String
                 $offset = $pos + strlen($val);
                 $str = substr_replace($str, $val, $pos, 1);
             }
-            return ($options['clean']) ? String::cleanInsert($str, $options) : $str;
+            return ($options['clean']) ? static::cleanInsert($str, $options) : $str;
         }
 
         asort($data);
@@ -201,19 +201,19 @@ class String
         if (!isset($options['format']) && isset($options['before'])) {
             $str = str_replace($options['escape'] . $options['before'], $options['before'], $str);
         }
-        return ($options['clean']) ? String::cleanInsert($str, $options) : $str;
+        return ($options['clean']) ? static::cleanInsert($str, $options) : $str;
     }
 
     /**
-     * Cleans up a String::insert() formatted string with given $options depending on the 'clean' key in
+     * Cleans up a Text::insert() formatted string with given $options depending on the 'clean' key in
      * $options. The default method used is text but html is also available. The goal of this function
      * is to replace all whitespace and unneeded markup around placeholders that did not get replaced
-     * by String::insert().
+     * by Text::insert().
      *
      * @param string $str String to clean.
      * @param array $options Options list.
      * @return string
-     * @see String::insert()
+     * @see \Cake\Utility\Text::insert()
      */
     public static function cleanInsert($str, array $options)
     {
@@ -243,7 +243,7 @@ class String
                 $str = preg_replace($kleenex, $clean['replacement'], $str);
                 if ($clean['andText']) {
                     $options['clean'] = ['method' => 'text'];
-                    $str = String::cleanInsert($str, $options);
+                    $str = static::cleanInsert($str, $options);
                 }
                 break;
             case 'text':

+ 2 - 2
src/Validation/Validation.php

@@ -14,7 +14,7 @@
  */
 namespace Cake\Validation;
 
-use Cake\Utility\String;
+use Cake\Utility\Text;
 use LogicException;
 use RuntimeException;
 
@@ -881,7 +881,7 @@ class Validation
         }
 
         if (is_string($size)) {
-            $size = String::parseFileSize($size);
+            $size = Text::parseFileSize($size);
         }
         $filesize = filesize($check);
 

+ 8 - 8
src/View/Helper/TextHelper.php

@@ -26,7 +26,7 @@ use Cake\View\View;
  *
  * @property HtmlHelper $Html
  * @link http://book.cakephp.org/3.0/en/views/helpers/text.html
- * @see \Cake\Utility\String
+ * @see \Cake\Utility\Text
  */
 class TextHelper extends Helper
 {
@@ -44,7 +44,7 @@ class TextHelper extends Helper
      * @var array
      */
     protected $_defaultConfig = [
-        'engine' => 'Cake\Utility\String'
+        'engine' => 'Cake\Utility\Text'
     ];
 
     /**
@@ -240,7 +240,7 @@ class TextHelper extends Helper
      * @param string $phrase The phrase that will be searched
      * @param array $options An array of html attributes and options.
      * @return string The highlighted text
-     * @see String::highlight()
+     * @see \Cake\Utility\Text::highlight()
      * @link http://book.cakephp.org/3.0/en/views/helpers/text.html#highlighting-substrings
      */
     public function highlight($text, $phrase, array $options = [])
@@ -277,7 +277,7 @@ class TextHelper extends Helper
      *
      * @param string $text Text
      * @return string The text without links
-     * @see String::stripLinks()
+     * @see \Cake\Utility\Text::stripLinks()
      * @link http://book.cakephp.org/3.0/en/views/helpers/text.html#removing-links
      */
     public function stripLinks($text)
@@ -301,7 +301,7 @@ class TextHelper extends Helper
      * @param int $length Length of returned string, including ellipsis.
      * @param array $options An array of html attributes and options.
      * @return string Trimmed string.
-     * @see String::truncate()
+     * @see \Cake\Utility\Text::truncate()
      * @link http://book.cakephp.org/3.0/en/views/helpers/text.html#truncating-text
      */
     public function truncate($text, $length = 100, array $options = [])
@@ -324,7 +324,7 @@ class TextHelper extends Helper
      * @param int $length Length of returned string, including ellipsis.
      * @param array $options An array of html attributes and options.
      * @return string Trimmed string.
-     * @see \Cake\Utility\String::tail()
+     * @see \Cake\Utility\Text::tail()
      * @link http://book.cakephp.org/3.0/en/views/helpers/text.html#truncating-the-tail-of-a-string
      */
     public function tail($text, $length = 100, array $options = [])
@@ -341,7 +341,7 @@ class TextHelper extends Helper
      * @param int $radius The amount of characters that will be returned on each side of the founded phrase
      * @param string $ending Ending that will be appended
      * @return string Modified string
-     * @see \Cake\Utility\String::excerpt()
+     * @see \Cake\Utility\Text::excerpt()
      * @link http://book.cakephp.org/3.0/en/views/helpers/text.html#extracting-an-excerpt
      */
     public function excerpt($text, $phrase, $radius = 100, $ending = '...')
@@ -356,7 +356,7 @@ class TextHelper extends Helper
      * @param string $and The word used to join the last and second last items together with. Defaults to 'and'.
      * @param string $separator The separator used to join all the other items together. Defaults to ', '.
      * @return string The glued together string.
-     * @see \Cake\Utility\String::toList()
+     * @see \Cake\Utility\Text::toList()
      * @link http://book.cakephp.org/3.0/en/views/helpers/text.html#converting-an-array-to-sentence-form
      */
     public function toList($list, $and = null, $separator = ', ')

+ 0 - 1
tests/TestCase/ORM/TableUuidTest.php

@@ -20,7 +20,6 @@ use Cake\Datasource\ConnectionManager;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
-use Cake\Utility\String;
 
 /**
  * Integration tests for Table class with uuid primary keys.

File diff suppressed because it is too large
+ 152 - 152
tests/TestCase/Utility/StringTest.php