/** * Converts an object into an INI formatted string * - Unfortunately, there is no way to have ini values nested further than two * levels deep. Therefore we will only go through the first two levels of * the object. * * @param object $struct Data source object. * @param array $options Options used by the formatter. * * @return string INI formatted string. */ public static function structToString($struct, array $options = array()) { $local = array(); $global = array(); // Iterate over the object to set the properties. foreach ($struct as $key => $value) { // If the value is an object then we need to put it in a local section. if (is_array($value)) { if (!RegistryHelper::isAssociativeArray($value)) { continue; } // Add the section line. $local[] = ''; $local[] = '[' . $key . ']'; // Add the properties for this section. foreach ($value as $k => $v) { if (is_numeric($k)) { continue; } $local[] = $k . '=' . static::getValueAsINI($v); } } else { // Not in a section so add the property to the global array. $global[] = $key . '=' . static::getValueAsINI($value); } } return implode("\n", array_merge($global, $local)); }
/** * Method to test isAssociativeArray(). * * @return void * * @covers Windwalker\Registry\RegistryHelper::isAssociativeArray */ public function testIsAssociativeArray() { $this->assertFalse(RegistryHelper::isAssociativeArray(array('a', 'b'))); $this->assertTrue(RegistryHelper::isAssociativeArray(array(1, 2, 'a' => 'b', 'c', 'd'))); }