View Source

<ac:macro ac:name="note"><ac:parameter ac:name="title">Under Construction</ac:parameter><ac:rich-text-body>
<p>Superseded by Zend_Locale_Utf8.</p></ac:rich-text-body></ac:macro>

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_UTF8
{zone-data}

{zone-data:proposer-list}
[André Hoffmann|mailto:antiHERO2006@gmail.com]
{zone-data}

{zone-data:revision}
1.0 - 2 August 2006: inital release of the Zend_UTF8 proposal
{zone-data}

{zone-data:overview}
Until Zend raises the requirements to PHP 6 we should have a solution for handling UTF-8 stuff. That way we won't be in a rush to upgrade to PHP 6 and ZF could support both PHP 5 and 6 for as long as needed.

Zend_UTF8 is a library of UTF-8 constants(patterns for PCRE) and functions, that is:
* functions that convert strings to ascii(at least the letters that are available in acii), convert strings to hmtlentities
* some standard string functions: strtolower/upper, strlen, strstr, ord/chr, str_replace and so on
* and some other stuff depending on what is needed by other components (*if you are a developer or even an user and think that you can't live without a specific string function please let me know*)
{zone-data}

{zone-data:references}
* [UTF-8 char table|http://www.utf8-chartable.de/]
* [http://en.wikipedia.org/wiki/UTF-8]
* [RFC 3629|http://tools.ietf.org/html/rfc3629#page-5]
* [UTF-8 library|http://sourceforge.net/project/showfiles.php?group_id=142846]
* [PEAR UTF-8 Lib|http://pear.php.net/package/I18N_UnicodeString]
* [What an amazing list|http://wiki.silverorange.com/UTF-8_Notes]
{zone-data}

{zone-data:requirements}
* should provide basic functions for PHP65 utf-8 handling
* should not require [mbyte|http://www.php.net/mbstring] extension, but should use it when installed
* an UTF-8 enabled PCRE extension should not be required, but used when available
* should make it possible to support both PHP6 and PHP5
{zone-data}

{zone-data:dependencies}
* Zend_UTF8_Exception
* mbstring ?
{zone-data}

{zone-data:operation}
Phases:
# ZF supports PHP5 only and uses Zend_UTF8 to achieve PHP6 UTF8 ability
# ZF supports both PHP5 and PHP6 and let's PHP_UTF8 decide whether to use the workarounds or to use the PHP6-wrapper
# ZF supports PHP6 only: Zend_UTF8 should be removed to achieve a little performance boost

Zend_UTF8 should not replace PHP6's UTF-8 support completely, but just add some often used and important functions to PHP5 as a temporary solution.
{zone-data}

{zone-data:class-list}
* Zend_UTF8
* Zend_UTF8_PHP5
* Zend_UTF8_PHP5_Library
* Zend_UTF8_PHP6
* Zend_UTF8_PHPx_String
* Zend_UTF8_PHPx_CharacterClass
* Zend_UTF8_Exception
(x is either 5 or 6)
{zone-data}

{zone-data:use-cases}
||Usage by other components
{code}
$myString = Zend_UTF8::toUpper('wéîrd tèst stríñg');
{code}||

||Usage by users
{code}
$utfLib = Zend_UTF8::factory();
//or: $utfLib = Zend_UTF8::factory( Zend_UTF8::PHP5 );
echo $utflib->toUpper('tèst');
{code}||

||Usage of Zend_UTF8_String by users
{code}
$utfLib = Zend_UTF8::factory();
$string = $utflib->string('tést - wêîrd lètters');
echo $string->toUpper();
{code}||

||Usage of Zend_UTF8_PHPx_CharacterClass
{code}
$utfLib = Zend_UTF8::factory();
$characterClass = $utfLib->characterClass();
$characterCLass ->addRange('B', 'F')
->addLowerAlpha()
->addRange(0, 9);
if ( preg_match('/my'.$characterClass->toString().'Something/', $var) )
{ /* .. */ }
//in php5.2 preg_match('/my'.$characterClass.'Something/' $var);
{code}||

{zone-data}

{zone-data:skeletons}
[!Zend_UTF8_v4_small.JPG!|Zend_Db_Adapter_Odbtp_Mssql^Zend_UTF8_v4.JPG]

*Please note that I'm yet to define the functions that will be available, so for now there's only strtolower as an example to illustrate how the design is planned to be like.*
{code}
/**
* Class 'Zend_UTF8'
*
* @package Zend
* @subpackage UTF8
*
*/
class Zend_UTF8 {

const PHP5 = 1;

const PHP6 = 2;

const AUTO = 4;

/**
* Property '_instances'
*
* @var array
* @access private
* @static
*/
private static $_instances;

/**
* Property '_version'
*
* @var int
* @access private
* @static
*/
private static $_version = Zend_UTF8::AUTO;

/**
* factory
*
* Gives back an instance of either Zend_UTF8_PHP5 or Zend_UTF8_PHP6
* depending on the parameter 'version'.
* Instances will be stored in $_instances as there isn't more than
* one instance of each class needed.
*
* @param int version
* @return Zend_UTF8_Interface
* @static
*/
public static function factory($version = Zend_UTF8::AUTO)
{}

/**
* setVersion
*
* sets the version that will be used by the static functions
*
* @param string version
* @static
*/
public static function setVersion($version
{}

/**
* getVersion
*
*
* @return int
* @static
*/
public static function getVersion()
{}

/**
* getLibrary
*
*
* @return Zend_UTF8_Interface
* @static
*/
private static function getLibrary()
{}

/**
* toLower
*
* uses Zend_UTF8::getLibrary() to get Library(PHP5 or PHP6) to call
* Zend_UTF8_Library::toLower()
*
* @param string string
* @return string
* @static
*/
public static function toLower($string)
{}

}

/**
* Class 'Zend_UTF8_Interface'
*
* @package Zend
* @subpackage UTF8
*
*/
interface Zend_UTF8_Interface {

/**
* toLower
*
*
* @param string string
* @return string
*/
public function toLower($string);

}


/**
* Class 'Zend_UTF8_PHP6'
*
* @package Zend
* @subpackage UTF8
*
*/
class Zend_UTF8_PHP6 implements Zend_UTF8_Interface {

/**
* toLower
*
*
* @param string string
* @return string
*/
public function toLower($string)
{}

}


/**
* Class 'Zend_UTF8_PHP5'
*
* @package Zend
* @subpackage UTF8
*
*/
class Zend_UTF8_PHP5 implements Zend_UTF8_Interface {

/**
* toLower
*
*
* @param string string
* @return string
*/
public function toLower($string)
{}


/**
* CharacterClass
*
*
* @access public
* @return Zend_UTF8_PHP5_CharacterClass
*/
public function characterClass()
{}

}


/**
* Class 'Zend_UTF8_Library'
*
* @package Zend
* @subpackage UTF8
*
*/
class Zend_UTF8_Library {

/**
* toLower
*
*
* @param string string
* @return string
* @static
*/
public static function toLower($string)
{}

}


/**
* Class 'Zend_UTF8_PHP5_Strng'
*
* @package Zend
* @subpackage UTF8
*
*/
class Zend_UTF8_PHP5_String implements Zend_UTF8_Interface_String {

/**
*Property '_string'
*
* @var string
* @access private
*/
private $_string = '';

/**
* __construct
*
*
* @param string string
*/
public function __construct($string)
{}


/**
* toLower
*
*
* @access public
* @return string
*/
public function toLower()
{}


/**
* __toString
*
*
* @access public
* @return string
*/
public function __toString()
{}



}

/**
* Class 'Zend_UTF8_PHP5_CharacterClass'
*
* @package Zend
* @subpackage UTF8
*
*/
class Zend_UTF8_PHP5_CharacterClass implements Zend_UTF8_Interface_CharacterClass {

private $_characterClass = '';

/**
* addRange
*
* Adds a range of characters to the character class(UTF-8 aware).
*
* @param $from mixed
* @param $to mixed
* @return Zend_UTF8_PHP5_CharacterClass
*/
public function addRange ($from, $to)
{}

/**
* addUpperAlpha
*
*
* @return Zend_UTF8_PHP5_CharacterClass
*/
public function addUpperAlpha()
{}

/**
* addLowerAlpha
*
*
* @return Zend_UTF8_PHP5_CharacterClass
*/
public function addLowerAlpha()
{}

/**
* addAlpha
*
*
* @return Zend_UTF8_PHP5_CharacterClass
*/
public function addAlpha()
{}

/**
* toString
*
*
* @return string
*/
public function toString()
{}

/**
* __toString
*
*
* @return string
*/
public function __toString()
{}
}


/**
* Class 'Zend_UTF8_Exception'
*
* @package Zend
* @subpackage UTF8
*
*/
class Zend_UTF8_Exception extends Zend_Exception
{}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>