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

/administrator/components/com_lyftenbloggie/framework/core/error.php

https://github.com/linkatic/Cultunet
PHP | 121 lines | 48 code | 15 blank | 58 comment | 7 complexity | afc62e5622485192ae5c4b2892be5ad6 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * LyftenBloggie 1.1.0 - Joomla! Blog Manager
  4. * @package LyftenBloggie 1.1.0
  5. * @copyright (C) 2009-2010 Lyften Designs
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. * @link http://www.lyften.com/ Official website
  8. **/
  9. // Disallow direct access to this file
  10. defined('_JEXEC') or die('Restricted access');
  11. /**
  12. * LyftenBloggie Framework Error class
  13. *
  14. * @static
  15. * @package LyftenBloggie
  16. * @since 1.1.0
  17. **/
  18. class BloggieError
  19. {
  20. var $_errors = array();
  21. /**
  22. * Get BloggieError instance
  23. *
  24. * @return object BloggieError object
  25. **/
  26. function &getInstance() {
  27. static $instance;
  28. if (!isset($instance)) {
  29. $instance = new BloggieError();
  30. }
  31. return $instance;
  32. }
  33. /**
  34. * Get the most recent error message
  35. *
  36. * @param string option error index
  37. * @param string indicates if jerror objects should return their error message
  38. * @return string error message
  39. **/
  40. function getError($i = null, $toString = true) {
  41. $error =& BloggieError::getInstance();
  42. return $error->get($i, $toString);
  43. }
  44. /**
  45. * Return all errors, if any
  46. *
  47. * @return array error message array
  48. **/
  49. function getErrors() {
  50. $error =& BloggieError::getInstance();
  51. return $error->getAll();
  52. }
  53. /**
  54. * Static. Add an error message
  55. *
  56. * @return void
  57. **/
  58. function setError($e)
  59. {
  60. $error =& BloggieError::getInstance();
  61. $error->set($e);
  62. }
  63. /**
  64. * Get the most recent error message
  65. *
  66. * @param string option error index
  67. * @param string indicates if jerror objects should return their error message
  68. * @return string error message
  69. **/
  70. function get($i = null, $toString = true)
  71. {
  72. // find the error
  73. if ($i === null) {
  74. // default, return the last message
  75. $error = end($this->_errors);
  76. } else if (!array_key_exists($i, $this->_errors)) {
  77. // if $i has been specified but does not exist, return false
  78. return false;
  79. } else {
  80. $error = $this->_errors[$i];
  81. }
  82. // check if only the string is requested
  83. if (JError::isError($error) && $toString) {
  84. return $error->toString();
  85. }
  86. return $error;
  87. }
  88. /**
  89. * Return all errors, if any
  90. *
  91. * @return array error message array
  92. **/
  93. function getAll()
  94. {
  95. return $this->_errors;
  96. }
  97. /**
  98. * Add an error message
  99. *
  100. * @return void
  101. **/
  102. function set($error)
  103. {
  104. array_push($this->_errors, $error);
  105. }
  106. }