Nirvanix.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage Nirvanix
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Loader
  23. */
  24. require_once 'Zend/Loader.php';
  25. /**
  26. * @see Zend_Http_Client
  27. */
  28. require_once 'Zend/Http/Client.php';
  29. /**
  30. * This class allows Nirvanix authentication credentials to be specified
  31. * in one place and provides a factory for returning convenience wrappers
  32. * around the Nirvanix web service namespaces.
  33. *
  34. * @category Zend
  35. * @package Zend_Service
  36. * @subpackage Nirvanix
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Service_Nirvanix
  41. {
  42. /**
  43. * Options to pass to namespace proxies
  44. * @param array
  45. */
  46. protected $_options;
  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. // login and save sessionToken to default POST params
  64. $resp = $this->getService('Authentication')->login($authParams);
  65. $this->_options['defaults']['sessionToken'] = (string)$resp->SessionToken;
  66. }
  67. /**
  68. * Nirvanix divides its service into namespaces, with each namespace
  69. * providing different functionality. This is a factory method that
  70. * returns a preconfigured Zend_Service_Nirvanix_Namespace_Base proxy.
  71. *
  72. * @param string $namespace Name of the namespace
  73. * @return Zend_Service_Nirvanix_Namespace_Base
  74. */
  75. public function getService($namespace, $options = array())
  76. {
  77. switch ($namespace) {
  78. case 'IMFS':
  79. $class = 'Zend_Service_Nirvanix_Namespace_Imfs';
  80. break;
  81. default:
  82. $class = 'Zend_Service_Nirvanix_Namespace_Base';
  83. }
  84. $options['namespace'] = ucfirst($namespace);
  85. $options = array_merge($this->_options, $options);
  86. Zend_Loader::loadClass($class);
  87. return new $class($options);
  88. }
  89. /**
  90. * Get the configured options.
  91. *
  92. * @return array
  93. */
  94. public function getOptions()
  95. {
  96. return $this->_options;
  97. }
  98. }