Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first checkin of 0.7.1-version of the package, as as a basis
git-svn-id: http://svn.php.net/repository/pear/packages/Net_IDNA/trunk@255772 c90b9560-bf6c-de11-be94-00142212c4b1
- Loading branch information
Showing
5 changed files
with
6,610 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
// {{{ license | ||
|
||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ | ||
// | ||
// +----------------------------------------------------------------------+ | ||
// | This library is free software; you can redistribute it and/or modify | | ||
// | it under the terms of the GNU Lesser General Public License as | | ||
// | published by the Free Software Foundation; either version 2.1 of the | | ||
// | License, or (at your option) any later version. | | ||
// | | | ||
// | This library is distributed in the hope that it will be useful, but | | ||
// | WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | ||
// | Lesser General Public License for more details. | | ||
// | | | ||
// | You should have received a copy of the GNU Lesser General Public | | ||
// | License along with this library; if not, write to the Free Software | | ||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | | ||
// | USA. | | ||
// +----------------------------------------------------------------------+ | ||
// | ||
|
||
// }}} | ||
|
||
|
||
/** | ||
* Encode/decode Internationalized Domain Names. | ||
* Factory class to get correct implementation either for php4 or php5. | ||
* | ||
* @author Markus Nix <mnix@docuverse.de> | ||
* @author Matthias Sommerfeld <mso@phlylabs.de> | ||
* @package Net | ||
* @version $Id$ | ||
*/ | ||
|
||
class Net_IDNA | ||
{ | ||
// {{{ factory | ||
/** | ||
* Attempts to return a concrete IDNA instance for either php4 or php5. | ||
* | ||
* @param array $params Set of paramaters | ||
* @return object IDNA The newly created concrete Log instance, or an | ||
* false on an error. | ||
* @access public | ||
*/ | ||
function &getInstance($params = array()) | ||
{ | ||
$version = explode( '.', phpversion() ); | ||
$handler = ((int)$version[0] > 4) ? 'php5' : 'php4'; | ||
$class = 'Net_IDNA_' . $handler; | ||
$classfile = 'Net/IDNA/' . $handler . '.php'; | ||
|
||
/* | ||
* Attempt to include our version of the named class, but don't treat | ||
* a failure as fatal. The caller may have already included their own | ||
* version of the named class. | ||
*/ | ||
@include_once $classfile; | ||
|
||
/* If the class exists, return a new instance of it. */ | ||
if (class_exists($class)) { | ||
return new $class($params); | ||
} | ||
|
||
return false; | ||
} | ||
// }}} | ||
|
||
// {{{ singleton | ||
/** | ||
* Attempts to return a concrete IDNA instance for either php4 or php5, | ||
* only creating a new instance if no IDNA instance with the same | ||
* parameters currently exists. | ||
* | ||
* @param array $params Set of paramaters | ||
* @return object IDNA The newly created concrete Log instance, or an | ||
* false on an error. | ||
* @access public | ||
*/ | ||
function &singleton($params = array()) | ||
{ | ||
static $instances; | ||
if (!isset($instances)) { | ||
$instances = array(); | ||
} | ||
|
||
$signature = serialize($params); | ||
if (!isset($instances[$signature])) { | ||
$instances[$signature] = &Net_IDNA::factory($params); | ||
} | ||
|
||
return $instances[$signature]; | ||
} | ||
// }}} | ||
} | ||
|
||
?> |
Oops, something went wrong.