Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We need namespace! #39

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tmhOAuth
# TmhOAuth

An OAuth 1.0A library written in PHP by @themattharris, specifically for use
An OAuth 1.0A library written in PHP by @themattharris, helped by @_erwann, specifically for use
with the Twitter API.

**Disclaimer**: This project is a work in progress. Please use the issue tracker
Expand Down Expand Up @@ -48,6 +48,11 @@ you should now define them as `'key' => 'value'` pairs.

## Change History ##

### 0.7 - 27 March 2012
- Change all the structure to be good with PSR-0
- Add namespace
- Add composer

### 0.62 - 01 March 2012
- Fix array merging bug. Props: julien-c
- use is_callable instead of function_exists: Props: samwierema
Expand Down
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "themattharris/tmhoauth",
"type": "library",
"description": "An OAuth 1.0A library written in PHP",
"authors": [
{
"name": "Matt Harris",
"email": "matt@themattharris.com"
},
{
"name": "Erwann MEST",
"email": "erwann.mest@gmail.com"
}
],
"require": {},
"autoload": {
"psr-0": {
"Themattharris" : "src"
}
}
}
20 changes: 11 additions & 9 deletions tmhOAuth.php → src/Themattharris/TmhOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
*
* 01 March 2012
*/
class tmhOAuth {
namespace Themattharris;

class TmhOAuth {
const VERSION = 0.62;

/**
* Creates a new tmhOAuth object
*
* @param string $config, the configuration to use for this request
*/
function __construct($config) {
public function __construct($config) {
$this->params = array();
$this->headers = array();
$this->auto_fixed_time = false;
Expand Down Expand Up @@ -83,7 +85,7 @@ function __construct($config) {
$this->set_user_agent();
}

function set_user_agent() {
public function set_user_agent() {
if (!empty($this->config['user_agent']))
return;

Expand Down Expand Up @@ -196,7 +198,7 @@ private function get_defaults() {
* @param string $body the response body from an OAuth flow method
* @return array the response body safely decoded to an array of key => values
*/
function extract_params($body) {
public function extract_params($body) {
$kvs = explode('&', $body);
$decoded = array();
foreach ($kvs as $kv) {
Expand Down Expand Up @@ -386,7 +388,7 @@ private function sign($method, $url, $params, $useauth) {
* @param string $useauth whether to use authentication when making the request. Default true.
* @param string $multipart whether this request contains multipart data. Default false
*/
function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
public function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
$this->config['multipart'] = $multipart;

$this->create_nonce();
Expand All @@ -408,7 +410,7 @@ function request($method, $url, $params=array(), $useauth=true, $multipart=false
* @param array $params the request parameters as an array of key=value pairs
* @param string $callback the callback function to stream the buffer to.
*/
function streaming_request($method, $url, $params=array(), $callback='') {
public function streaming_request($method, $url, $params=array(), $callback='') {
if ( ! empty($callback) ) {
if ( ! is_callable($callback) ) {
return false;
Expand All @@ -428,7 +430,7 @@ function streaming_request($method, $url, $params=array(), $callback='') {
/**
* Handles the updating of the current Streaming API metrics.
*/
function update_metrics() {
public function update_metrics() {
$now = time();
if (($this->metrics['interval_start'] + $this->config['streaming_metrics_interval']) > $now)
return false;
Expand All @@ -449,7 +451,7 @@ function update_metrics() {
* @param string $format the format of the response. Default json. Set to an empty string to exclude the format
* @return string the concatenation of the host, API version, API method and format
*/
function url($request, $format='json') {
public function url($request, $format='json') {
$format = strlen($format) > 0 ? ".$format" : '';
$proto = $this->config['use_ssl'] ? 'https:/' : 'http:/';

Expand All @@ -471,7 +473,7 @@ function url($request, $format='json') {
* @param string $mode the transformation mode. either encode or decode
* @return the string as transformed by the given mode
*/
function transformText($text, $mode='encode') {
public function transformText($text, $mode='encode') {
return $this->{"safe_$mode"}($text);
}

Expand Down
24 changes: 13 additions & 11 deletions tmhUtilities.php → src/Themattharris/TmhUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
*
* 01 March 2012
*/
class tmhUtilities {
namespace Themattharris;

class TmhUtilities {
/**
* Entifies the tweet using the given entities element.
* Deprecated.
Expand All @@ -19,8 +21,8 @@ class tmhUtilities {
* @param array $replacements if specified, the entities and their replacements will be stored to this variable
* @return the tweet text with entities replaced with hyperlinks
*/
function entify($tweet, &$replacements=array()) {
return tmhUtilities::entify_with_options($tweet, array(), $replacements);
public function entify($tweet, &$replacements=array()) {
return self::entify_with_options($tweet, array(), $replacements);
}

/**
Expand All @@ -32,7 +34,7 @@ function entify($tweet, &$replacements=array()) {
* @param array $replacements if specified, the entities and their replacements will be stored to this variable
* @return the tweet text with entities replaced with hyperlinks
*/
function entify_with_options($tweet, $options=array(), &$replacements=array()) {
public function entify_with_options($tweet, $options=array(), &$replacements=array()) {
$default_opts = array(
'encoding' => 'UTF-8',
'target' => '',
Expand Down Expand Up @@ -108,7 +110,7 @@ function entify_with_options($tweet, $options=array(), &$replacements=array()) {
* @param bool $dropqs whether to drop the querystring or not. Default true
* @return string the current URL
*/
function php_self($dropqs=true) {
public function php_self($dropqs=true) {
$protocol = 'http';
if (strtolower($_SERVER['HTTPS']) == 'on') {
$protocol = 'https';
Expand Down Expand Up @@ -143,7 +145,7 @@ function php_self($dropqs=true) {
return $url;
}

function is_cli() {
public function is_cli() {
return (PHP_SAPI == 'cli' && empty($_SERVER['REMOTE_ADDR']));
}

Expand All @@ -152,7 +154,7 @@ function is_cli() {
*
* @param mixes $obj
*/
function pr($obj) {
public function pr($obj) {

if (!self::is_cli())
echo '<pre style="word-wrap: break-word">';
Expand Down Expand Up @@ -184,7 +186,7 @@ function pr($obj) {
* @param string $useauth whether to use authentication when making the request. Default true.
* @param string $multipart whether this request contains multipart data. Default false
*/
function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
public function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
$tmhOAuth->request($method, $url, $params, $useauth, $multipart);

// if we're not doing auth the timestamp isn't important
Expand Down Expand Up @@ -213,7 +215,7 @@ function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useau
* @param string $prompt the text to display to the user
* @return the text entered by the user
*/
function read_input($prompt) {
public function read_input($prompt) {
echo $prompt;
$handle = fopen("php://stdin","r");
$data = fgets($handle);
Expand All @@ -229,7 +231,7 @@ function read_input($prompt) {
* @return string
* @url http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
*/
function read_password($prompt, $stars=false) {
public function read_password($prompt, $stars=false) {
echo $prompt;
$style = shell_exec('stty -g');

Expand Down Expand Up @@ -268,7 +270,7 @@ function read_password($prompt, $stars=false) {
* @param string $needle the string to check $haystack ends with
* @return true if $haystack ends with $needle, false otherwise
*/
function endswith($haystack, $needle) {
public function endswith($haystack, $needle) {
$haylen = strlen($haystack);
$needlelen = strlen($needle);
if ($needlelen > $haylen)
Expand Down
File renamed without changes.