home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / CodeGen / License.php < prev    next >
Encoding:
PHP Script  |  2006-04-07  |  3.3 KB  |  135 lines

  1. <?php
  2. /**
  3.  * Abstract base class for licenses
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   Tools and Utilities
  14.  * @package    CodeGen
  15.  * @author     Hartmut Holzgraefe <hartmut@php.net>
  16.  * @copyright  2005 Hartmut Holzgraefe
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: License.php,v 1.4 2005/08/14 16:47:54 hholzgra Exp $
  19.  * @link       http://pear.php.net/package/CodeGen
  20.  */
  21.  
  22. /**
  23.  * includes
  24.  */
  25. require_once("CodeGen/Tools/FileReplacer.php");
  26.  
  27. /**
  28.  * Abstract base class for licenses
  29.  *
  30.  * @category   Tools and Utilities
  31.  * @package    CodeGen
  32.  * @author     Hartmut Holzgraefe <hartmut@php.net>
  33.  * @copyright  2005 Hartmut Holzgraefe
  34.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  35.  * @version    Release: @package_version@
  36.  * @link       http://pear.php.net/package/CodeGen
  37.  */
  38. abstract class CodeGen_License
  39. {
  40.     /**
  41.      * Constructor
  42.      *
  43.      * @access private
  44.      * @param  License options
  45.      */
  46.     function __construct($options = array()) 
  47.     {
  48.         $this->options = $options;
  49.     }
  50.  
  51.     /**
  52.      * Takes a License shortname and returns an instantiated object of that license
  53.      *
  54.      * @access  public
  55.      * @param   string  License shortname, e.g. PHP, BSD, LGPL
  56.      * @param   array   License options
  57.      * @returns object  License instance
  58.      */
  59.     static function factory($name, $options=array()) 
  60.     {
  61.         $classname = "CodeGen_License_".strtoupper($name);
  62.         $classfile = str_replace("_", "/", $classname).".php";
  63.  
  64.         if (!class_exists($classname)) {
  65.             if (!@include_once "$classfile")
  66.                 PEAR::raiseError("Unknown license type '$name' ", E_USER_WARNING);
  67.         }
  68.  
  69.         return 
  70.             class_exists($classname) 
  71.             ? new $classname($options) 
  72.             : false;
  73.     }
  74.  
  75.     /**
  76.      * Writes the License text to a file
  77.      *
  78.      * @param   string Filename to write to (default is ./LICENSE) 
  79.      * @return  bool   Success state
  80.      * @access  public
  81.      */
  82.     function writeToFile($path = "./LICENSE") 
  83.     {
  84.         $fp = new CodeGen_Tools_FileReplacer($path);
  85.  
  86.         $fp->puts($this->getText()); 
  87.         
  88.         return $fp->close();
  89.     }
  90.     
  91.     /**
  92.      * Returns the full license name
  93.      * 
  94.      * @return string    License name
  95.      * @access public
  96.      */
  97.     abstract function getName();
  98.  
  99.     /**
  100.      * Returns the sort license name
  101.      * 
  102.      * @return string    License shortname
  103.      * @access public
  104.      */
  105.     abstract function getShortName();
  106.  
  107.     /**
  108.      * Returns the complete license text as string
  109.      * 
  110.      * @return string    License text
  111.      * @access public
  112.      */
  113.     abstract function getText();
  114.  
  115.     /** 
  116.      * Returns an URI that points to the license text or an online description
  117.      *
  118.      * @return string License URI
  119.      * @access public
  120.      */
  121.     function getUri()
  122.     {
  123.         return "";
  124.     }
  125. }
  126.  
  127. /*
  128.  * Local variables:
  129.  * tab-width: 4
  130.  * c-basic-offset: 4
  131.  * indent-tabs-mode:nil
  132.  * End:
  133.  */
  134.  
  135. ?>