/plugin/PBAPI/PBAPI/Response.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/ · PHP · 75 lines · 19 code · 8 blank · 48 comment · 2 complexity · fd9e1ac773f6c37a86fd06e7ca82d168 MD5 · raw file

  1. <?php
  2. /**
  3. * Photobucket API
  4. * Fluent interface for PHP5
  5. * Response parent class
  6. *
  7. * @author jhart
  8. * @package PBAPI
  9. *
  10. * @copyright Copyright (c) 2008, Photobucket, Inc.
  11. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  12. */
  13. /**
  14. * Response parser parent class
  15. *
  16. * @package PBAPI
  17. */
  18. abstract class PBAPI_Response
  19. {
  20. /**
  21. * Result data
  22. *
  23. * @var array
  24. */
  25. protected $result_data = array();
  26. /**
  27. * parameter holder
  28. *
  29. * @var array
  30. */
  31. protected $params = array();
  32. /**
  33. * Class constructor
  34. *
  35. * @param array $params
  36. */
  37. public function __construct($params = array())
  38. {
  39. $this->params = $params;
  40. }
  41. /**
  42. * Parse response
  43. *
  44. * @param string $response_string string to parse
  45. * @param bool $onlycontent only return content 'node'
  46. * @return string
  47. */
  48. abstract public function parse($string, $onlycontent = false);
  49. /**
  50. * Detect an exception response and throw a code exception
  51. *
  52. * @param array $data parsed data from parser strategy
  53. */
  54. protected function detectException(array $data)
  55. {
  56. if ($data['status'] != 'OK')
  57. {
  58. throw new PBAPI_Exception_Response($data['message'], $data['code']);
  59. }
  60. }
  61. /**
  62. * Returns optimal format for given parser
  63. *
  64. * @return string
  65. */
  66. abstract public function getFormat();
  67. }