Net
[ class tree: Net ] [ index: Net ] [ all elements ]

Source for file IDNA.php

Documentation is available at IDNA.php

  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.2 2004/08/16 09:35:40 docuverse_de 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.             return new $class($params);
  66.         }
  67.  
  68.         return false;
  69.     }
  70.     // }}}
  71.     
  72.     // {{{ singleton
  73.     /**
  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.
  77.      *
  78.      * @param  array  $params   Set of paramaters
  79.      * @return object IDNA      The newly created concrete Log instance, or an
  80.      *                           false on an error.
  81.      * @access public
  82.      */
  83.     function &singleton($params = array())
  84.     {
  85.         static $instances;
  86.         if (!isset($instances)) {
  87.             $instances = array();
  88.         }
  89.         
  90.         $signature serialize($params);
  91.         if (!isset($instances[$signature])) {
  92.             $instances[$signature&Net_IDNA::factory($params);
  93.         }
  94.  
  95.         return $instances[$signature];
  96.     }
  97.     // }}}
  98. }
  99.  
  100. ?>

Documentation generated on Mon, 11 Mar 2019 14:22:38 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.