public function test_object_to_array_recursive()
 {
     $simple = new SimpleObejct();
     $notSimple = new NotSimpleObject();
     $notSimple->setFoo(new SimpleObejct());
     $notObject = "foo";
     $simpleExpected = array('foo' => 'bar', 'b' => 1);
     $notSimpleExpected = array('foo' => array('foo' => 'bar', 'b' => 1), 'b' => 1);
     $notObjectExpected = 'foo';
     $this->assertEquals($simpleExpected, object_to_array_recursive($simple));
     $this->assertEquals($notSimpleExpected, object_to_array_recursive($notSimple));
     $this->assertEquals($notObjectExpected, object_to_array_recursive($notObject));
 }
 function __construct()
 {
     parent::SugarView();
     global $current_user;
     if (!$current_user->isDeveloperForModule("Leads")) {
         die("Unauthorized Access to Administration");
     }
     $this->jsonHelper = getJSONobj();
     $this->parser = new ConvertLayoutMetadataParser("Contacts");
     if (isset($_REQUEST['updateConvertDef']) && $_REQUEST['updateConvertDef'] && !empty($_REQUEST['data'])) {
         $this->parser->updateConvertDef(object_to_array_recursive($this->jsonHelper->decode(html_entity_decode_utf8($_REQUEST['data']))));
         // clear the cache for this module only
         MetaDataManager::refreshModulesCache(array('Leads'));
     }
 }
Example #3
0
/**
 * This function will attempt to convert an object to an array.
 * Loops are not checked for so this function should be used with caution.
 * 
 * @param $obj
 * @return array representation of $obj
 */
function object_to_array_recursive($obj)
{
    if (!is_object($obj)) {
        return $obj;
    }
    $ret = get_object_vars($obj);
    foreach ($ret as $key => $val) {
        if (is_object($val)) {
            $ret[$key] = object_to_array_recursive($val);
        }
    }
    return $ret;
}
 public function testobject_to_array_recursive()
 {
     //execute the method and test if it returns expected values
     //test invalid input
     $obj = '';
     $expected = '';
     $actual = object_to_array_recursive($obj);
     $this->assertSame($actual, $expected);
     //test with a valid object
     $obj = new TimeDate();
     $expected = array('dbDayFormat' => 'Y-m-d', 'dbTimeFormat' => 'H:i:s', 'allow_cache' => true);
     $actual = object_to_array_recursive($obj);
     $this->assertSame($actual, $expected);
 }