Source for file DataHandler.php
Documentation is available at DataHandler.php
declare(encoding = "utf-8");
* This file is part of ForwardFW a web application framework.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @author Alexander Opitz <opitz.alexander@primacom.net>
* @copyright 2009-2010 The Authors
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link http://forwardfw.sourceforge.net
* @since File available since Release 0.0.7
require_once 'ForwardFW/Interface/DataHandler.php';
require_once 'ForwardFW/Interface/Application.php';
require_once 'ForwardFW/Callback.php';
require_once 'ForwardFW/Cache/Frontend/Function.php';
require_once 'ForwardFW/Config/Cache/Backend/File.php';
require_once 'ForwardFW/Config/Cache/Data/Function.php';
* Managing DataLoading via PEAR::MDB
* @author Alexander Opitz <opitz.alexander@primacom.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link http://forwardfw.sourceforge.net
* @var array Cache of connections
* @param ForwardFW_Interface_Application $application The running application.
public function __construct(ForwardFW_Interface_Application $application)
* Returns an instance of configured DataHandler.
* @param ForwardFW_Interface_Application $application The running application.
public static function getInstance(ForwardFW_Interface_Application $application)
if (isset ($GLOBALS['DataLoader']['instance'][$application])) {
$return = $GLOBALS['DataLoader']['instance'][$application->getName()];
$GLOBALS['DataLoader']['instance'][$application->getName()] = $return;
* Loads Data from cache or from a connection (DB, SOAP, File) if cache failed.
* @param string $strConnection Name of connection
* @param array $arOptions Options to load the data
* @return mixed Data from the connection.
public function loadFromCached($strConnection, array $arOptions, $nCacheTimeout = - 1)
$handler = $this->getConnection($strConnection);
array($handler, 'loadFrom'),
array($strConnection, $arOptions)
->setCallback($cacheCallback)
->setTimeout($nCacheTimeout);
return $cache->getCache($configCacheData);
* Initializes and returns the caching system depending on connection
* @param string $strConnection Name of connection
* @return ForwardFW_Cache_Frontend The Cache Frontend.
$backendConfig->strPath = getcwd() . '/cache/';
->setCacheBackend('ForwardFW_Cache_Backend_File')
->setBackendConfig($backendConfig)
->setCacheFrontend('ForwardFW_Cache_Frontend_Function');
* Loads Data from a connection (DB, SOAP, File)
* @param string $strConnection Name of connection
* @param array $arOptions Options to load the data
* @return mixed Data from the connection.
public function loadFrom($strConnection, array $arOptions)
$handler = $this->getConnection($strConnection);
return $handler->loadFrom($strConnection, $arOptions);
* Saves Data to a connection (DB, SOAP, File)
* @param string $strConnection Name of connection
* @param array $arOptions Options to load the data
* @return mixed Data from the connection.
public function saveTo($strConnection, array $options)
$handler = $this->getConnection($strConnection);
return $handler->saveTo($strConnection, $arOptions);
* Gets the connection handler.
* @param string $strConnection Name of connection
* @return mixed ConnectionHandler
// Return existing connection
* Loads and initialize the connection handler.
* @param string $strConnection Name of connection
$strHandler = $arConfig['handler'];
$strFile = str_replace('_', '/', $strHandler) . '.php';
$rIncludeFile = @fopen($strFile, 'r', true);
$ret = include_once $strFile;
$this->application->getResponse()->addError('DataHandler not includeable.');
|