PageRenderTime 28ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 19ms 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
  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 
 10// Disallow direct access to this file
 11defined('_JEXEC') or die('Restricted access');
 12
 13/**
 14 * LyftenBloggie Framework Error class
 15 *
 16 * @static
 17 * @package	LyftenBloggie
 18 * @since	1.1.0
 19 **/
 20class BloggieError
 21{
 22	var $_errors = array();
 23
 24	/**
 25	 * Get BloggieError instance
 26	 *
 27	 * @return	object  BloggieError object
 28	 **/
 29	function &getInstance() {
 30		static $instance;
 31
 32		if (!isset($instance)) {
 33			$instance = new BloggieError();
 34		}
 35		
 36		return $instance;
 37	}
 38
 39	/**
 40	 * Get the most recent error message
 41	 *
 42	 * @param	string	option error index
 43	 * @param	string	indicates if jerror objects should return their error message
 44	 * @return	string  error message
 45	 **/
 46	function getError($i = null, $toString = true) {
 47		$error =& BloggieError::getInstance();
 48		return $error->get($i, $toString);
 49	}
 50
 51	/**
 52	 * Return all errors, if any
 53	 *
 54	 * @return	array   error message array
 55	 **/
 56	function getErrors() {
 57		$error =& BloggieError::getInstance();
 58		return $error->getAll();
 59	}
 60
 61	/**
 62	 * Static. Add an error message
 63	 *
 64	 * @return	void
 65	 **/
 66	function setError($e)
 67	{
 68		$error =& BloggieError::getInstance();
 69		$error->set($e);
 70	}
 71
 72	/**
 73	 * Get the most recent error message
 74	 *
 75	 * @param	string	option error index
 76	 * @param	string	indicates if jerror objects should return their error message
 77	 * @return	string  error message
 78	 **/
 79	function get($i = null, $toString = true)
 80	{
 81
 82		// find the error
 83		if ($i === null) {
 84			// default, return the last message
 85			$error = end($this->_errors);
 86		} else if (!array_key_exists($i, $this->_errors)) {
 87			// if $i has been specified but does not exist, return false
 88			return false;
 89		} else {
 90			$error = $this->_errors[$i];
 91		}
 92
 93		// check if only the string is requested
 94		if (JError::isError($error) && $toString) {
 95			return $error->toString();
 96		}
 97
 98		return $error;
 99	}
100
101	/**
102	 * Return all errors, if any
103	 *
104	 * @return	array   error message array
105	 **/
106	function getAll()
107	{
108		return $this->_errors;
109	}
110
111	/**
112	 * Add an error message
113	 *
114	 * @return	void
115	 **/
116	function set($error)
117	{
118		array_push($this->_errors, $error);
119	}
120
121}