Skip to content

Commit

Permalink
adding phRets library and non-working shell thing
Browse files Browse the repository at this point in the history
  • Loading branch information
dkullmann committed Nov 7, 2011
1 parent 8150ab0 commit 4f4e8a5
Show file tree
Hide file tree
Showing 3 changed files with 1,770 additions and 0 deletions.
141 changes: 141 additions & 0 deletions libs/rets.php
@@ -0,0 +1,141 @@
<?php
/**
* Import the phRETS library
*
* @author David Kullmann
*/
App::import('Vendor', 'Rets.phRETS', array('file' => 'vendors'.DS.'phrets.php'));

/**
* Whatever
*/
define('RETS_VERSION_HEADER', 'RETS-Version');
define('USERAGENT_HEADER', 'User-Agent');

/**
* Class for connecting via phRETS and forwarding methods to phRETS
*
* @package rets.lib.rets
* @author David Kullmann
*/
class RETS {

/**
* phRETS object
*
* @author David Kullmann
*/
public static $phRETS;

/**
* Configuration options
*
* @author David Kullmann
*/
public static $config;

/**
* Connection status
*
* @author David Kullmann
*/
public static $connection;

/**
* Available RETS resources and their class information
*
* @author David Kullmann
*/
public static $resources;

/**
* Get the config and initialize the phRETS object
*
* @author David Kullmann
*/
public function __construct() {
if (empty(self::$phRETS)) {
self::$phRETS = new phRETS;
}
self::$config = Configure::read('RETS');
if (!is_array(self::$config)) {
throw new Exception('Configure::read("RETS") was not able to load your settings');
}
}

/**
* Connect via phRETS and save the connection
*
* @param string $options
* @return void
* @author David Kullmann
*/
public function connect($options = array()) {
$options = array_merge(self::$config, $options);

if (!empty($options['rets_version'])) {
self::$phRETS->AddHeader(RETS_VERSION_HEADER, $options['rets_version']);
}

if (!empty($options['useragent'])) {
self::$phRETS->AddHeader(USERAGENT_HEADER, $options['useragent']);
}

self::$connection = self::$phRETS->Connect(
$options['login_url'],
$options['username'],
$options['password']
);

if (!self::$connection) {
$exception = self::$phRETS->error();
throw new Exception($exception['text']);
}

self::$resources = Set::combine(self::$phRETS->GetMetadataTypes(), '{n}.Resource', '{n}.Data.0');
}

/**
* Disconnect phRETS and unset the connection
*
* @return void
* @author David Kullmann
*/
public function disconnect() {
self::$phRETS->Disconnect();
self::$connection = false;
}

/**
* Forward methods to phRETS
*
* @param string $method
* @param string $params
* @return void
* @author David Kullmann
*/
public function __call($method, $params) {
try {
return call_user_func_array(array(self::$phRETS, $method), $params);
} catch (Exception $e) {
error_log($e);
}
}

/**
* Forward static methods to phRETS
*
* @param string $method
* @param string $params
* @return void
* @author David Kullmann
*/
public static function __callstatic($method, $params) {
try {
return call_user_func_array(array(self::$phRETS, $method), $params);
} catch (Exception $e) {
error_log($e);
}
}
}
?>

0 comments on commit 4f4e8a5

Please sign in to comment.