本文整理汇总了PHP中Joomla\Registry\Registry::loadObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::loadObject方法的具体用法?PHP Registry::loadObject怎么用?PHP Registry::loadObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\Registry\Registry
的用法示例。
在下文中一共展示了Registry::loadObject方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param Registry $config The config object.
*
* @throws \RuntimeException
*/
public function __construct(Registry $config)
{
// Set the configuration file path for the application.
$file = JPATH_ROOT . '/etc/config.json';
// Verify the configuration exists and is readable.
if (!is_readable($file)) {
throw new \RuntimeException('Configuration file does not exist or is unreadable.');
}
// Load the configuration file into an object.
$configObject = json_decode(file_get_contents($file));
if ($configObject === null) {
throw new \RuntimeException('Unable to parse the configuration file.');
}
$config->loadObject($configObject);
// No sure.. defined('JDEBUG') || define('JDEBUG', ($config->get('debug.system') || $config->get('debug.database')));
$this->config = $config;
}
示例2: __construct
/**
* Class constructor.
*
* @param string $path Path to the config file.
*
* @since 1.0
* @throws \RuntimeException
*/
public function __construct($path)
{
// Set the configuration file path for the application.
$file = JPATH_CONFIGURATION . '/config.json';
// Verify the configuration exists and is readable.
if (!is_readable($file)) {
throw new \RuntimeException('Configuration file does not exist or is unreadable.');
}
// Load the configuration file into an object.
$configObject = json_decode(file_get_contents($file));
if ($configObject === null) {
throw new \RuntimeException(sprintf('Unable to parse the configuration file %s.', $file));
}
$config = new Registry();
$config->loadObject($configObject);
$this->config = $config;
}
示例3: __construct
/**
* Constructor.
*
* @param Registry $config The config object.
*
* @since 1.0
* @throws \RuntimeException
*/
public function __construct(Registry $config)
{
// Check for a custom configuration.
$type = trim(getenv('JTRACKER_ENVIRONMENT'));
$name = $type ? 'config.' . $type : 'config';
// Set the configuration file path for the application.
$file = JPATH_ROOT . '/etc/' . $name . '.json';
// Verify the configuration exists and is readable.
if (!is_readable($file)) {
throw new \RuntimeException('Configuration file does not exist or is unreadable.');
}
// Load the configuration file into an object.
$configObject = json_decode(file_get_contents($file));
if ($configObject === null) {
throw new \RuntimeException(sprintf('Unable to parse the configuration file %s.', $file));
}
$config->loadObject($configObject);
defined('JDEBUG') || define('JDEBUG', $config->get('debug.system') || $config->get('debug.database'));
$this->config = $config;
}
示例4: createConfig
/**
* Create a configuration object
*
* @param string $file The path to the configuration file.
* @param string $type The type of the configuration file.
* @param string $namespace The namespace of the configuration file.
*
* @return Registry
*
* @see Registry
* @since 11.1
*/
protected static function createConfig($file, $type = 'PHP', $namespace = '')
{
if (is_file($file)) {
include_once $file;
}
// Create the registry with a default namespace of config
$registry = new Registry();
// Sanitize the namespace.
$namespace = ucfirst((string) preg_replace('/[^A-Z_]/i', '', $namespace));
// Build the config name.
$name = 'JConfig' . $namespace;
// Handle the PHP configuration type.
if ($type == 'PHP' && class_exists($name)) {
// Create the JConfig object
$config = new $name();
// Load the configuration values into the registry
$registry->loadObject($config);
}
return $registry;
}
示例5: delete
/**
* Method to delete one or more overrides.
*
* @param array $cids Array of keys to delete.
*
* @return integer Number of successfully deleted overrides, boolean false if an error occured.
*
* @since 2.5
*/
public function delete($cids)
{
// Check permissions first.
if (!JFactory::getUser()->authorise('core.delete', 'com_languages')) {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'));
return false;
}
jimport('joomla.filesystem.file');
require_once JPATH_COMPONENT . '/helpers/languages.php';
$filterclient = JFactory::getApplication()->getUserState('com_languages.overrides.filter.client');
$client = $filterclient == 0 ? 'SITE' : 'ADMINISTRATOR';
// Parse the override.ini file in oder to get the keys and strings.
$filename = constant('JPATH_' . $client) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini';
$strings = LanguagesHelper::parseFile($filename);
// Unset strings that shall be deleted
foreach ($cids as $key) {
if (isset($strings[$key])) {
unset($strings[$key]);
}
}
foreach ($strings as $key => $string) {
$strings[$key] = str_replace('"', '"_QQ_"', $string);
}
// Write override.ini file with the left strings.
$registry = new Registry();
$registry->loadObject($strings);
$reg = $registry->toString('INI');
$filename = constant('JPATH_' . $client) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini';
if (!JFile::write($filename, $reg)) {
return false;
}
$this->cleanCache();
return count($cids);
}
示例6: testLoadObject
/**
* Test the Joomla\Registry\Registry::loadObject method.
*
* @return void
*
* @covers Joomla\Registry\Registry::loadObject
* @since 1.0
*/
public function testLoadObject()
{
$object = new stdClass();
$object->foo = 'testloadobject';
$registry = new Registry();
$result = $registry->loadObject($object);
// Checking result is self that we can chaining
$this->assertEquals($result, $registry, '$result should be $registry self that support chaining');
// Test getting a known value.
$this->assertThat($registry->get('foo'), $this->equalTo('testloadobject'), 'Line: ' . __LINE__ . '.');
// Test that loadObject will auto 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"
}
}';
$registry->loadObject(json_decode($object1));
$registry->loadObject(json_decode($object2));
$this->assertEquals($registry->get('bar.bar2'), 'new bar value 2', 'Line: ' . __LINE__ . '. bar.bar2 shuould be override.');
$this->assertEquals($registry->get('bar.bar1'), 'bar value 1', 'Line: ' . __LINE__ . '. bar.bar1 should not be overrided.');
}
示例7: save
/**
* Method to save the form data.
*
* @param array $data The form data.
* @param boolean $opposite_client Indicates whether the override should not be created for the current client.
*
* @return boolean True on success, false otherwise.
*
* @since 2.5
*/
public function save($data, $opposite_client = false)
{
$app = JFactory::getApplication();
require_once JPATH_COMPONENT . '/helpers/languages.php';
jimport('joomla.filesystem.file');
$client = $app->getUserState('com_languages.overrides.filter.client', 0);
$language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB');
// If the override should be created for both.
if ($opposite_client) {
$client = 1 - $client;
}
// Return false if the constant is a reserved word, i.e. YES, NO, NULL, FALSE, ON, OFF, NONE, TRUE
$blacklist = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE');
if (in_array($data['key'], $blacklist)) {
$this->setError(JText::_('COM_LANGUAGES_OVERRIDE_ERROR_RESERVED_WORDS'));
return false;
}
$client = $client ? 'administrator' : 'site';
// Parse the override.ini file in oder to get the keys and strings.
$filename = constant('JPATH_' . strtoupper($client)) . '/language/overrides/' . $language . '.override.ini';
$strings = LanguagesHelper::parseFile($filename);
if (isset($strings[$data['id']])) {
// If an existent string was edited check whether
// the name of the constant is still the same.
if ($data['key'] == $data['id']) {
// If yes, simply override it.
$strings[$data['key']] = $data['override'];
} else {
// If no, delete the old string and prepend the new one.
unset($strings[$data['id']]);
$strings = array($data['key'] => $data['override']) + $strings;
}
} else {
// If it is a new override simply prepend it.
$strings = array($data['key'] => $data['override']) + $strings;
}
foreach ($strings as $key => $string) {
$strings[$key] = str_replace('"', '"_QQ_"', $string);
}
// Write override.ini file with the strings.
$registry = new Registry();
$registry->loadObject($strings);
$reg = $registry->toString('INI');
if (!JFile::write($filename, $reg)) {
return false;
}
// If the override should be stored for both clients save
// it also for the other one and prevent endless recursion.
if (isset($data['both']) && $data['both'] && !$opposite_client) {
return $this->save($data, true);
}
return true;
}
示例8: SplFileInfo
<?php
/**
* Part of Ezset project.
*
* @copyright Copyright (C) 2015 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later;
*/
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
$configDistFile = new SplFileInfo(INSTALL_ROOT . '/../configuration.dist.php');
$configFile = new SplFileInfo(INSTALL_ROOT . '/../configuration.php');
include_once $configDistFile->getPathname();
$config = new Registry();
$config->loadObject(new JConfig());
$options = $this->input->getVar('install');
$options['select'] = false;
$options['driver'] = $config->get('driver');
$db = JDatabaseDriver::getInstance($options);
try {
// Create
$db->setQuery('CREATE DATABASE IF NOT EXISTS ' . $db->qn($options['database']) . ' CHARACTER SET = "utf8"')->execute();
$db->select($options['database']);
// Import
$sql = new SplFileInfo(JPATH_BASE . '/ezset-sql-backup.sql');
$queries = file_get_contents($sql->getPathname());
$queries = $db->splitSql($queries);
foreach ($queries as $query) {
$db->setQuery($query)->execute();
}
$config->set('host', $options['host']);
示例9: testAnObjectCanBeLoaded
/**
* @testdox The Registry can load an object
*
* @covers Joomla\Registry\Registry::bindData
* @covers Joomla\Registry\Registry::loadObject
*/
public function testAnObjectCanBeLoaded()
{
$object = new \stdClass();
$object->foo = 'testloadobject';
$registry = new Registry();
$result = $registry->loadObject($object);
$this->assertSame($registry->loadObject($object), $registry, 'The loadObject() method should return $this');
$this->assertSame('testloadobject', $registry->get('foo'), 'The object\'s data should be correctly loaded.');
}
示例10: createConfig
/**
* Create a configuration object
*
* @param string $file The path to the configuration file.
* @param string $type The type of the configuration file.
* @param string $namespace The namespace of the configuration file.
*
* @return Registry
*
* @see Registry
* @since 11.1
* @deprecated 5.0 Use the configuration object within the application.
*/
protected static function createConfig($file, $type = 'PHP', $namespace = '')
{
JLog::add(sprintf('%s() is deprecated. The configuration object should be read from the application.', __METHOD__), JLog::WARNING, 'deprecated');
if (is_file($file)) {
include_once $file;
}
// Create the registry with a default namespace of config
$registry = new Registry();
// Sanitize the namespace.
$namespace = ucfirst((string) preg_replace('/[^A-Z_]/i', '', $namespace));
// Build the config name.
$name = 'JConfig' . $namespace;
// Handle the PHP configuration type.
if ($type == 'PHP' && class_exists($name)) {
// Create the JConfig object
$config = new $name();
// Load the configuration values into the registry
$registry->loadObject($config);
}
return $registry;
}