Nirvanix.php 3.5 KB

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