Source for file exception.php

Documentation is available at exception.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  Exception
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Joomla! Exception object.
  14.  *
  15.  * @package     Joomla.Legacy
  16.  * @subpackage  Exception
  17.  * @since       11.1
  18.  * @deprecated  12.1 (Platform) & 4.0 (CMS)
  19.  */
  20. class JException extends Exception
  21. {
  22.     /**
  23.      * @var    string  Error level.
  24.      * @since  11.1
  25.      */
  26.     protected $level = null;
  27.  
  28.     /**
  29.      * @var    string  Error code.
  30.      * @since  11.1
  31.      */
  32.     protected $code = null;
  33.  
  34.     /**
  35.      * @var    string  Error message.
  36.      * @since  11.1
  37.      */
  38.     protected $message = null;
  39.  
  40.     /**
  41.      * Additional info about the error relevant to the developer,
  42.      * for example, if a database connect fails, the dsn used
  43.      *
  44.      * @var    string 
  45.      * @since  11.1
  46.      */
  47.     protected $info = '';
  48.  
  49.     /**
  50.      * Name of the file the error occurred in [Available if backtrace is enabled]
  51.      *
  52.      * @var    string 
  53.      * @since  11.1
  54.      */
  55.     protected $file = null;
  56.  
  57.     /**
  58.      * Line number the error occurred in [Available if backtrace is enabled]
  59.      *
  60.      * @var    int 
  61.      * @since  11.1
  62.      */
  63.     protected $line = 0;
  64.  
  65.     /**
  66.      * Name of the method the error occurred in [Available if backtrace is enabled]
  67.      *
  68.      * @var    string 
  69.      * @since  11.1
  70.      */
  71.     protected $function = null;
  72.  
  73.     /**
  74.      * Name of the class the error occurred in [Available if backtrace is enabled]
  75.      *
  76.      * @var    string 
  77.      * @since  11.1
  78.      */
  79.     protected $class = null;
  80.  
  81.     /**
  82.      * @var    string  Error type.
  83.      * @since  11.1
  84.      */
  85.     protected $type = null;
  86.  
  87.     /**
  88.      * Arguments recieved by the method the error occurred in [Available if backtrace is enabled]
  89.      *
  90.      * @var    array 
  91.      * @since  11.1
  92.      */
  93.     protected $args = array();
  94.  
  95.     /**
  96.      * @var    mixed  Backtrace information.
  97.      * @since  11.1
  98.      */
  99.     protected $backtrace = null;
  100.  
  101.     /**
  102.      * Constructor
  103.      * - used to set up the error with all needed error details.
  104.      *
  105.      * @param   string   $msg        The error message
  106.      * @param   string   $code       The error code from the application
  107.      * @param   integer  $level      The error level (use the PHP constants E_ALL, E_NOTICE etc.).
  108.      * @param   string   $info       Optional: The additional error information.
  109.      * @param   boolean  $backtrace  True if backtrace information is to be collected
  110.      *
  111.      * @since   11.1
  112.      *
  113.      * @deprecated  12.1
  114.      */
  115.     public function __construct($msg$code 0$level null$info null$backtrace false)
  116.     {
  117.         JLog::add('JException is deprecated.'JLog::WARNING'deprecated');
  118.  
  119.         $this->level = $level;
  120.         $this->code = $code;
  121.         $this->message = $msg;
  122.  
  123.         if ($info != null)
  124.         {
  125.             $this->info = $info;
  126.         }
  127.  
  128.         if ($backtrace && function_exists('debug_backtrace'))
  129.         {
  130.             $this->backtrace = debug_backtrace();
  131.  
  132.             for ($i count($this->backtrace1$i >= 0--$i)
  133.             {
  134.                 ++$i;
  135.                 if (isset($this->backtrace[$i]['file']))
  136.                 {
  137.                     $this->file = $this->backtrace[$i]['file'];
  138.                 }
  139.                 if (isset($this->backtrace[$i]['line']))
  140.                 {
  141.                     $this->line = $this->backtrace[$i]['line'];
  142.                 }
  143.                 if (isset($this->backtrace[$i]['class']))
  144.                 {
  145.                     $this->class = $this->backtrace[$i]['class'];
  146.                 }
  147.                 if (isset($this->backtrace[$i]['function']))
  148.                 {
  149.                     $this->function = $this->backtrace[$i]['function'];
  150.                 }
  151.                 if (isset($this->backtrace[$i]['type']))
  152.                 {
  153.                     $this->type = $this->backtrace[$i]['type'];
  154.                 }
  155.  
  156.                 $this->args = false;
  157.                 if (isset($this->backtrace[$i]['args']))
  158.                 {
  159.                     $this->args = $this->backtrace[$i]['args'];
  160.                 }
  161.                 break;
  162.             }
  163.         }
  164.  
  165.         // Store exception for debugging purposes!
  166.         JError::addToStack($this);
  167.  
  168.         parent::__construct($msg(int) $code);
  169.     }
  170.  
  171.     /**
  172.      * Returns to error message
  173.      *
  174.      * @return  string  Error message
  175.      *
  176.      * @since   11.1
  177.      *
  178.      * @deprecated  12.1
  179.      */
  180.     public function __toString()
  181.     {
  182.         JLog::add('JException::__toString is deprecated.'JLog::WARNING'deprecated');
  183.  
  184.         return $this->message;
  185.     }
  186.  
  187.     /**
  188.      * Returns to error message
  189.      *
  190.      * @return  string   Error message
  191.      *
  192.      * @since   11.1
  193.      * @deprecated    12.1
  194.      */
  195.     public function toString()
  196.     {
  197.         JLog::add('JException::toString is deprecated.'JLog::WARNING'deprecated');
  198.  
  199.         return (string) $this;
  200.     }
  201.  
  202.     /**
  203.      * Returns a property of the object or the default value if the property is not set.
  204.      *
  205.      * @param   string  $property  The name of the property
  206.      * @param   mixed   $default   The default value
  207.      *
  208.      * @return  mixed  The value of the property or null
  209.      *
  210.      * @deprecated  12.1
  211.      * @see         JException::getProperties()
  212.      * @since       11.1
  213.      */
  214.     public function get($property$default null)
  215.     {
  216.         JLog::add('JException::get is deprecated.'JLog::WARNING'deprecated');
  217.  
  218.         if (isset($this->$property))
  219.         {
  220.             return $this->$property;
  221.         }
  222.         return $default;
  223.     }
  224.  
  225.     /**
  226.      * Returns an associative array of object properties
  227.      *
  228.      * @param   boolean  $public  If true, returns only the public properties
  229.      *
  230.      * @return  array  Object properties
  231.      *
  232.      * @deprecated    12.1
  233.      * @see     JException::get()
  234.      * @since   11.1
  235.      */
  236.     public function getProperties($public true)
  237.     {
  238.         JLog::add('JException::getProperties is deprecated.'JLog::WARNING'deprecated');
  239.  
  240.         $vars get_object_vars($this);
  241.         if ($public)
  242.         {
  243.             foreach ($vars as $key => $value)
  244.             {
  245.                 if ('_' == substr($key01))
  246.                 {
  247.                     unset($vars[$key]);
  248.                 }
  249.             }
  250.         }
  251.         return $vars;
  252.     }
  253.  
  254.     /**
  255.      * Get the most recent error message
  256.      *
  257.      * @param   integer  $i         Option error index
  258.      * @param   boolean  $toString  Indicates if JError objects should return their error message
  259.      *
  260.      * @return  string  Error message
  261.      *
  262.      * @since   11.1
  263.      *
  264.      * @deprecated  12.1
  265.      */
  266.     public function getError($i null$toString true)
  267.     {
  268.         JLog::add('JException::getError is deprecated.'JLog::WARNING'deprecated');
  269.  
  270.         // Find the error
  271.         if ($i === null)
  272.         {
  273.             // Default, return the last message
  274.             $error end($this->_errors);
  275.         }
  276.         elseif (!array_key_exists($i$this->_errors))
  277.         {
  278.             // If $i has been specified but does not exist, return false
  279.             return false;
  280.         }
  281.         else
  282.         {
  283.             $error $this->_errors[$i];
  284.         }
  285.  
  286.         // Check if only the string is requested
  287.         if ($error instanceof Exception && $toString)
  288.         {
  289.             return (string) $error;
  290.         }
  291.  
  292.         return $error;
  293.     }
  294.  
  295.     /**
  296.      * Return all errors, if any
  297.      *
  298.      * @return  array  Array of error messages or JErrors
  299.      *
  300.      * @since   11.1
  301.      *
  302.      * @deprecated  12.1
  303.      */
  304.     public function getErrors()
  305.     {
  306.         JLog::add('JException::getErrors is deprecated.'JLog::WARNING'deprecated');
  307.  
  308.         return $this->_errors;
  309.     }
  310.  
  311.     /**
  312.      * Modifies a property of the object, creating it if it does not already exist.
  313.      *
  314.      * @param   string  $property  The name of the property
  315.      * @param   mixed   $value     The value of the property to set
  316.      *
  317.      * @return  mixed  Previous value of the property
  318.      *
  319.      * @deprecated  12.1
  320.      * @see         JException::setProperties()
  321.      * @since       11.1
  322.      */
  323.     public function set($property$value null)
  324.     {
  325.         JLog::add('JException::set is deprecated.'JLog::WARNING'deprecated');
  326.  
  327.         $previous = isset($this->$property$this->$property null;
  328.         $this->$property $value;
  329.         return $previous;
  330.     }
  331.  
  332.     /**
  333.      * Set the object properties based on a named array/hash
  334.      *
  335.      * @param   mixed  $properties  Either and associative array or another object
  336.      *
  337.      * @return  boolean 
  338.      *
  339.      * @deprecated  12.1
  340.      * @see         JException::set()
  341.      * @since       11.1
  342.      */
  343.     public function setProperties($properties)
  344.     {
  345.         JLog::add('JException::setProperties is deprecated.'JLog::WARNING'deprecated');
  346.  
  347.         // Cast to an array
  348.         $properties = (array) $properties;
  349.  
  350.         if (is_array($properties))
  351.         {
  352.             foreach ($properties as $k => $v)
  353.             {
  354.                 $this->$k $v;
  355.             }
  356.  
  357.             return true;
  358.         }
  359.  
  360.         return false;
  361.     }
  362.  
  363.     /**
  364.      * Add an error message
  365.      *
  366.      * @param   string  $error  Error message
  367.      *
  368.      * @return  void 
  369.      *
  370.      * @since   11.1
  371.      *
  372.      * @deprecated  12.1
  373.      */
  374.     public function setError($error)
  375.     {
  376.         JLog::add('JException::setErrors is deprecated.'JLog::WARNING'deprecated');
  377.  
  378.         array_push($this->_errors$error);
  379.     }
  380. }

Documentation generated on Tue, 19 Nov 2013 15:02:41 +0100 by phpDocumentor 1.4.3