Nirvanix.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_Http_Client
  23. */
  24. require_once 'Zend/Http/Client.php';
  25. /**
  26. * This class allows Nirvanix authentication credentials to be specified
  27. * in one place and provides a factory for returning convenience wrappers
  28. * around the Nirvanix web service namespaces.
  29. *
  30. * @category Zend
  31. * @package Zend_Service
  32. * @subpackage Nirvanix
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Service_Nirvanix
  37. {
  38. /**
  39. * Options to pass to namespace proxies
  40. * @param array
  41. */
  42. protected $_options;
  43. /**
  44. * Class constructor. Authenticates with Nirvanix to receive a
  45. * sessionToken, which is then passed to each future request.
  46. *
  47. * @param array $authParams Authentication POST parameters. This
  48. * should have keys "username", "password",
  49. * and "appKey".
  50. * @param array $options Options to pass to namespace proxies
  51. */
  52. public function __construct($authParams, $options = array())
  53. {
  54. // merge options with default options
  55. $defaultOptions = array('defaults' => array(),
  56. 'httpClient' => new Zend_Http_Client(),
  57. 'host' => 'http://services.nirvanix.com');
  58. $this->_options = array_merge($defaultOptions, $options);
  59. // login and save sessionToken to default POST params
  60. $resp = $this->getService('Authentication')->login($authParams);
  61. $this->_options['defaults']['sessionToken'] = (string)$resp->SessionToken;
  62. }
  63. /**
  64. * Nirvanix divides its service into namespaces, with each namespace
  65. * providing different functionality. This is a factory method that
  66. * returns a preconfigured Zend_Service_Nirvanix_Namespace_Base proxy.
  67. *
  68. * @param string $namespace Name of the namespace
  69. * @return Zend_Service_Nirvanix_Namespace_Base
  70. */
  71. public function getService($namespace, $options = array())
  72. {
  73. switch ($namespace) {
  74. case 'IMFS':
  75. $class = 'Zend_Service_Nirvanix_Namespace_Imfs';
  76. break;
  77. default:
  78. $class = 'Zend_Service_Nirvanix_Namespace_Base';
  79. }
  80. $options['namespace'] = ucfirst($namespace);
  81. $options = array_merge($this->_options, $options);
  82. if (!class_exists($class)) {
  83. require_once 'Zend/Loader.php';
  84. Zend_Loader::loadClass($class);
  85. }
  86. return new $class($options);
  87. }
  88. /**
  89. * Get the configured options.
  90. *
  91. * @return array
  92. */
  93. public function getOptions()
  94. {
  95. return $this->_options;
  96. }
  97. }