Permalink
Browse files

FREAKING LOADERgit add system/libraries/Driver.phpgit add system/libr…

…aries/Driver.php
  • Loading branch information...
hannesvdvreken committed Jul 12, 2012
1 parent a4f169e commit ff15cacbcb8016fb255fb6b66806e2664c006dab
@@ -52,7 +52,7 @@
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/
-$autoload['libraries'] = array('database','session');
+$autoload['libraries'] = array('database','service');//'database','session');//,'service');//,'OAuth2');
/*
@@ -106,7 +106,7 @@
| http://codeigniter.com/user_guide/general/creating_libraries.html
|
*/
-$config['subclass_prefix'] = 'MY_';
+$config['subclass_prefix'] = '';
/*
@@ -51,19 +51,17 @@ function index() {
} else if ($post_params !== FALSE) {
$method = 'post';
$params = $post_params;
- } else {
- if ($postbody = file_get_contents('php://input')) {
- return $this->return_error(array('error' => 'plain text postbody not yet supported'));
- }
+ } else if ($postbody = file_get_contents('php://input')) {
+ return $this->return_error(array('error' => 'plain text postbody not yet supported'));
}
- // Y U NO LOAD?
$this->load->driver('service', array('adapter' => $service_name));
if (!$this->service->is_valid($service_name)) {
return $this->return_error(array('error' => $service_name . ' does not exist'));
}
$this->service->{$service_name}->set_authentication($tokens);
echo $this->service->{$service_name}->api($endpoint_uri, $params, $method);
+
}
}
@@ -12,6 +12,7 @@ function __construct(){
/**
* @return object ( 'client_id','user_id','access_token')
*/
+
protected function is_authenticated(){
// Get token
$auth_header = $this->input->get_request_header('Authorization');
@@ -11,15 +11,16 @@
class Service extends CI_Driver_Library {
- protected $adapter = NULL;
+ protected $adapter = NULL; //default
protected $valid_drivers = array('Service_foursquare', 'Service_facebook', 'Service_google', 'Service_viking');
+ /*
public function __construct($config = array()) {
if (isset($config['adapter']) && in_array('service_' . $config['adapter'], array_map('strtolower', $this->valid_drivers))) {
$this->adapter = $config['adapter'];
}
}
-
+ */
function __call($method, $args = array()) {
return call_user_func_array(array($this->{$this->adapter}, $method), $args);
}
@@ -44,6 +45,8 @@ function __construct() {
$this->ci = &get_instance();
}
+ function set_service_name( $service_name ){}; // do nothing
+
/**
* Get ext_user_id and authentication_tokens from specific service
*/
@@ -12,23 +12,22 @@
abstract class Service_default extends CI_Driver {
- protected $ci ;
- protected $settings ;
+ protected $ci;
+ protected $url_api_base;
function __construct(){
$this->ci = &get_instance();
$this->ci->load->library('curl');
}
- protected function load_config($name, $conf_dir = NULL) {
- $file = is_null($conf_dir) ? '' : rtrim($conf_dir, '/') . '/';
- $file .= $name;
+ function set_service_name( $service_name ){
$this->ci->config->load($file, TRUE);
- $this->settings = $this->ci->config->item($file);
+ $settings = $this->ci->config->item($file);
+ var_dump( $settings ); exit ;
}
public function api( $endpoint_uri, $params = array(), $method = 'get' ){
- $endpoint_uri = $this->settings['url_api_base'] . $endpoint_uri ;
+ $endpoint_uri = $this->url_api_base . $endpoint_uri ;
return $this->ci->curl->{$method}( $endpoint_uri, $params );
}
}
View
@@ -882,7 +882,7 @@ protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
// The directory path can be included as part of the class name,
// but we don't want a leading slash
$class = str_replace('.php', '', trim($class, '/'));
-
+
// Was the path included with the class name?
// We look for a slash to determine this
$subdir = '';
@@ -899,12 +899,12 @@ protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
foreach (array(ucfirst($class), strtolower($class)) as $class)
{
$subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
-
+
// Is this a class extension request?
if (file_exists($subclass))
{
$baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
-
+
if ( ! file_exists($baseclass))
{
log_message('error', "Unable to load the requested class: ".$class);
@@ -937,17 +937,17 @@ protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
}
-
+
// Lets search for the requested library file and load it.
$is_duplicate = FALSE;
foreach ($this->_ci_library_paths as $path)
{
$filepath = $path.'libraries/'.$subdir.$class.'.php';
-
+
// Does the file exist? No? Bummer...
if ( ! file_exists($filepath))
{
- continue;
+ continue;
}
// Safety: Was the class already loaded by a previous call?
@@ -31,7 +31,7 @@ class CI_Driver_Library {
protected $valid_drivers = array();
protected $lib_name;
-
+
// The first time a child is used it won't exist, so we instantiate it
// subsequents calls will go straight to the proper child.
function __get($child)

0 comments on commit ff15cac

Please sign in to comment.