This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/oauth/classes/Kohana/OAuth/API.php

86 lines
1.5 KiB
PHP
Raw Normal View History

2013-05-27 12:10:41 +00:00
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* OAuth API
*
* @package OAuth
* @category Classes
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class Kohana_OAuth_API {
/**
* @var string profile data
*/
protected $profile;
/**
* Create a new API object.
*
* $API = OAuth_API::factory($name);
*
* @param string API type
* @param array API options
* @return OAuth_API
*/
public static function factory(OAuth_Provider $provider, $name, array $options = NULL)
{
$class = 'OAuth_API_'.ucfirst($name).'_'.ucfirst($provider->name);
return new $class($options);
}
/**
* @var string required parameters
*/
protected $required = array(
'profile',
);
/**
* Sets the API data.
*
* @param array API options
* @return void
*/
public function __construct(array $options = NULL)
{
foreach ($this->required as $key)
{
if ( ! isset($options[$key]))
{
throw new Kohana_OAuth_Exception('Required option not passed: :option',
array(':option' => $key));
}
$this->$key = $options[$key];
}
}
/**
* Return the value of any protected class variable.
*
* // Get the API details
* $secret = $api->id;
*
* @param string variable name
* @return mixed
*/
public function __get($key)
{
return $this->$key;
}
/**
* Returns the API key.
*
* @return string
*/
public function __toString()
{
return (string) $this->profile;
}
} // End OAuth_API