Skip to content

Commit

Permalink
Create a value object for a component record
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Feb 18, 2017
1 parent 40b3a1e commit 863ec06
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 11 deletions.
17 changes: 6 additions & 11 deletions libraries/cms/component/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JComponentHelper
/**
* The component list cache
*
* @var array
* @var JComponentRecord[]
* @since 1.6
*/
protected static $components = array();
Expand All @@ -32,7 +32,7 @@ class JComponentHelper
* @param string $option The component option.
* @param boolean $strict If set and the component does not exist, the enabled attribute will be set to false.
*
* @return stdClass An object with the information for the component.
* @return JComponentRecord An object with the information for the component.
*
* @since 1.5
*/
Expand All @@ -46,21 +46,16 @@ public static function getComponent($option, $strict = false)
}
else
{
$result = new stdClass;
$result = new JComponentRecord;
$result->enabled = $strict ? false : true;
$result->params = new Registry;
$result->setParams(new Registry);
}
}
else
{
$result = static::$components[$option];
}

if (is_string($result->params))
{
static::$components[$option]->params = new Registry(static::$components[$option]->params);
}

return $result;
}

Expand Down Expand Up @@ -436,7 +431,7 @@ protected static function load($option)
->where($db->quoteName('type') . ' = ' . $db->quote('component'));
$db->setQuery($query);

return $db->loadObjectList('option');
return $db->loadObjectList('option', 'JComponentRecord');
};

/** @var JCacheControllerCallback $cache */
Expand Down Expand Up @@ -493,7 +488,7 @@ protected static function load($option)
/**
* Get installed components
*
* @return array The components property
* @return JComponentRecord[] The components property
*
* @since 3.6.3
*/
Expand Down
142 changes: 142 additions & 0 deletions libraries/cms/component/record.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage Component
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_PLATFORM') or die;

use Joomla\Registry\Registry;

/**
* Object representing a component extension record
*
* @since __DEPLOY_VERSION__
*/
class JComponentRecord extends JObject
{
/**
* Primary key
*
* @var integer
* @since __DEPLOY_VERSION__
*/
public $id;

/**
* The component name
*
* @var integer
* @since __DEPLOY_VERSION__
*/
public $option;

/**
* The component parameters
*
* @var string|Registry
* @since __DEPLOY_VERSION__
* @note This field is protected to require reading this field to proxy through the getter to convert the params to a Registry instance
*/
protected $params;

/**
* Indicates if this component is enabled
*
* @var integer
* @since __DEPLOY_VERSION__
*/
public $enabled;

/**
* Class constructor
*
* @param array $data The menu item data to load
*
* @since __DEPLOY_VERSION__
*/
public function __construct($data = array())
{
foreach ((array) $data as $key => $value)
{
$this->$key = $value;
}
}

/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since __DEPLOY_VERSION__
* @deprecated 4.0 Access the item parameters through the `getParams()` method
*/
public function __get($name)
{
if ($name === 'params')
{
return $this->getParams();
}

return $this->get($name);
}

/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to the the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since __DEPLOY_VERSION__
* @deprecated 4.0 Set the item parameters through the `setParams()` method
*/
public function __set($name, $value)
{
if ($name === 'params')
{
$this->setParams($value);

return;
}

$this->set($name, $value);
}

/**
* Returns the menu item parameters
*
* @return Registry
*
* @since __DEPLOY_VERSION__
*/
public function getParams()
{
if (!($this->params instanceof Registry))
{
$this->params = new Registry($this->params);
}

return $this->params;
}

/**
* Sets the menu item parameters
*
* @param Registry|string $params The data to be stored as the parameters
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function setParams($params)
{
$this->params = $params;
}
}

0 comments on commit 863ec06

Please sign in to comment.