web/rsln/Zend/Oauth.php
author Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Fri, 21 Jan 2011 13:42:03 +0100
changeset 20 7e0a67a20e74
permissions -rw-r--r--
add new rsln page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     1
<?php
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     2
/**
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     3
 * Zend Framework
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     4
 *
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     5
 * LICENSE
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     6
 *
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     7
 * This source file is subject to the new BSD license that is bundled
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     8
 * with this package in the file LICENSE.txt.
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     9
 * It is also available through the world-wide-web at this URL:
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    10
 * http://framework.zend.com/license/new-bsd
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    11
 * If you did not receive a copy of the license and are unable to
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    12
 * obtain it through the world-wide-web, please send an email
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    13
 * to license@zend.com so we can send you a copy immediately.
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    14
 *
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    15
 * @category   Zend
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    16
 * @package    Zend_Oauth
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    17
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    18
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    19
 * @version    $Id: Oauth.php 21070 2010-02-16 14:34:25Z padraic $
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    20
 */
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    21
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    22
/** Zend_Http_Client */
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    23
require_once 'Zend/Http/Client.php';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    24
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    25
/**
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    26
 * @category   Zend
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    27
 * @package    Zend_Oauth
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    28
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    29
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    30
 */
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    31
class Zend_Oauth
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    32
{
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    33
    const REQUEST_SCHEME_HEADER      = 'header';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    34
    const REQUEST_SCHEME_POSTBODY    = 'postbody';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    35
    const REQUEST_SCHEME_QUERYSTRING = 'querystring';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    36
    const GET                        = 'GET';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    37
    const POST                       = 'POST';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    38
    const PUT                        = 'PUT';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    39
    const DELETE                     = 'DELETE';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    40
    const HEAD                       = 'HEAD';
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    41
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    42
    /**
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    43
     * Singleton instance if required of the HTTP client
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    44
     *
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    45
     * @var Zend_Http_Client
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    46
     */
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    47
    protected static $httpClient = null;
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    48
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    49
    /**
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    50
     * Allows the external environment to make Zend_Oauth use a specific
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    51
     * Client instance.
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    52
     *
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    53
     * @param Zend_Http_Client $httpClient
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    54
     * @return void
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    55
     */
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    56
    public static function setHttpClient(Zend_Http_Client $httpClient)
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    57
    {
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    58
        self::$httpClient = $httpClient;
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    59
    }
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    60
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    61
    /**
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    62
     * Return the singleton instance of the HTTP Client. Note that
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    63
     * the instance is reset and cleared of previous parameters and
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    64
     * Authorization header values.
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    65
     *
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    66
     * @return Zend_Http_Client
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    67
     */
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    68
    public static function getHttpClient()
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    69
    {
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    70
        if (!isset(self::$httpClient)) {
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    71
            self::$httpClient = new Zend_Http_Client;
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    72
        } else {
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    73
            self::$httpClient->setHeaders('Authorization', null);
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    74
            self::$httpClient->resetParameters();
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    75
        }
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    76
        return self::$httpClient;
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    77
    }
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    78
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    79
    /**
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    80
     * Simple mechanism to delete the entire singleton HTTP Client instance
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    81
     * which forces an new instantiation for subsequent requests.
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    82
     *
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    83
     * @return void
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    84
     */
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    85
    public static function clearHttpClient()
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    86
    {
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    87
        self::$httpClient = null;
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    88
    }
7e0a67a20e74 add new rsln page
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    89
}