1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 21:57:51 +02:00

e107::getSession()->set will now accept multi-dimensional key format. Test added. Form-handler PHP8 fix.

This commit is contained in:
Cameron
2021-02-08 11:59:04 -08:00
parent 608c0c57b1
commit 72c54371cc
4 changed files with 58 additions and 16 deletions

View File

@@ -5648,10 +5648,14 @@ var_dump($select_options);*/
break; break;
case 'files': case 'files':
if(!empty($value) && !is_array($value))
if(!empty($value))
{
if(!is_array($value))
{ {
return "Type 'files' must have a data type of 'array' or 'json'"; return "Type 'files' must have a data type of 'array' or 'json'";
} }
$ret = '<ol>'; $ret = '<ol>';
for ($i=0; $i < 5; $i++) for ($i=0; $i < 5; $i++)
{ {
@@ -5666,6 +5670,9 @@ var_dump($select_options);*/
} }
$ret .= '</ol>'; $ret .= '</ol>';
$value = $ret; $value = $ret;
}
break; break;
case 'datestamp': case 'datestamp':

View File

@@ -303,13 +303,34 @@ class e_session
/** /**
* Set value in current session namespace * Set value in current session namespace
* Equals to $_SESSION[NAMESPACE][$key] = $value * Equals to $_SESSION[NAMESPACE][$key] = $value
* @param string $key * @param string $key Also accepts multi-dimensinal format. key1/key2
* @param mixed $value * @param mixed $value
* @return e_session * @return e_session
*/ */
public function set($key, $value) public function set($key, $value)
{
if(strpos($key,'/') !== false) // multi-dimensional
{
$keyArr = explode('/',$key);
$count = count($keyArr);
if($count === 2)
{
list($k1, $k2) = $keyArr;
$this->_data[$k1][$k2] = $value;
}
elseif($count === 3)
{
list($k1, $k2, $k3) = $keyArr;
$this->_data[$k1][$k2][$k3] = $value;
}
}
else
{ {
$this->_data[$key] = $value; $this->_data[$key] = $value;
}
return $this; return $this;
} }

View File

@@ -1395,7 +1395,7 @@ class e107Test extends \Codeception\Test\Unit
$all = e107::getAddonConfig('e_url'); $all = e107::getAddonConfig('e_url');
foreach($all as $plugin => $var) foreach($all as $plugin => $var)
{ {
if($plugin === 'gallery' || $plugin === 'rss_menu') // fixme - sef may be enabled or disabled each time tests are run if($plugin === 'gallery' || $plugin === 'rss_menu' || $plugin === 'vstore') // fixme - sef may be enabled or disabled each time tests are run
{ {
continue; continue;
} }

View File

@@ -60,6 +60,20 @@
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
// Multi-dimensional array support.
$newsess = e107::getSession('newtest');
$newsess->set('customer', array('firstname'=>'Fred'));
$newsess->set('customer/lastname', 'Smith');
$expected = array (
'firstname' => 'Fred',
'lastname' => 'Smith',
);
$result = $newsess->get('customer');
$this->assertSame($expected, $result);
} }
/* /*
public function testGetOption() public function testGetOption()