|
Posted by Timothee Groleau on 05/19/06 06:51
Hi all,
I'm trying to create a webservice by using a class but I have some problems
with sharing redundant code. I thought I could create private methods in my
class to share the common code without exposing the function in the
webservice but that is not working :(.
Is there a way to achieve this? Here is my sample webservice class. The
method, I'd like to share is "connect".
=================
<?php
require_once('DB.php');
require_once($_SERVER["DOCUMENT_ROOT"]."/page_tracker/config.inc.php");
/**
* retrieve hit count for pages, or IDs, over specified period of time
*/
class PageTrackerWS {
private $connected = false;
private $db;
/**
* Initializes connection to the DB
* @return void
*/
private function connect()
{
if ($connected) return;
global $config;
$db = DB::Connect($config['dsn']);
if (DB::isError($db)) {
throw new Exception($db->getUserInfo());
}
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$connected = true;
}
/**
* Returns a list of all page that are marked for tracking
* @return string[]
*/
public function getTrackedPages()
{
try
{
connect();
$db->setFetchMode(DB_FETCHMODE_ORDERED);
$req = $db->query("SELECT URI from URIS");
if (DB::isError($req)) throw new Exception($req->getUserInfo());
while ($row = $req->fetchRow())
{
$ret[] = $row[0];
}
return $ret;
}
catch(Exception $e)
{
// !! TODO
// return Fault here
}
}
/**
* Returns the internal ID of a tracked page
* @param string $uri The uri
* @return string
*/
public function getPageID($uri)
{
try
{
connect();
$ID = $db->getOne("SELECT ID from URIS WHERE URI=?", array($uri));
if (DB::isError($ID)) throw new Exception($ID->getUserInfo());
return $ID;
}
catch(Exception $e)
{
// !! TODO
// return Fault here
}
}
}
?>
=================
Navigation:
[Reply to this message]
|