home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Net / IDNA.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.5 KB  |  102 lines

  1. <?php
  2.  
  3. // {{{ license
  4.  
  5. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  6. //
  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.                      |
  12. // |                                                                      |
  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.                      |
  17. // |                                                                      |
  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 |
  21. // | USA.                                                                 |
  22. // +----------------------------------------------------------------------+
  23. //
  24.  
  25. // }}}
  26.  
  27.  
  28. /**
  29.  * Encode/decode Internationalized Domain Names.
  30.  * Factory class to get correct implementation either for php4 or php5.
  31.  *
  32.  * @author  Markus Nix <mnix@docuverse.de>
  33.  * @author  Matthias Sommerfeld <mso@phlylabs.de>
  34.  * @package Net
  35.  * @version $Id: IDNA.php,v 1.1 2008/03/22 12:39:37 neufeind Exp $
  36.  */
  37.  
  38. class Net_IDNA
  39. {
  40.     // {{{ factory
  41.     /**
  42.      * Attempts to return a concrete IDNA instance for either php4 or php5.
  43.      *
  44.      * @param  array  $params   Set of paramaters
  45.      * @return object IDNA      The newly created concrete Log instance, or an
  46.      *                          false on an error.
  47.      * @access public
  48.      */
  49.     function &getInstance($params = array())
  50.     {
  51.         $version   = explode( '.', phpversion() );
  52.         $handler   = ((int)$version[0] > 4) ? 'php5' : 'php4';
  53.         $class     = 'Net_IDNA_' . $handler;
  54.         $classfile = 'Net/IDNA/' . $handler . '.php';
  55.  
  56.         /*
  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.
  60.          */
  61.         @include_once $classfile;
  62.  
  63.         /* If the class exists, return a new instance of it. */
  64.         if (class_exists($class)) {
  65.             $instance = &new $class($params);
  66.             return $instance;
  67.         }
  68.  
  69.         return false;
  70.     }
  71.     // }}}
  72.  
  73.     // {{{ singleton
  74.     /**
  75.      * Attempts to return a concrete IDNA instance for either php4 or php5,
  76.      * only creating a new instance if no IDNA instance with the same
  77.      * parameters currently exists.
  78.      *
  79.      * @param  array  $params   Set of paramaters
  80.      * @return object IDNA      The newly created concrete Log instance, or an
  81.      *                          false on an error.
  82.      * @access public
  83.      */
  84.     function &singleton($params = array())
  85.     {
  86.         static $instances;
  87.         if (!isset($instances)) {
  88.             $instances = array();
  89.         }
  90.  
  91.         $signature = serialize($params);
  92.         if (!isset($instances[$signature])) {
  93.             $instances[$signature] = &Net_IDNA::getInstance($params);
  94.         }
  95.  
  96.         return $instances[$signature];
  97.     }
  98.     // }}}
  99. }
  100.  
  101. ?>
  102.