本文整理汇总了PHP中JRegistryFormat类的典型用法代码示例。如果您正苦于以下问题:PHP JRegistryFormat类的具体用法?PHP JRegistryFormat怎么用?PHP JRegistryFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JRegistryFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testObjectToString
/**
* Test the JRegistryFormatJSON::objectToString method.
*
* @return void
*/
public function testObjectToString()
{
$class = JRegistryFormat::getInstance('JSON');
$options = null;
$object = new stdClass;
$object->foo = 'bar';
$object->quoted = '"stringwithquotes"';
$object->booleantrue = true;
$object->booleanfalse = false;
$object->numericint = 42;
$object->numericfloat = 3.1415;
// The PHP registry format does not support nested objects
$object->section = new stdClass;
$object->section->key = 'value';
$object->array = array('nestedarray' => array('test1' => 'value1'));
$string = '{"foo":"bar","quoted":"\"stringwithquotes\"",' .
'"booleantrue":true,"booleanfalse":false,' .
'"numericint":42,"numericfloat":3.1415,' .
'"section":{"key":"value"},' .
'"array":{"nestedarray":{"test1":"value1"}}' .
'}';
// Test basic object to string.
$this->assertThat(
$class->objectToString($object, $options),
$this->equalTo($string)
);
}
示例2: testGetInstance
/**
* Test the JRegistryFormat::getInstance method.
*/
public function testGetInstance()
{
// Test INI format.
$object = JRegistryFormat::getInstance('INI');
$this->assertThat(
$object instanceof JRegistryFormatIni,
$this->isTrue()
);
// Test JSON format.
$object = JRegistryFormat::getInstance('JSON');
$this->assertThat(
$object instanceof JRegistryFormatJson,
$this->isTrue()
);
// Test PHP format.
$object = JRegistryFormat::getInstance('PHP');
$this->assertThat(
$object instanceof JRegistryFormatPHP,
$this->isTrue()
);
// Test XML format.
$object = JRegistryFormat::getInstance('XML');
$this->assertThat(
$object instanceof JRegistryFormatXml,
$this->isTrue()
);
}
示例3: testStringToObject
/**
* Test the JRegistryFormatPHP::stringToObject method.
*
* @return void
*/
public function testStringToObject()
{
$class = JRegistryFormat::getInstance('PHP');
// This method is not implemented in the class. The test is to achieve 100% code coverage
$this->assertTrue($class->stringToObject(''));
}
示例4: testStringToObject
/**
* Test the JRegistryFormatINI::stringToObject method.
*
* @return void
*/
public function testStringToObject()
{
$class = JRegistryFormat::getInstance('INI');
$string2 = "[section]\nfoo=bar";
$object1 = new stdClass();
$object1->foo = 'bar';
$object2 = new stdClass();
$object2->section = $object1;
// Test INI format string without sections.
$object = $class->stringToObject($string2, array('processSections' => false));
$this->assertThat($object, $this->equalTo($object1));
// Test INI format string with sections.
$object = $class->stringToObject($string2, array('processSections' => true));
$this->assertThat($object, $this->equalTo($object2));
// Test empty string
$this->assertThat($class->stringToObject(null), $this->equalTo(new stdClass()));
$string3 = "[section]\nfoo=bar\n;Testcomment\nkey=value\n\n/brokenkey=)brokenvalue";
$object2->section->key = 'value';
$this->assertThat($class->stringToObject($string3, array('processSections' => true)), $this->equalTo($object2));
$string4 = "boolfalse=false\nbooltrue=true\nkeywithoutvalue\nnumericfloat=3.1415\nnumericint=42\nkey=\"value\"";
$object3 = new stdClass();
$object3->boolfalse = false;
$object3->booltrue = true;
$object3->numericfloat = 3.1415;
$object3->numericint = 42;
$object3->key = 'value';
$this->assertThat($class->stringToObject($string4), $this->equalTo($object3));
// Trigger the cache - Doing this only to achieve 100% code coverage. ;-)
$this->assertThat($class->stringToObject($string4), $this->equalTo($object3));
}
示例5: stdclass
/**
* Logic for the event edit screen
*
* @access public
* @return array
* @since 0.9
*/
function &getData()
{
if (empty($this->_data)) {
$res = new stdclass();
// original file
$source = $this->getSource();
$helper =& JRegistryFormat::getInstance('INI');
$object = $helper->stringToObject(file_get_contents($source));
$res->from = get_object_vars($object);
// target file
$path = $this->getTarget();
MissingtAdminHelper::checkHistory($path);
if (file_exists($path)) {
$object = $helper->stringToObject(file_get_contents($path));
$strings = get_object_vars($object);
$present = array();
foreach ($res->from as $k => $v) {
if (isset($strings[$k]) && !empty($strings[$k])) {
$present[$k] = $strings[$k];
}
}
$res->to = $present;
} else {
$res->to = array();
}
$this->_data = $res;
}
return $this->_data;
}
示例6: testStringToObject
/**
* Test the JRegistryFormatXML::stringToObject method.
*
* @return void
*/
public function testStringToObject()
{
$class = JRegistryFormat::getInstance('XML');
$object = new stdClass;
$object->foo = 'bar';
$object->booleantrue = true;
$object->booleanfalse = false;
$object->numericint = 42;
$object->numericfloat = 3.1415;
$object->section = new stdClass;
$object->section->key = 'value';
$object->array = array('test1' => 'value1');
$string = "<?xml version=\"1.0\"?>\n<registry>" .
"<node name=\"foo\" type=\"string\">bar</node>" .
"<node name=\"booleantrue\" type=\"boolean\">1</node>" .
"<node name=\"booleanfalse\" type=\"boolean\"></node>" .
"<node name=\"numericint\" type=\"integer\">42</node>" .
"<node name=\"numericfloat\" type=\"double\">3.1415</node>" .
"<node name=\"section\" type=\"object\">" .
"<node name=\"key\" type=\"string\">value</node>" .
"</node>" .
"<node name=\"array\" type=\"array\">" .
"<node name=\"test1\" type=\"string\">value1</node>" .
"</node>" .
"</registry>\n";
// Test basic object to string.
$this->assertThat(
$class->stringToObject($string),
$this->equalTo($object)
);
}
示例7: stringToObject
function stringToObject($data)
{
$data = JString::trim($data);
if (JString::substr($data, 0, 1) != '{' && JString::substr($data, -1, 1) != '}') {
$object = JRegistryFormat::getInstance('INI')->stringToObject($data);
} else {
$object = json_decode($data);
}
return $object;
}
示例8: __construct
/**
* Constructor.
*
* @param mixed $dispatcher A dispatcher
* @param array $config An optional KConfig object with configuration options.
*
* @return void
*/
public function __construct($dispatcher = null, $config = array())
{
if (isset($config['params'])) {
$config = (array) JRegistryFormat::getInstance('ini')->stringToObject($config['params']);
}
$config = new KConfig($config);
parent::__construct($config);
$this->_params = $config;
KService::set('plg:storage.default', $this);
}
示例9: __construct
/**
* Class Constructor
*
* @param array|object $data The data to be converted to JRegistry format
*
* @since 1.0.0
*/
public function __construct($data = array())
{
if ($data instanceof JRegistry) {
$data = $data->toArray();
} else {
if (is_string($data) && substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') {
$data = JRegistryFormat::getInstance('INI')->stringToObject($data);
}
}
parent::__construct($data);
}
示例10: stringToObject
/**
* Parse a JSON formatted string and convert it into an object.
*
* If the string is not in JSON format, this method will attempt to parse it as INI format.
*
* @param string $data JSON formatted string to convert.
* @param array $options Options used by the formatter.
*
* @return object Data object.
*
* @since 11.1
*/
public function stringToObject($data, array $options = array('processSections' => false))
{
$data = trim($data);
if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') {
$ini = JRegistryFormat::getInstance('INI');
$obj = $ini->stringToObject($data, $options);
} else {
$obj = json_decode($data);
}
return $obj;
}
示例11: _convertToIni
function _convertToIni($array)
{
$handlerIni =& JRegistryFormat::getInstance('INI');
$object = new StdClass();
foreach ($array as $k => $v) {
if (strpos($k, 'KEY_') === 0) {
$key = substr($k, 4);
$object->{$key} = $v;
}
}
$string = $handlerIni->objectToString($object, null);
return $string;
}
示例12: _sanitize
/**
* Sanitize a value
*
* @param scalar Value to be sanitized
* @return string
*/
protected function _sanitize($value)
{
$result = null;
$handler = JRegistryFormat::getInstance('INI');
if ($value instanceof KConfig) {
$value = $value->toArray();
}
if (is_string($value)) {
$result = $handler->stringToObject($value);
}
if (is_null($result)) {
$result = $handler->objectToString((object) $value, null);
}
return $result;
}
示例13: stringToObject
/**
* Parse a JSON formatted string and convert it into an object.
*
* If the string is not in JSON format, this method will attempt to parse it as INI format.
*
* @param string $data JSON formatted string to convert.
* @param array $options Options used by the formatter.
*
* @return object Data object.
*
* @since 11.1
*/
public function stringToObject($data, $options = array('processSections' => false))
{
// Fix legacy API.
if (is_bool($options)) {
$options = array('processSections' => $options);
// Deprecation warning.
JLog::add('JRegistryFormatJSON::stringToObject() second argument should not be a boolean.', JLog::WARNING, 'deprecated');
}
$data = trim($data);
if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') {
$ini = JRegistryFormat::getInstance('INI');
$obj = $ini->stringToObject($data, $options);
} else {
$obj = json_decode($data);
}
return $obj;
}
示例14: testGetInstance
/**
* Test the JRegistryFormat::getInstance method.
*
* @return void
*/
public function testGetInstance()
{
// Test INI format.
$object = JRegistryFormat::getInstance('INI');
$this->assertThat(
$object instanceof JRegistryFormatIni,
$this->isTrue()
);
// Test JSON format.
$object = JRegistryFormat::getInstance('JSON');
$this->assertThat(
$object instanceof JRegistryFormatJson,
$this->isTrue()
);
// Test PHP format.
$object = JRegistryFormat::getInstance('PHP');
$this->assertThat(
$object instanceof JRegistryFormatPHP,
$this->isTrue()
);
// Test XML format.
$object = JRegistryFormat::getInstance('XML');
$this->assertThat(
$object instanceof JRegistryFormatXml,
$this->isTrue()
);
// Test non-existing format.
try
{
$object = JRegistryFormat::getInstance('SQL');
}
catch (Exception $e)
{
return;
}
$this->fail('JRegistryFormat should throw an exception in case of non-existing formats');
}
示例15: fwdtofriend
public static function fwdtofriend($action, $task)
{
jimport('joomla.html.parameter');
$mainframe = JFactory::getApplication();
JPluginHelper::importPlugin('jnews');
$plugin = JPluginHelper::getPlugin('jnews', 'forwardtofriend');
$registry = new JRegistry();
if (!method_exists($registry, 'loadString')) {
$data = trim($plugin->params);
$options = array('processSections' => false);
if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') {
$ini = JRegistryFormat::getInstance('INI');
$obj = $ini->stringToObject($data, $options);
} else {
$obj = json_decode($data);
}
$registry->loadObject($obj);
} else {
$registry->loadString($plugin->params);
}
$params = $registry;
if ($task == 'sendtofriend') {
$new = false;
$mailingID = JRequest::getInt('mailingid');
$html = JRequest::getInt('html');
$html1 = $html ? 'true' : 'false';
$mailing = new stdClass();
$mailing = jNews_Mailing::getOneMailing('', $mailingID, '', $new, $html1);
//&$new
$mailing->fromname = JRequest::getVar('fromName');
$mailing->fromemail = JRequest::getVar('fromEmail');
$mailing->frombounce = JRequest::getVar('fromEmail');
$mailing->id = $mailingID;
$mailing->issue_nb = 0;
$mailing->images = '';
$mailing->attachments = '';
$receiversNames = JRequest::getVar('toName', array(), '', 'array');
$receiversEmails = JRequest::getVar('toEmail', array(), '', 'array');
$message = new stdClass();
$message->dflt = JRequest::getVar('message');
$message->inEmail = JRequest::getVar('inEmailMessage');
//need to get it from the URL/request
$list = new stdClass();
$list->id = JRequest::getInt('listid');
$list->html = $html;
$botResult = $mainframe->triggerEvent('jnewsbot_sendtofriend', array($mailing, $message, $receiversNames, $receiversEmails, $list));
if (empty($plugin)) {
echo '<center><span style="font-size: 1.3em;">The <strong>jNews: Forward to friend</strong> plugin is either not installed or published. Click <a target="_blank" href="administrator/index.php?option=com_plugins&client=site&filter_type=jnews">here</a> to check if it\'s installed or published.</span></center>';
}
} else {
$botResult = $mainframe->triggerEvent('jnewsbot_fwdtofriend', array($params));
if (empty($plugin)) {
echo '<center><span style="font-size: 1.3em;">The <strong>jNews: Forward to friend</strong> plugin is either not installed or published. Click <a target="_blank" href="administrator/index.php?option=com_plugins&client=site&filter_type=jnews">here</a> to check if it\'s installed or published.</span></center>';
}
}
}