[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Service/ -> Nirvanix.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Service
  17   * @subpackage Nirvanix
  18   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   * @version    $Id$
  21   */
  22  
  23  /**
  24   * @see Zend_Http_Client
  25   */
  26  require_once 'Zend/Http/Client.php';
  27  
  28  /**
  29   * This class allows Nirvanix authentication credentials to be specified
  30   * in one place and provides a factory for returning convenience wrappers
  31   * around the Nirvanix web service namespaces.
  32   *
  33   * @category   Zend
  34   * @package    Zend_Service
  35   * @subpackage Nirvanix
  36   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  37   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  38   */
  39  class Zend_Service_Nirvanix
  40  {
  41      /**
  42       * Options to pass to namespace proxies
  43       * @param array
  44       */
  45      protected $_options;
  46  
  47      /**
  48       * Class constructor.  Authenticates with Nirvanix to receive a
  49       * sessionToken, which is then passed to each future request.
  50       *
  51       * @param  array  $authParams  Authentication POST parameters.  This
  52       *                             should have keys "username", "password",
  53       *                             and "appKey".
  54       * @param  array  $options     Options to pass to namespace proxies
  55       */
  56      public function __construct($authParams, $options = array())
  57      {
  58          // merge options with default options
  59          $defaultOptions = array('defaults'   => array(),
  60                                  'httpClient' => new Zend_Http_Client(),
  61                                  'host'       => 'http://services.nirvanix.com');
  62          $this->_options = array_merge($defaultOptions, $options);
  63  
  64          // login and save sessionToken to default POST params
  65          $resp = $this->getService('Authentication')->login($authParams);
  66          $this->_options['defaults']['sessionToken'] = (string)$resp->SessionToken;
  67      }
  68  
  69      /**
  70       * Nirvanix divides its service into namespaces, with each namespace
  71       * providing different functionality.  This is a factory method that
  72       * returns a preconfigured Zend_Service_Nirvanix_Namespace_Base proxy.
  73       *
  74       * @param  string  $namespace  Name of the namespace
  75       * @return Zend_Service_Nirvanix_Namespace_Base
  76       */
  77      public function getService($namespace, $options = array())
  78      {
  79          switch ($namespace) {
  80              case 'IMFS':
  81                  $class = 'Zend_Service_Nirvanix_Namespace_Imfs';
  82                  break;
  83              default:
  84                  $class = 'Zend_Service_Nirvanix_Namespace_Base';
  85          }
  86  
  87          $options['namespace'] = ucfirst($namespace);
  88          $options = array_merge($this->_options, $options);
  89  
  90          if (!class_exists($class)) {
  91              require_once 'Zend/Loader.php';
  92              Zend_Loader::loadClass($class);
  93          }
  94          return new $class($options);
  95      }
  96  
  97      /**
  98       * Get the configured options.
  99       *
 100       * @return array
 101       */
 102      public function getOptions()
 103      {
 104          return $this->_options;
 105      }
 106  
 107  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1