Skip to content
This repository

We need namespace! #39

Closed
wants to merge 8 commits into from

5 participants

Erwänn Mest David Guyon Matt Harris William Durand Dieter Van der Stock
Erwänn Mest
kud commented

No description provided.

Erwänn Mest
kud commented

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

David Guyon

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

Matt Harris
Owner

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

William Durand

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 ;)

David Guyon

@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.

Erwänn Mest
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?

William Durand

@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!

Erwänn Mest
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. ;)

Dieter Van der Stock

+1 on including the composer file btw :-)

Matt Harris

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.

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

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.

Matt Harris themattharris referenced this pull request
Closed

Namespace & PSR-0 #77

Matt Harris themattharris referenced this pull request from a commit
Matt Harris 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
This page is out of date. Refresh to see the latest.
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +vendor
9 README.md
Source Rendered
... ... @@ -1,6 +1,6 @@
1   -# tmhOAuth
  1 +# TmhOAuth
2 2
3   -An OAuth 1.0A library written in PHP by @themattharris, specifically for use
  3 +An OAuth 1.0A library written in PHP by @themattharris, helped by @_erwann, specifically for use
4 4 with the Twitter API.
5 5
6 6 **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.
48 48
49 49 ## Change History ##
50 50
  51 +### 0.7 - 27 March 2012
  52 +- Change all the structure to be good with PSR-0
  53 +- Add namespace
  54 +- Add composer
  55 +
51 56 ### 0.62 - 01 March 2012
52 57 - Fix array merging bug. Props: julien-c
53 58 - use is_callable instead of function_exists: Props: samwierema
21 composer.json
... ... @@ -0,0 +1,21 @@
  1 +{
  2 + "name": "themattharris/tmhoauth",
  3 + "type": "library",
  4 + "description": "An OAuth 1.0A library written in PHP",
  5 + "authors": [
  6 + {
  7 + "name": "Matt Harris",
  8 + "email": "matt@themattharris.com"
  9 + },
  10 + {
  11 + "name": "Erwann MEST",
  12 + "email": "erwann.mest@gmail.com"
  13 + }
  14 + ],
  15 + "require": {},
  16 + "autoload": {
  17 + "psr-0": {
  18 + "Themattharris" : "src"
  19 + }
  20 + }
  21 +}
