Skip to content

We need namespace! #39

Closed
wants to merge 8 commits into from
View
1 .gitignore
@@ -0,0 +1 @@
+vendor
View
9 README.md
@@ -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
@@ -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
View
21 composer.json
@@ -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"
+ }
+ }
+}
View
20 tmhOAuth.php → src/Themattharris/TmhOAuth.php
@@ -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;
@@ -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;
@@ -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) {
@@ -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();
@@ -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;
@@ -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;
@@ -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:/';
@@ -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);
}
View
24 tmhUtilities.php → src/Themattharris/TmhUtilities.php
@@ -9,7 +9,9 @@
*
* 01 March 2012
*/
-class tmhUtilities {
+namespace Themattharris;
+
+class TmhUtilities {
/**
* Entifies the tweet using the given entities element.
* Deprecated.
@@ -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);
}
/**
@@ -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' => '',
@@ -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';
@@ -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']));
}
@@ -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">';
@@ -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
@@ -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);
@@ -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');
@@ -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)
View
0 cacert.pem → src/Themattharris/cacert.pem
File renamed without changes.
Something went wrong with that request. Please try again.