1 <?php
  2 /**
  3  * @package     Joomla.Libraries
  4  * @subpackage  Component
  5  *
  6  * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
  7  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8  */
  9 
 10 defined('JPATH_PLATFORM') or die;
 11 
 12 use Joomla\Registry\Registry;
 13 
 14 /**
 15  * Object representing a component extension record
 16  *
 17  * @since  3.7.0
 18  * @note   As of 4.0 this class will no longer extend JObject
 19  */
 20 class JComponentRecord extends JObject
 21 {
 22     /**
 23      * Primary key
 24      *
 25      * @var    integer
 26      * @since  3.7.0
 27      */
 28     public $id;
 29 
 30     /**
 31      * The component name
 32      *
 33      * @var    integer
 34      * @since  3.7.0
 35      */
 36     public $option;
 37 
 38     /**
 39      * The component parameters
 40      *
 41      * @var    string|Registry
 42      * @since  3.7.0
 43      * @note   This field is protected to require reading this field to proxy through the getter to convert the params to a Registry instance
 44      */
 45     protected $params;
 46 
 47     /**
 48      * Indicates if this component is enabled
 49      *
 50      * @var    integer
 51      * @since  3.7.0
 52      */
 53     public $enabled;
 54 
 55     /**
 56      * Class constructor
 57      *
 58      * @param   array  $data  The component record data to load
 59      *
 60      * @since   3.7.0
 61      */
 62     public function __construct($data = array())
 63     {
 64         foreach ((array) $data as $key => $value)
 65         {
 66             $this->$key = $value;
 67         }
 68     }
 69 
 70     /**
 71      * Method to get certain otherwise inaccessible properties from the form field object.
 72      *
 73      * @param   string  $name  The property name for which to the the value.
 74      *
 75      * @return  mixed  The property value or null.
 76      *
 77      * @since   3.7.0
 78      * @deprecated  4.0  Access the item parameters through the `getParams()` method
 79      */
 80     public function __get($name)
 81     {
 82         if ($name === 'params')
 83         {
 84             return $this->getParams();
 85         }
 86 
 87         return $this->get($name);
 88     }
 89 
 90     /**
 91      * Method to set certain otherwise inaccessible properties of the form field object.
 92      *
 93      * @param   string  $name   The property name for which to the the value.
 94      * @param   mixed   $value  The value of the property.
 95      *
 96      * @return  void
 97      *
 98      * @since   3.7.0
 99      * @deprecated  4.0  Set the item parameters through the `setParams()` method
100      */
101     public function __set($name, $value)
102     {
103         if ($name === 'params')
104         {
105             $this->setParams($value);
106 
107             return;
108         }
109 
110         $this->set($name, $value);
111     }
112 
113     /**
114      * Returns the menu item parameters
115      *
116      * @return  Registry
117      *
118      * @since   3.7.0
119      */
120     public function getParams()
121     {
122         if (!($this->params instanceof Registry))
123         {
124             $this->params = new Registry($this->params);
125         }
126 
127         return $this->params;
128     }
129 
130     /**
131      * Sets the menu item parameters
132      *
133      * @param   Registry|string  $params  The data to be stored as the parameters
134      *
135      * @return  void
136      *
137      * @since   3.7.0
138      */
139     public function setParams($params)
140     {
141         $this->params = $params;
142     }
143 }
144