20 tmhOAuth.php → src/Themattharris/TmhOAuth.php
@@ -11,7 +11,9 @@
11 11 *
12 12 * 01 March 2012
13 13 */
14   -class tmhOAuth {
  14 +namespace Themattharris;
  15 +
  16 +class TmhOAuth {
15 17 const VERSION = 0.62;
16 18
17 19 /**
@@ -19,7 +21,7 @@ class tmhOAuth {
19 21 *
20 22 * @param string $config, the configuration to use for this request
21 23 */
22   - function __construct($config) {
  24 + public function __construct($config) {
23 25 $this->params = array();
24 26 $this->headers = array();
25 27 $this->auto_fixed_time = false;
@@ -83,7 +85,7 @@ function __construct($config) {
83 85 $this->set_user_agent();
84 86 }
85 87
86   - function set_user_agent() {
  88 + public function set_user_agent() {
87 89 if (!empty($this->config['user_agent']))
88 90 return;
89 91
@@ -196,7 +198,7 @@ private function get_defaults() {
196 198 * @param string $body the response body from an OAuth flow method
197 199 * @return array the response body safely decoded to an array of key => values
198 200 */
199   - function extract_params($body) {
  201 + public function extract_params($body) {
200 202 $kvs = explode('&', $body);
201 203 $decoded = array();
202 204 foreach ($kvs as $kv) {
@@ -386,7 +388,7 @@ private function sign($method, $url, $params, $useauth) {
386 388 * @param string $useauth whether to use authentication when making the request. Default true.
387 389 * @param string $multipart whether this request contains multipart data. Default false
388 390 */
389   - function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
  391 + public function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
390 392 $this->config['multipart'] = $multipart;
391 393
392 394 $this->create_nonce();
@@ -408,7 +410,7 @@ function request($method, $url, $params=array(), $useauth=true, $multipart=false
408 410 * @param array $params the request parameters as an array of key=value pairs
409 411 * @param string $callback the callback function to stream the buffer to.
410 412 */
411   - function streaming_request($method, $url, $params=array(), $callback='') {
  413 + public function streaming_request($method, $url, $params=array(), $callback='') {
412 414 if ( ! empty($callback) ) {
413 415 if ( ! is_callable($callback) ) {
414 416 return false;
@@ -428,7 +430,7 @@ function streaming_request($method, $url, $params=array(), $callback='') {
428 430 /**
429 431 * Handles the updating of the current Streaming API metrics.
430 432 */
431   - function update_metrics() {
  433 + public function update_metrics() {
432 434 $now = time();
433 435 if (($this->metrics['interval_start'] + $this->config['streaming_metrics_interval']) > $now)
434 436 return false;
@@ -449,7 +451,7 @@ function update_metrics() {
449 451 * @param string $format the format of the response. Default json. Set to an empty string to exclude the format
450 452 * @return string the concatenation of the host, API version, API method and format
451 453 */
452   - function url($request, $format='json') {
  454 + public function url($request, $format='json') {
453 455 $format = strlen($format) > 0 ? ".$format" : '';
454 456 $proto = $this->config['use_ssl'] ? 'https:/' : 'http:/';
455 457
@@ -471,7 +473,7 @@ function url($request, $format='json') {
471 473 * @param string $mode the transformation mode. either encode or decode
472 474 * @return the string as transformed by the given mode
473 475 */
474   - function transformText($text, $mode='encode') {
  476 + public function transformText($text, $mode='encode') {
475 477 return $this->{"safe_$mode"}($text);
476 478 }
477 479
24 tmhUtilities.php → src/Themattharris/TmhUtilities.php
@@ -9,7 +9,9 @@
9 9 *
10 10 * 01 March 2012
11 11 */
12   -class tmhUtilities {
  12 +namespace Themattharris;
  13 +
  14 +class TmhUtilities {
13 15 /**
14 16 * Entifies the tweet using the given entities element.
15 17 * Deprecated.
@@ -19,8 +21,8 @@ class tmhUtilities {
19 21 * @param array $replacements if specified, the entities and their replacements will be stored to this variable
20 22 * @return the tweet text with entities replaced with hyperlinks
21 23 */
22   - function entify($tweet, &$replacements=array()) {
23   - return tmhUtilities::entify_with_options($tweet, array(), $replacements);
  24 + public function entify($tweet, &$replacements=array()) {
  25 + return self::entify_with_options($tweet, array(), $replacements);
24 26 }
25 27
26 28 /**
@@ -32,7 +34,7 @@ function entify($tweet, &$replacements=array()) {
32 34 * @param array $replacements if specified, the entities and their replacements will be stored to this variable
33 35 * @return the tweet text with entities replaced with hyperlinks
34 36 */
35   - function entify_with_options($tweet, $options=array(), &$replacements=array()) {
  37 + public function entify_with_options($tweet, $options=array(), &$replacements=array()) {
36 38 $default_opts = array(
37 39 'encoding' => 'UTF-8',
38 40 'target' => '',
@@ -108,7 +110,7 @@ function entify_with_options($tweet, $options=array(), &$replacements=array()) {
108 110 * @param bool $dropqs whether to drop the querystring or not. Default true
109 111 * @return string the current URL
110 112 */
111   - function php_self($dropqs=true) {
  113 + public function php_self($dropqs=true) {
112 114 $protocol = 'http';
113 115 if (strtolower($_SERVER['HTTPS']) == 'on') {
114 116 $protocol = 'https';
@@ -143,7 +145,7 @@ function php_self($dropqs=true) {
143 145 return $url;
144 146 }
145 147
146   - function is_cli() {
  148 + public function is_cli() {
147 149 return (PHP_SAPI == 'cli' && empty($_SERVER['REMOTE_ADDR']));
148 150 }
149 151
@@ -152,7 +154,7 @@ function is_cli() {
152 154 *
153 155 * @param mixes $obj
154 156 */
155   - function pr($obj) {
  157 + public function pr($obj) {
156 158
157 159 if (!self::is_cli())
158 160 echo '<pre style="word-wrap: break-word">';
@@ -184,7 +186,7 @@ function pr($obj) {
184 186 * @param string $useauth whether to use authentication when making the request. Default true.
185 187 * @param string $multipart whether this request contains multipart data. Default false
186 188 */
187   - function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
  189 + public function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
188 190 $tmhOAuth->request($method, $url, $params, $useauth, $multipart);
189 191
190 192 // 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
213 215 * @param string $prompt the text to display to the user
214 216 * @return the text entered by the user
215 217 */
216   - function read_input($prompt) {
  218 + public function read_input($prompt) {
217 219 echo $prompt;
218 220 $handle = fopen("php://stdin","r");
219 221 $data = fgets($handle);
@@ -229,7 +231,7 @@ function read_input($prompt) {
229 231 * @return string
230 232 * @url http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
231 233 */
232   - function read_password($prompt, $stars=false) {
  234 + public function read_password($prompt, $stars=false) {
233 235 echo $prompt;
234 236 $style = shell_exec('stty -g');
235 237
@@ -268,7 +270,7 @@ function read_password($prompt, $stars=false) {
268 270 * @param string $needle the string to check $haystack ends with
269 271 * @return true if $haystack ends with $needle, false otherwise
270 272 */
271   - function endswith($haystack, $needle) {
  273 + public function endswith($haystack, $needle) {
272 274 $haylen = strlen($haystack);
273 275 $needlelen = strlen($needle);
274 276 if ($needlelen > $haylen)
0  cacert.pem → src/Themattharris/cacert.pem
File renamed without changes

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.