From 533d8a65c27d5740e7b10f7758e57c6d847d2c39 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 16 Jul 2009 13:21:46 -0600 Subject: [PATCH] Add Horde_Ajax::. --- framework/Ajax/lib/Horde/Ajax/Imple.php | 54 +++++++++++++++++++ framework/Ajax/lib/Horde/Ajax/Imple/Base.php | 79 ++++++++++++++++++++++++++++ framework/Ajax/package.xml | 65 +++++++++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 framework/Ajax/lib/Horde/Ajax/Imple.php create mode 100644 framework/Ajax/lib/Horde/Ajax/Imple/Base.php create mode 100644 framework/Ajax/package.xml diff --git a/framework/Ajax/lib/Horde/Ajax/Imple.php b/framework/Ajax/lib/Horde/Ajax/Imple.php new file mode 100644 index 000000000..a29044926 --- /dev/null +++ b/framework/Ajax/lib/Horde/Ajax/Imple.php @@ -0,0 +1,54 @@ + + * @package Horde_Ajax + */ +class Horde_Ajax_Imple +{ + /** + * Parameters needed by the subclasses. + * + * @var array + */ + protected $_params = array(); + + /** + * Attempts to return a concrete instance based on $driver. + * + * @param mixed $driver The type of concrete subclass to return. If + * $driver is an array, then look in + * $driver[0]/lib/Ajax/Imple for the subclass + * implementation named $driver[1].php. + * @param array $params A hash containing any additional configuration or + * parameters a subclass might need. + * + * @return Horde_Ajax_Imple_Base The newly created concrete instance. + * @throws Horde_Exception + */ + static public function getInstance($driver, $params = array()) + { + if (is_array($driver)) { + list($app, $driv_name) = $driver; + $driver = basename($driv_name); + } else { + $driver = basename($driver); + } + + $class = (empty($app) ? 'Horde' : $app) . '_Ajax_Imple_' . ucfirst($driver); + + if (class_exists($class)) { + return new $class($params); + } + + throw new Horde_Exception('Class definition of ' . $class . ' not found.'); + } +} diff --git a/framework/Ajax/lib/Horde/Ajax/Imple/Base.php b/framework/Ajax/lib/Horde/Ajax/Imple/Base.php new file mode 100644 index 000000000..aaafb1c98 --- /dev/null +++ b/framework/Ajax/lib/Horde/Ajax/Imple/Base.php @@ -0,0 +1,79 @@ + + * @package Horde_Ajax + */ +abstract class Horde_Ajax_Imple_Base +{ + /** + * Parameters needed by the subclasses. + * + * @var array + */ + protected $_params = array(); + + /** + * Constructor. + * + * @param array $params Any parameters needed by the class. + */ + public function __construct($params) + { + $this->_params = $params; + } + + /** + * Attach the object to a javascript event. + */ + abstract public function attach(); + + /** + * TODO + * + * @param array $args TODO + */ + abstract public function handle($args); + + /** + * TODO + * + * @param string $driver + * @param string $app + * @param array $params + * + * @return string + */ + protected function _getUrl($driver, $app = 'horde', $params = array()) + { + $qstring = 'imple=' . $driver; + + if ($app != 'horde') { + $qstring .= '/impleApp=' . $app; + } + + foreach ($params as $key => $val) { + $qstring .= '/' . $key . '=' . rawurlencode($val); + } + + $registry = Horde_Registry::singleton(); + return Horde::url($registry->get('webroot', 'horde') . '/services/imple.php?' . $qstring); + } + + /** + * Generate a random ID string. + * + * @return string The random ID string. + */ + protected function _randomid() + { + return 'imple_' . uniqid(mt_rand()); + } + +} diff --git a/framework/Ajax/package.xml b/framework/Ajax/package.xml new file mode 100644 index 000000000..4094921aa --- /dev/null +++ b/framework/Ajax/package.xml @@ -0,0 +1,65 @@ + + + Ajax + pear.horde.org + Horde Ajax utilities + This package provides utilities to aid with using AJAX with Horde applications. + + + Michael Slusarz + slusarz + slusarz@horde.org + yes + + 2009-07-16 + + 0.1.0 + 0.1.0 + + + beta + beta + + LGPL + * Initial release. + + + + + + + + + + + + + + + + + + + 5.2.0 + + + 1.7.0 + + + + Core + pear.horde.org + + + + + + + + + + + -- 2.11.0