PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/googlemini/code/trunk/administrator/components/com_artofgm/libraries/joomla/client/http.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 107 lines | 52 code | 15 blank | 40 comment | 8 complexity | 4a6cdd47299e6a1263bdd2ebc06c851c MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: http.php 518 2011-01-07 06:36:43Z eddieajau $
  4. * @package Jentla
  5. * @subpackage com_jentlacert
  6. * @copyright Copyright 2011 New Life in IT Pty Ltd. All rights reserved.
  7. * @copyright Copyright 2010 Jentla Pty Ltd. All rights reserved.
  8. * @license GNU General Public License version 2 or later.
  9. * @link http://www.jentla.com
  10. * @author Andrew Eddie <andrew.eddie@newlifeinit.com>
  11. */
  12. // no direct access
  13. defined('_JEXEC') or die;
  14. /**
  15. * @package Jentla
  16. * @subpackage com_jentlacert
  17. * @since 1.0
  18. */
  19. abstract class JHTTP
  20. {
  21. /**
  22. * @var array Connector options.
  23. * @since 1.0
  24. */
  25. protected $options = array();
  26. /**
  27. * Magic get method.
  28. *
  29. * @param string $name The name of the property
  30. *
  31. * @return mixed The value of the property or proxy or null if not found.
  32. * @throws Exception
  33. */
  34. protected function __get($name)
  35. {
  36. switch ($name)
  37. {
  38. case 'proxy_host':
  39. case 'proxy_port':
  40. case 'proxy_user':
  41. case 'proxy_pass':
  42. case 'timeout':
  43. if (isset($this->options[$name])) {
  44. return trim($this->options[$name]);
  45. }
  46. break;
  47. default:
  48. throw new Exception('Undefined property via __get: '.$name);
  49. break;
  50. }
  51. return null;
  52. }
  53. /**
  54. * Get an instance of a HTTP connector class.
  55. *
  56. * @param string $type The type of HTTP connector: fopen|curl
  57. * @param array $options Options for the connector.
  58. *
  59. * @return JHTTP An instance of a JHTTP derived class.
  60. * @throws Exception
  61. */
  62. public function getInstance($type = 'fopen', $options = array())
  63. {
  64. static $instances;
  65. if (!isset($instances)) {
  66. $instances = array();
  67. }
  68. $type = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
  69. $signature = $type.serialize($options);
  70. if (empty($instances[$signature])) {
  71. // Check if the user has preloaded a custom type.
  72. $className = 'JHTTP'.$type;
  73. if (!class_exists($className)) {
  74. $path = dirname(__FILE__).'/http/'.$type.'.php';
  75. if (file_exists($path)) {
  76. require_once $path;
  77. // Just check again to see if the class loaded.
  78. if (!class_exists($className)) {
  79. throw new Exception(JText::sprintf('JLIB_ERROR_HTTP_ADAPTER_UNAVAILABLE', $type));
  80. }
  81. }
  82. else {
  83. throw new Exception(JText::sprintf('JLIB_ERROR_HTTP_ADAPTER_UNAVAILABLE', $type));
  84. }
  85. }
  86. // Constructor can throw an exception if there is a problem.
  87. $instance = new $className($options);
  88. $instances[$signature] = $instance;
  89. }
  90. return $instances[$signature];
  91. }
  92. }