[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Form/ -> Action.php (source)

   1  <?php
   2  /**
   3   * The Horde_Form_Action class provides an API for adding actions to
   4   * Horde_Form variables.
   5   *
   6   * $Horde: framework/Form/Form/Action.php,v 1.19.10.6 2006/01/01 21:28:17 jan Exp $
   7   * Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org>
   8   *
   9   * See the enclosed file COPYING for license information (LGPL). If you
  10   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  11   *
  12   * @author  Chuck Hagenbuch <chuck@horde.org>
  13   * @package Horde_Form
  14   */
  15  class Horde_Form_Action {
  16  
  17      var $_id;
  18      var $_params;
  19      var $_trigger = null;
  20  
  21      function Horde_Form_Action($params = null)
  22      {
  23          $this->_params = $params;
  24          $this->_id = md5(mt_rand());
  25      }
  26  
  27      function getTrigger()
  28      {
  29          return $this->_trigger;
  30      }
  31  
  32      function id()
  33      {
  34          return $this->_id;
  35      }
  36  
  37      function getActionScript($form, $renderer, $varname)
  38      {
  39          return '';
  40      }
  41  
  42      function printJavaScript()
  43      {
  44      }
  45  
  46      function _printJavaScriptStart()
  47      {
  48          echo '<script type="text/javascript"><!--';
  49      }
  50  
  51      function _printJavaScriptEnd()
  52      {
  53          echo '// --></script>';
  54      }
  55  
  56      function getTarget()
  57      {
  58          return isset($this->_params['target']) ? $this->_params['target'] : null;
  59      }
  60  
  61      function setValues(&$vars, $sourceVal, $index = null, $arrayVal = false)
  62      {
  63      }
  64  
  65      /**
  66       * Attempts to return a concrete Horde_Form_Action instance
  67       * based on $form.
  68       *
  69       * @param mixed $form    The type of concrete Horde_Form_Action subclass
  70       *                       to return. If $form is an array, then we will look
  71       *                       in $form[0]/lib/Form/Action/ for the subclass
  72       *                       implementation named $form[1].php.
  73       * @param array $params  A hash containing any additional configuration a
  74       *                       form might need.
  75       *
  76       * @return Horde_Form_Action  The concrete Horde_Form_Action reference, or
  77       *                            false on an error.
  78       */
  79      function &factory($action, $params = null)
  80      {
  81          if (is_array($action)) {
  82              $app = $action[0];
  83              $action = $action[1];
  84          }
  85  
  86          $action = basename($action);
  87          if (empty($action) || (strcmp($action, 'none') == 0)) {
  88              return PEAR::raiseError('Cannot instantiate abstract class Horde_Form_Action.');
  89          }
  90  
  91          if (!empty($app)) {
  92              require_once $GLOBALS['registry']->get('fileroot', $app) . '/lib/Form/Action/' . $action . '.php';
  93          } elseif (@file_exists(dirname(__FILE__) . '/Action/' . $action . '.php')) {
  94              require_once dirname(__FILE__) . '/Action/' . $action . '.php';
  95          } else {
  96              require_once 'Horde/Form/Action/' . $action . '.php';
  97          }
  98  
  99          $class = 'Horde_Form_Action_' . $action;
 100          if (class_exists($class)) {
 101              $instance = &new $class($params);
 102          } else {
 103              $instance = PEAR::raiseError('Class definition of ' . $class . ' not found.');
 104          }
 105  
 106          return $instance;
 107      }
 108  
 109      /**
 110       * Attempts to return a reference to a concrete
 111       * Horde_Form_Action instance based on $action. It will only
 112       * create a new instance if no Horde_Form_Action instance with
 113       * the same parameters currently exists.
 114       *
 115       * This should be used if multiple types of form renderers (and,
 116       * thus, multiple Horde_Form_Action instances) are required.
 117       *
 118       * This method must be invoked as: $var =
 119       * &Horde_Form_Action::singleton()
 120       *
 121       * @param mixed $action  The type of concrete Horde_Form_Action subclass to return.
 122       *                       The code is dynamically included. If $action is an array,
 123       *                       then we will look in $action[0]/lib/Form/Action/ for
 124       *                       the subclass implementation named $action[1].php.
 125       * @param array $params  A hash containing any additional configuration a
 126       *                       form might need.
 127       *
 128       * @return Horde_Form_Action  The concrete Horde_Form_Action reference, or
 129       *                            false on an error.
 130       */
 131      function &singleton($action, $params = null)
 132      {
 133          static $instances;
 134          if (!isset($instances)) {
 135              $instances = array();
 136          }
 137  
 138          $signature = serialize(array($action, $params));
 139          if (!isset($instances[$signature])) {
 140              $instances[$signature] = &Horde_Form_Action::factory($action, $params);
 141          }
 142  
 143          return $instances[$signature];
 144      }
 145  
 146  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7