Source for file Setting.class.php

Documentation is available at Setting.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Load
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Load Setting Interface
  22.  * 
  23.  * This is a special Setting Interface for the Load Interface.  A Load Setting
  24.  * holds rules on how to Load a particular file into memory.  A series of
  25.  * Settings can be created for a variety of file types.  Each Load Setting
  26.  * element refers to a parameter in one of the Load methods.  By defining a
  27.  * Load Setting, the programmer would not have to memorize the entire list
  28.  * arguments required by certain Gumbo_Interface_Load methods, just a key
  29.  * reference.
  30.  * <pre>
  31.  * $load->load ("File_Name", "my_key");
  32.  * </pre>
  33.  * 
  34.  * 'dirs'
  35.  * This provides a list of directories to search for the possible existence
  36.  * of the file.  The list will be searched in the order they are added.  The
  37.  * list will be appended to the type of path chosen (see below).  This is where
  38.  * the use of a custom directory is important.  Place the custom directory ahead
  39.  * of the source path.
  40.  * 
  41.  * 'class'
  42.  * This simply indicates that the file name passed is the class name.  There are
  43.  * special rules when loading a Class file and a regular file.  There can only be
  44.  * one definition of a Class or Interface.
  45.  * 
  46.  * 'ext' (file extension)
  47.  * This will define the file extension of the file being passed.  The file name
  48.  * passed does not need to include the file extension.  If the extension argument
  49.  * is set, then it will replace the extension in the file name (file_name.*.ext).
  50.  * It will only replace the last part of the extension.  So, if passing
  51.  * "file_name.class.php" with an extension "inc.php", the search will be for
  52.  * "file_name.class.inc.php".  If the extension is not set, the default value
  53.  * will be used.
  54.  * 
  55.  * 'once'
  56.  * This will load the file only once.  This is useful for files that hold a series
  57.  * of functions or multiple class definitions.
  58.  * 
  59.  * 'include'
  60.  * This setting will tell the Loader to use the include[_once] functions instead of
  61.  * the require[_once] functions.  The default is require.
  62.  * 
  63.  * 'stretch'
  64.  * This setting will expand the file name into additional directory paths.  For example,
  65.  * the Gumbo Library is organized using the stretch feature.  To find the Gumbo_Valid_Address
  66.  * class, simply go into <gumbo_home[custom]_path>/valid/Address.class.php.  The last element
  67.  * of the file name should be the actual file name.  The stretch feature will use the
  68.  * separator string (see below) for searching.
  69.  * 
  70.  * 'separator'
  71.  * This is a character of string of characters to use to separate the file name into
  72.  * directory paths.  The default is an underscore "_" (see example above).
  73.  * 
  74.  * 'path'
  75.  * This indicates the starting path of the search.  The directories list will be
  76.  * appended to this location, followed by any stretch definitions, then the file
  77.  * name and extension.  The path is separated into three areas.
  78.  * - include (default), uses the include path
  79.  * - home, indicates the path to the Gumbo Library
  80.  * - absolute, indicates the directories are from the home path
  81.  * 
  82.  * 'remove'
  83.  * This is a character or string of characters to remove from the file name prior to
  84.  * searching.  For example, when searching for Library files, I would want the
  85.  * library path (home or custom) to be the starting point, followed by the stretch
  86.  * of the file name "Gumbo_Valid_Address".  Without remove, the path would be created
  87.  * as '<home>/gumbo/valid/address.class.php'.  With remove set to "Gumbo_" (default),
  88.  * the string will be removed prior to setting the file path. Now, the path will be
  89.  * '<home>/valid/address.class.php'.  This feature can be used to create a Load Setting
  90.  * for the Zend Framework, using remove as 'Zend_'.
  91.  *
  92.  * @category Gumbo
  93.  * @package Load
  94.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  95.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  96.  * @author Michael Luster <mluster79@yahoo.com>
  97.  * @link http://sourceforge.net/projects/phpgumbo
  98.  * @desc Load Setting Interface
  99.  * @version 0.0.1
  100.  */
  101.  
  102.     
  103.     /** ACTION METHODS **/
  104.     /**
  105.      * Adds a single directory path to the list
  106.      * @param string $dir 
  107.      */
  108.     public function addDir ($dir);
  109.     
  110.     
  111.     
  112.     /** MUTATOR METHODS **/
  113.     /**
  114.      * Sets the setting to load a class file
  115.      * @param bool $val 
  116.      */
  117.     public function setClass ($val);
  118.     
  119.     /**
  120.      * Adds a list of directories to the list
  121.      * 
  122.      * There are three ways to set the Directory paths.  The first method passes
  123.      * a string, with either a single directory or list of directories separated
  124.      * by the PATH_SEPARATOR constant.  The second passes an array, with each
  125.      * element value a different directory.  The third involves either of the first
  126.      * two methods, but multiple arguments.
  127.      * 
  128.      * 1. $this->setDirs ("path1:path2:path3/path4");
  129.      * 2. $this->setDirs (array ("path1", "path2", "path3/path4"));
  130.      * 3. $this->setDirs ("path1", array ("path2"), "path3/path4:path5");
  131.      * 
  132.      * @param array|string$dirs ...[]
  133.      */
  134.     public function setDirs ($dirs);
  135.     
  136.     /**
  137.      * Sets the file extension (leading "." not necessary)
  138.      * @param string $ext 
  139.      */
  140.     public function setExtension ($ext);
  141.     
  142.     /**
  143.      * Sets the load only once setting
  144.      * @param bool $once 
  145.      */
  146.     public function setOnce ($once);
  147.     
  148.     /**
  149.      * Sets to use include instead of require
  150.      * @param bool $include 
  151.      */
  152.     public function setInclude ($include);
  153.     
  154.     /**
  155.      * Sets to stretch the file name as additional directory paths
  156.      * @param bool $stretch 
  157.      */
  158.     public function setStretch ($stretch);
  159.     
  160.     /**
  161.      * Sets the stretch separator character
  162.      * @param string $sep 
  163.      */
  164.     public function setSeparator ($sep);
  165.     
  166.     /**
  167.      * Sets the path to start searching from.
  168.      * Possible values:
  169.      * - include: search the include path (default)
  170.      * - home: start from Gumbo home directory
  171.      * - absolute: ignores starting point and uses dirs as absolute paths
  172.      * 
  173.      * @param string $path 
  174.      */
  175.     public function setPath ($path);
  176.     
  177.     /**
  178.      * Sets a string pattern to remove from the file name before search
  179.      * @param string $remove 
  180.      */
  181.     public function setRemove ($remove);
  182.     
  183.     
  184.     
  185.     /** ACCESSOR METHODS **/
  186.     /**
  187.      * Returns if the setting is for a class load
  188.      * @return bool 
  189.      */
  190.     public function getClass ();
  191.     
  192.     /**
  193.      * Returns the list of directory paths
  194.      * @return array 
  195.      */
  196.     public function getDirs ();
  197.     
  198.     /**
  199.      * Returns the file extension
  200.      * @return string 
  201.      */
  202.     public function getExtension ();
  203.     
  204.     /**
  205.      * Returns if the file should be loaded once
  206.      * @return bool 
  207.      */
  208.     public function getOnce ();
  209.     
  210.     /**
  211.      * Returns if the include function should be used instead of require
  212.      * @return bool 
  213.      */
  214.     public function getInclude ();
  215.     
  216.     /**
  217.      * Returns if the file name should stretch
  218.      * @return bool 
  219.      */
  220.     public function getStretch ();
  221.     
  222.     /**
  223.      * Returns the stretch separator character
  224.      * @return string 
  225.      */
  226.     public function getSeparator ();
  227.     
  228.     /**
  229.      * Returns the path to start searching from
  230.      * @return string 
  231.      */
  232.     public function getPath ();
  233.     
  234.     /**
  235.      * Returns the remove string pattern
  236.      * @return string 
  237.      */
  238.     public function getRemove ();
  239.     
  240. }
  241.  
  242. ?>