Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

We need namespace! #39

Closed
wants to merge 8 commits into from

5 participants

@kud

No description provided.

@kud

Hmmm maybe it ain't the correct namespace but please add one. ;)

@dguyon

At least, this library need to be autoloaded following PSR-0 namespace conventions or either prefix conventions.

@themattharris

I'm interested in the motivation behind adhering to PSR-0 and including namespaces while PHP 5.2 is still so widely used.

@willdurand

Ok folks, you can use this lib without adding anything, even with Composer, and/or a namespaced environment. The default NS is \ afterall.

Extract of my composer.json:

{                                                                                                                                                        
    "require": {
        "php": ">=5.3.2",
        "themattharris/thm-oauth": "0.0.61"
    },
    "repositories": {
        "tmh-oauth": {
            "type": "package",
            "package": {
                "name": "themattharris/thm-oauth",
                "version": "0.0.61",
                "dist": {
                    "url": "https://github.com/themattharris/tmhOAuth/zipball/v0.61",
                    "type": "zip"
                },  
                "source": {
                    "url": "https://github.com/themattharris/tmhOAuth.git",
                    "type": "git",
                    "reference": "v0.61"
                }   
            }   
        }   
    }
}

I guess you can add a classmap section to get classes autoloaded by default.

@themattharris to provide a composer.json file is more than enough IMO, and I would be glad to see this file in your awesome library.

@kud be fair, and don't add yourself to the authors list ;)

@dguyon

@willdurand you're right for Composer but the main idea was to benefit from PHP 5.3 features maybe with creating a dedicated branch for this library rather than replacing it for < PHP 5.2.

@themattharris to provide a composer.json file is more than enough IMO, and I would be glad to see this file in your  awesome library.

Yes please do that ! I'm inviting you to read the Composer documentation in order to do so.

@kud
kud commented

@willdurand Wait wait wait Will. I think there's a mistake in my merge. If I added me in authors list, it's onlye because I'm working on a restructuration of all the lib, available here; https://github.com/kud/tmhoauth (it's not finished), and I prefer that people come back to me if there's a composer mistake, but in any case I wanted to say it's my lib. For sure.

In fact, I'm working on the silex service provider (https://github.com/kud/tmhoauth-silex-service-provider) of this lib and I think I need to change the paths of the lib to respect PSR-0. But maybe yeah I'm wrong?

@willdurand

@themattharris Composer is a new dependency manager for PHP. It allows you to specify dependencies on a per-project basis. It takes lots of inspiration from NPM and ruby's bundler.

All you need to support composer is a composer.json file. In order to allow easy installation, the repository needs to be added to packagist, which is the standard repository for composer. Packagist will fetch all the versions from your github repository tags.

Once it has been added, adding tmhOAuth to a project will be as easy as creating this composer.json file in the project's directory:

{
    "require": {
        "themattharris/tmhOAuth": "*"
    }
}

And running this command:

$ php composer.phar install

Note: Packagist will re-crawl github for new versions all the time. After submitting it once, you don't have to do anything else.

Check out the following information on composer and packagist:

@dguyon to have a PHP 5.3 compliant lib definitely makes sense, that's right.

@kud yeah, looks better on your own fork right, my apologies then. Didn't see you've worked a lot. Nice to see a Silex Provider for this lib btw, good job!

@kud
kud commented

@willdurand No problem, I'll finish it soon as possible and will try to do a pull request but I could understand that @themattharris doesn't approve all these modifications. ;)

@dietervds

+1 on including the composer file btw :-)

@themattharris themattharris referenced this pull request
Closed

Support for Composer #54

@themattharris

i'm going to tackle this on 0.7.1.
i'll comment again when i have a test branch with this setup in it.

@philsturgeon philsturgeon referenced this pull request
Closed

Adding Composer Support #85

@themattharris themattharris referenced this pull request from a commit
@themattharris introduce composer.json. Issues #39,#77,#85. Props: akandels, conradk…
…leinespel, dguyon, kud, philsturgeon, willdurand
8b3a81c
@themattharris

ok i've committed a variant of the pull request to the 0.7.2-devel branch. i'm closing this and issue #77 out in favor of tracking all of it under one ticket -- #85. please add any feedback or comments there.

@themattharris themattharris referenced this pull request
Closed

Namespace & PSR-0 #77

@themattharris themattharris referenced this pull request from a commit
@themattharris Version 0.7.2
- use DIRECTORY_SEPARATOR for multi-environment support. (Issue #80) Props: whallz
- tidied up the curlHeader function to use explode instead of substr and store the keys in the format they are returned from the API
- removed content-length hack as it isn't needed if CURLOPT_POSTFIELDS is initialized on all POSTs
- removed the expects header hack as Twitter no longer requires it to be there
- introduce composer.json. (Issues #39, #77, #85) Props: akandels, conradkleinespel, dguyon, kud, philsturgeon, willdurand
- added support for specifying custom headers when using $tmhOAuth->request. (Issue #98)
6c4a2ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 22, 2012
  1. @kud

    A bit more PHP 5.3.

    kud authored
Commits on Mar 24, 2012
  1. @kud

    Add a new namespace. Cf PSR-0

    kud authored
Commits on Mar 26, 2012
  1. @kud

    Fix namespace.

    kud authored
Commits on Mar 27, 2012
  1. @kud

    Change namespace

    kud authored
  2. @kud

    Fix name function

    kud authored
  3. @kud

    New structure.

    kud authored
  4. @kud
  5. @kud

    fix composer

    kud authored
This page is out of date. Refresh to see the latest.
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,7 +11,9 @@
*
* 01 March 2012
*/
-class tmhOAuth {
+namespace Themattharris;
+
+class TmhOAuth {
const VERSION = 0.62;
/**
@@ -19,7 +21,7 @@ class tmhOAuth {
*
* @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.