本文整理汇总了PHP中Joomla\Registry\Registry::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::merge方法的具体用法?PHP Registry::merge怎么用?PHP Registry::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\Registry\Registry
的用法示例。
在下文中一共展示了Registry::merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param Registry $config The config object.
* @param string $extension The extension name.
*/
public function __construct(Registry $config = null, $extension = null)
{
$config = $config ?: new Registry();
$this->extension = $extension;
$this->resetCachePosition();
$this->config->merge($config);
}
示例2: render
/**
* Renders a module script and returns the results as a string
*
* @param mixed $module The name of the module to render
* @param array $attribs Associative array of values
* @param string $content If present, module information from the buffer will be used
*
* @return string The output of the script
*
* @since 11.1
*/
public function render($module, $attribs = array(), $content = null)
{
if (!is_object($module)) {
$title = isset($attribs['title']) ? $attribs['title'] : null;
$module = JModuleHelper::getModule($module, $title);
if (!is_object($module)) {
if (is_null($content)) {
return '';
} else {
/**
* If module isn't found in the database but data has been pushed in the buffer
* we want to render it
*/
$tmp = $module;
$module = new stdClass();
$module->params = null;
$module->module = $tmp;
$module->id = 0;
$module->user = 0;
}
}
}
// Get the user and configuration object
// $user = JFactory::getUser();
$conf = Factory::getConfig();
// Set the module content
if (!is_null($content)) {
$module->content = $content;
}
// Get module parameters
$params = new Registry();
$params->loadString($module->params);
// Use parameters from template
if (isset($attribs['params'])) {
$template_params = new Registry();
$template_params->loadString(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
$params->merge($template_params);
$module = clone $module;
$module->params = (string) $params;
}
$contents = '';
// Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the
// module instead
$cachemode = $params->get('cachemode', 'oldstatic');
if ($params->get('cache', 0) == 1 && $conf->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri') {
// Default to itemid creating method and workarounds on
$cacheparams = new stdClass();
$cacheparams->cachemode = $cachemode;
$cacheparams->class = 'JModuleHelper';
$cacheparams->method = 'renderModule';
$cacheparams->methodparams = array($module, $attribs);
$contents = JModuleHelper::ModuleCache($module, $params, $cacheparams);
} else {
$contents = JModuleHelper::renderModule($module, $attribs);
}
return $contents;
}
示例3: getParams
/**
* Get component params.
*
* @return Registry
*/
public function getParams()
{
if ($this->params) {
return $this->params;
}
$app = $this->getContainer()->get('app');
$comParams = ExtensionHelper::getParams($this->option);
$menuParams = new Registry();
if ($menu = $app->getMenu()->getActive()) {
$menuParams->loadString($menu->params);
}
$menuParams->merge($comParams);
return $this->params = $menuParams;
}
示例4: load
protected function load()
{
//the cart is in the session, or in state.
//We start with getting the cart items, then enumerating them to get each cart item type, so we can process
//it through its plugin.
$this->product = Sp4kAppsProductApp::getInstance(new Joomla\Registry\Registry(['id' => $this->getState()->get('product_id')]))->getItem();
$config = $this->product->config;
foreach (get_object_vars($config) as $index => $configopt) {
$state = new Registry(['options' => $configopt]);
$state->merge($this->getState());
$cartPluginClassName = 'Sp4kAppsCartPlugins' . ucfirst($index) . 'Plg';
if (class_exists($cartPluginClassName)) {
$this->plugins[$index] = $cartPluginClassName::getInstance($state);
}
}
//$this->plugins['summary'] = Sp4kAppsCartPluginsSummaryPlg::getInstance($this->getState());
$this->cart_key = md5($this->getState()->get('event_id') . '.' . $this->getState()->get('product_id') . '.' . $this->getState()->get('child_id'));
// set the state to the table data so
// that any empty variables in the incoming data are populated with table data.
//$this->getState()->loadArray(get_object_vars($this->_table),true);
}
示例5: __construct
/**
* Constructor.
*
* @param string $name The Component name.
* @param \JInput $input The Input object.
* @param \JApplicationCms $application The Application object.
* @param Container $container The DI container.
*
* @throws \Exception
*/
public function __construct($name = null, $input = null, $application = null, $container = null)
{
$this->name = $name;
// Guess component name.
if (!$this->name) {
$reflection = $this->getReflection();
$this->name = $reflection->getShortName();
$this->name = strtolower(str_replace('Component', '', $this->name));
if (!$this->name) {
throw new \Exception('Component need name.');
}
}
$this->option = 'com_' . strtolower($this->name);
$this->container = $container ?: Container::getInstance($this->option);
$this->application = $application ?: $this->container->get('app');
$this->input = $input ?: $this->application->input;
// Add a config but make it B/C
if ($this->container->exists($this->option . '.config')) {
$this->config = $this->container->get($this->option . '.config');
}
$this->config = $this->config ?: new Registry();
$this->config->merge(\JComponentHelper::getParams($this->option));
$this->init();
}
示例6: testMerge
/**
* Test the Joomla\Registry\Registry::merge method.
*
* @return void
*
* @covers Joomla\Registry\Registry::merge
* @since 1.0
*/
public function testMerge()
{
$array1 = array('foo' => 'bar', 'hoo' => 'hum', 'dum' => array('dee' => 'dum'));
$array2 = array('foo' => 'soap', 'dum' => 'huh');
$registry1 = new Registry();
$registry1->loadArray($array1);
$registry2 = new Registry();
$registry2->loadArray($array2);
$registry1->merge($registry2);
// Test getting a known value.
$this->assertThat($registry1->get('foo'), $this->equalTo('soap'), 'Line: ' . __LINE__ . '.');
$this->assertThat($registry1->get('dum'), $this->equalTo('huh'), 'Line: ' . __LINE__ . '.');
// Test merge with zero and blank value
$json1 = '{
"param1":1,
"param2":"value2"
}';
$json2 = '{
"param1":2,
"param2":"",
"param3":0,
"param4":-1,
"param5":1
}';
$a = new Registry($json1);
$b = new Registry();
$b->loadString($json2, 'JSON');
$result = $a->merge($b);
// New param with zero value should show in merged registry
$this->assertEquals(2, $a->get('param1'), '$b value should override $a value');
$this->assertEquals('value2', $a->get('param2'), '$a value should override blank $b value');
$this->assertEquals(0, $a->get('param3'), '$b value of 0 should override $a value');
$this->assertEquals(-1, $a->get('param4'), '$b value of -1 should override $a value');
$this->assertEquals(1, $a->get('param5'), '$b value of 1 should override $a value');
// Test recursive merge
$registry = new Registry();
$object1 = '{
"foo" : "foo value",
"bar" : {
"bar1" : "bar value 1",
"bar2" : "bar value 2"
}
}';
$object2 = '{
"foo" : "foo value",
"bar" : {
"bar2" : "new bar value 2"
}
}';
$registry1 = new Registry(json_decode($object1));
$registry2 = new Registry(json_decode($object2));
$registry1->merge($registry2, true);
$this->assertEquals($registry1->get('bar.bar2'), 'new bar value 2', 'Line: ' . __LINE__ . '. bar.bar2 shuould be override.');
$this->assertEquals($registry1->get('bar.bar1'), 'bar value 1', 'Line: ' . __LINE__ . '. bar.bar1 should not be overrided.');
// Chicking we merge a non Registry object will return error.
$a = new Registry();
$b = new stdClass();
try {
$a->merge($b);
} catch (Exception $e) {
$this->assertInstanceOf('PHPUnit_Framework_Error', $e, 'Line: ' . __LINE__ . '. Attempt to merge non Registry should return Error');
}
}
示例7: testANonRegistryObjectCannotBeMergedIntoARegistry
/**
* @testdox Two Registry instances can be merged
*
* @covers Joomla\Registry\Registry::merge
*/
public function testANonRegistryObjectCannotBeMergedIntoARegistry()
{
$registry = new Registry();
$this->assertFalse($registry->merge(new \stdClass()), 'Only Registry instances can be merged together.');
}
示例8: display
/**
* Display function
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise a Error object.
*
* @since 1.7.2
*/
public function display ($tpl = null)
{
$renderHelper = new ChurchDirectoryRenderHelper;
// Get some data from the models
$state = $this->get('State');
/** @var Registry $params */
$params = $state->params;
$items = $this->get('Items');
$category = $this->get('Category');
$children = $this->get('Children');
$parent = $this->get('Parent');
$pagination = $this->get('Pagination');
// Check whether category access level allows access.
$user = JFactory::getUser();
$groups = $user->getAuthorisedViewLevels();
if (!in_array($category->access, $groups))
{
echo JText::_('JERROR_ALERTNOAUTHOR');
return false;
}
if ($items == false || empty($items))
{
echo JText::_('COM_CHURCHDIRECTOY_ERROR_DIRECTORY_NOT_FOUND');
return false;
}
// Prepare the data.
for ($i = 0, $n = count($items); $i < $n; $i++)
{
$item = &$items[$i];
// Compute the contact slug.
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$item->event = new stdClass;
$temp = new Registry;
$temp->loadString($item->params);
$item->params = clone $params;
$item->params->merge($temp);
if ($item->params->get('dr_show_email', 0) == 1)
{
$item->email_to = trim($item->email_to);
if (empty($item->email_to) && !JMailHelper::isEmailAddress($item->email_to))
{
$item->email_to = null;
}
}
}
// Setup the category parameters.
$cparams = $category->getParams();
$category->params = clone $params;
$category->params->merge($cparams);
$children = [$category->id => $children];
$maxLevel = $params->get('maxLevel', -1);
$this->maxLevel = &$maxLevel;
$this->state = &$state;
$this->items = &$items;
$this->category = &$category;
$this->children = &$children;
$this->params = &$params;
$this->parent = &$parent;
$this->pagination = &$pagination;
// Creates an array of strings to hold the lines of the KML file.
$kml = ['<?xml version="1.0" encoding="UTF-8"?>'];
$kml[] = '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"'
. ' xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">';
$kml[] = '<Document>';
$kml[] = '<name>' . $items[0]->kml_name . '</name>';
$kml[] = '<open>' . $items[0]->kml_params->get('open') . '</open>';
$kml[] = '<LookAt>
<longitude>' . $items[0]->kml_lng . '</longitude>
<latitude>' . $items[0]->kml_lat . '</latitude>
<altitude>' . $items[0]->kml_params->get('altitude') . '</altitude>
<range>' . $items[0]->kml_params->get('range') . '</range>
<tilt>' . $items[0]->kml_params->get('tilt') . '</tilt>
<heading>' . $items[0]->kml_params->get('heading') . '</heading>
<gx:altitudeMode>' . $items[0]->kml_params->get('gxaltitudeMode') . '</gx:altitudeMode>
</LookAt> <!-- Camera or LookAt -->';
$kml[] = $items[0]->kml_style;
//.........这里部分代码省略.........