5 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
7 // +----------------------------------------------------------------------+
8 // | This library is free software; you can redistribute it and/or modify |
9 // | it under the terms of the GNU Lesser General Public License as |
10 // | published by the Free Software Foundation; either version 2.1 of the |
11 // | License, or (at your option) any later version. |
13 // | This library is distributed in the hope that it will be useful, but |
14 // | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 // | Lesser General Public License for more details. |
18 // | You should have received a copy of the GNU Lesser General Public |
19 // | License along with this library; if not, write to the Free Software |
20 // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
22 // +----------------------------------------------------------------------+
29 * Encode/decode Internationalized Domain Names.
30 * Factory class to get correct implementation either for php4 or php5.
32 * @author Markus Nix <mnix@docuverse.de>
33 * @author Matthias Sommerfeld <mso@phlylabs.de>
35 * @version $Id: IDNA.php 284681 2009-07-24 04:24:27Z clockwerx $
42 * Attempts to return a concrete IDNA instance for either php4 or php5.
44 * @param array $params Set of paramaters
45 * @return object IDNA The newly created concrete Log instance, or an
49 function getInstance($params = array())
51 $version = explode( '.', phpversion() );
52 $handler = ((int)$version[0] > 4) ? 'php5' : 'php4';
53 $class = 'Net_IDNA_' . $handler;
54 $classfile = 'Net/IDNA/' . $handler . '.php';
57 * Attempt to include our version of the named class, but don't treat
58 * a failure as fatal. The caller may have already included their own
59 * version of the named class.
61 @include_once $classfile;
63 /* If the class exists, return a new instance of it. */
64 if (class_exists($class)) {
65 return new $class($params);
74 * Attempts to return a concrete IDNA instance for either php4 or php5,
75 * only creating a new instance if no IDNA instance with the same
76 * parameters currently exists.
78 * @param array $params Set of paramaters
79 * @return object IDNA The newly created concrete Log instance, or an
83 function singleton($params = array())
86 if (!isset($instances)) {
90 $signature = serialize($params);
91 if (!isset($instances[$signature])) {
92 $instances[$signature] = Net_IDNA::getInstance($params);
95 return $instances[$signature];