Recursively gets variables from all template/data scopes

@param  Smarty_Internal_Template|Smarty_Data $obj object to debug

@return StdClass
194496
public function get_debug_vars($obj)
    {
        $config_vars = array();
        foreach ($obj->config_vars as $key => $var) {
            $config_vars[$key]['value'] = $var;
            if ($obj->_objType == 2) {
                $config_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
            } elseif ($obj->_objType == 4) {
                $tpl_vars[$key]['scope'] = $obj->dataObjectName;
            } else {
                $config_vars[$key]['scope'] = 'Smarty object';
            }
        }
        $tpl_vars = array();
        foreach ($obj->tpl_vars as $key => $var) {
            foreach ($var as $varkey => $varvalue) {
                if ($varkey == 'value') {
                    $tpl_vars[$key][$varkey] = $varvalue;
                } else {
                    if ($varkey == 'nocache') {
                        if ($varvalue == true) {
                            $tpl_vars[$key][$varkey] = $varvalue;
                        }
                    } else {
                        if ($varkey != 'scope' || $varvalue !== 0) {
                            $tpl_vars[$key]['attributes'][$varkey] = $varvalue;
                        }
                    }
                }
            }
            if ($obj->_objType == 2) {
                $tpl_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
            } elseif ($obj->_objType == 4) {
                $tpl_vars[$key]['scope'] = $obj->dataObjectName;
            } else {
                $tpl_vars[$key]['scope'] = 'Smarty object';
            }
        }

        if (isset($obj->parent)) {
            $parent = $this->get_debug_vars($obj->parent);
            foreach ($parent->tpl_vars as $name => $pvar) {
                if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) {
                    $tpl_vars[$name]['scope'] = $pvar['scope'];
                }
            }
            $tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);

            foreach ($parent->config_vars as $name => $pvar) {
                if (isset($config_vars[$name]) && $config_vars[$name]['value'] === $pvar['value']) {
                    $config_vars[$name]['scope'] = $pvar['scope'];
                }
            }
            $config_vars = array_merge($parent->config_vars, $config_vars);
        } else {
            foreach (Smarty::$global_tpl_vars as $key => $var) {
                if (!array_key_exists($key, $tpl_vars)) {
                    foreach ($var as $varkey => $varvalue) {
                        if ($varkey == 'value') {
                            $tpl_vars[$key][$varkey] = $varvalue;
                        } else {
                            if ($varkey == 'nocache') {
                                if ($varvalue == true) {
                                    $tpl_vars[$key][$varkey] = $varvalue;
                                }
                            } else {
                                if ($varkey != 'scope' || $varvalue !== 0) {
                                    $tpl_vars[$key]['attributes'][$varkey] = $varvalue;
                                }
                            }
                        }
                    }
                    $tpl_vars[$key]['scope'] = 'Global';
                }
            }
        }

        return (object) array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
    }
624310
public function objectToXml($obj)
    {
        //====================================================================//
        // Create Transmition Object
        $tmp = new stdClass();
        $tmp->SPLASH = $obj;
        //====================================================================//
        // Convert Object to XML Recursively
        $this->objectToXmlCore(self::$xml, $tmp);
        //====================================================================//
        // Put End Element on Xml
        self::$xml->endElement();
        //====================================================================//
        // Output Result
        return self::$xml->outputMemory(true);
    }
984288
public function toObject(bool $recursive = false) : \stdClass
    {
        $o = new \stdClass();
        if (!$recursive) {
            foreach ($this->explorableIndex as $property) {
                $o->{$property} = $this->{$property};
            }
        } else {
            foreach ($this->explorableIndex as $property) {
                $value = $this->{$property};
                $o->{$property} = !($value instanceof Explorable) ? $value : $value->toObject(true);
            }
        }
        return $o;
    }
820584
public static function objectToArray($obj)
    {
        if (is_object($obj)) {
            if (method_exists($obj, 'toArray')) {
                $obj = $obj->toArray();
            } elseif (method_exists($obj, '__toArray')) {
                $obj = $obj->__toArray();
            } else {
                $obj = (array)$obj;
            }
        }
        if (is_array($obj)) {
            $new = [];
            foreach ($obj as $key => $val) {
                $new[$key] = self::objectToArray($val);
            }
        } else {
            $new = $obj;
        }

        return $new;
    }
529019
public function getMetaObject(string $obj): self
    {
        static $STATIC_CACHE = [];

        $cacheKey = $obj;
        if (!empty($STATIC_CACHE[$cacheKey])) {
            return $STATIC_CACHE[$cacheKey];
        }

        $reflector = new \ReflectionClass($obj);
        $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
        $docComment = $reflector->getDocComment();
        if ($docComment) {
            $docblock = $factory->create($docComment);
            foreach ($docblock->getTagsByName('property') as $tag) {
                /** @var \phpDocumentor\Reflection\DocBlock\Tags\Property $tag */
                $PropertyName = $tag->getVariableName();
                $this->{$PropertyName} = $PropertyName;
            }
        }

        $STATIC_CACHE[$cacheKey] = $this;

        return $this;
    }
235503
private function get_array_value( $obj ) {
		if ( $obj instanceof \stdClass ) {
			$obj = get_object_vars( $obj );
		} elseif ( ! is_array( $obj ) ) {
			if ( method_exists( $obj, 'to_array' ) ) {
				$obj = $obj->to_array();
			}
		}
		if ( ! is_array( $obj ) || empty( $obj ) ) {
			return [];
		}

		return $obj;
	}
1141064
public static function object_to_array($obj)
	{
		//$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
		if(is_object($obj) || is_array($obj)){
			if(is_object($obj)){
				$_arr = get_object_vars($obj);
			}else{
				$_arr = $obj;
			}
			foreach ($_arr as $key => $val)
			{
				$val = (is_array($val) || is_object($val)) ? self::object_to_array($val) : $val;
				$arr[$key] = $val;
			}
			return $arr;
		}else{
			return $obj;
		}
		
	}
1314415
public function getAttr($obj, $attr, $args = [])
    {
        if (is_array($obj)) {
            if (isset($obj[$attr])) {
                if ($obj[$attr] instanceof \Closure) {
                    if (is_array($args)) {
                        array_unshift($args, $obj);
                    } else {
                        $args = [$obj];
                    }

                    return call_user_func_array($obj[$attr], $args);
                }

                return $obj[$attr];
            }

            return null;
        } elseif (is_object($obj)) {
            if (is_array($args)) {
                $callable = [$obj, $attr];

                return is_callable($callable) ?
                    call_user_func_array($callable, $args) : null;
            }
            $members = array_keys(get_object_vars($obj));
            $methods = get_class_methods(get_class($obj));
            if (in_array($attr, $members)) {
                return @$obj->$attr;
            } elseif (in_array('__get', $methods)) {
                return $obj->__get($attr);
            }
            $callable = [$obj, $attr];

            return is_callable($callable) ?
                call_user_func($callable) : null;
        }

        return null;
    }
244804
function get_object($sql, $class_name = 'stdClass', array $params = null)
	{
		$rs = $this->query($sql, MYSQLI_USE_RESULT);
		$obj = is_null($params) ? $rs->fetch_object($class_name) : $rs->fetch_object($class_name, $params);
		$rs->free_result();
		return $obj;
	}
615691
protected function invokeProperty($obj, $property = null)
    {
        if (null === $property) {
            return null;
        }

        if (!settype($property, 'string')) {
            return null;
        }

        $property = trim($property);
        if (0 === mb_strlen($property)) {
            return null;
        }

        if (!is_object($obj)) {
            return null;
        }

        $methods = [
            $this->createMethodName('get', $property),
            $this->createMethodName('is', $property),
            $property
        ];

        $r = new \ReflectionObject($obj);
        foreach ($methods as $method) {
            if ($r->hasMethod($method)) {
                $result = $r->getMethod($method)->invoke($obj);

                return $result;
            }
        }

        if ($r->hasProperty($property)) {
            $rProperty = $r->getProperty($property);
            if ($rProperty->isPublic()) {
                $result = $rProperty->getValue($obj);

                return $result;
            }
        }

        return null;
    }
625641
public function pegaAtributosDoObjeto($obj)
    {
        $properties      = [];
        $reflectionClass = new ReflectionClass($obj);
        $propriedades    = $reflectionClass->getProperties(
            ReflectionProperty::IS_PUBLIC |
            ReflectionProperty::IS_PROTECTED | 
            ReflectionProperty::IS_PRIVATE
        );
     
        $iterator = 0;
        $limit    = count($propriedades);
        for ($iterator = 0; $iterator < $limit; $iterator++) {
            $properties[$iterator] = $propriedades[$iterator]->name;
        }

        return $properties;
    }
1075984
public static function getProperties($obj)
    {
        $properties = array();
        try {
            $rc = new ReflectionClass($obj);
            do {
                $rp = array();

                // Note that we will not include any properties in traits
                $traits = $rc->getTraits();
                $skipProperties = array();
                if (!empty($traits)) {
                    foreach ($traits as $trait) {
                        foreach ($trait->getProperties() as $traitProperty) {
                            $skipProperties[] = $traitProperty->getName();
                        }
                    }
                }
                /* @var $p \ReflectionProperty */
                foreach ($rc->getProperties() as $p) {
                    if (in_array($p->getName(), $skipProperties, true)) {
                        continue;
                    }
                    $p->setAccessible(true);
                    $rp[$p->getName()] = $p->getValue($obj);
                }
                $properties = array_merge($rp, $properties);
            } while ($rc = $rc->getParentClass());
        } catch (ReflectionException $e) {
            //
        }
        return $properties;
    }
492950
public function setValue($value, $obj = null)
    {
        // If we're not passed a value directly,
        // we can look for it in a relation method on the object passed as a second arg
        if ($obj instanceof DataObject) {
            $this->loadFrom($obj);
        } else {
            parent::setValue($value);
        }
        return $this;
    }
502216
protected function _convertToArray($obj) {
        $arr    = array();
        $arrObj = is_object($obj) ? get_object_vars($obj) : $obj;

        foreach ($arrObj as $key => $val) {
            if (is_object($val)) {
                switch (get_class($val)) {
                case 'Garp_Spawn_Relation_Set':
                    $val = $val->getRelations();
                    break;
                case 'Garp_Spawn_Behaviors':
                    $val = $val->getBehaviors();
                    break;
                case 'Garp_Spawn_Fields':
                    $val = $val->getFields();
                }

                $val = $this->_convertToArray($val);
            } elseif (is_array($val)) {
                $val = $this->_convertToArray($val);
            }
            $arr[$key] = $val;
        }

        return $arr;
    }
1032961
private function parseData($obj)
    {
        $data = [
            'temperature' => [
                'now' => [
                    'value' => $obj->temperature->now->getValue(),
                    'unit' => $obj->temperature->now->getUnit()
                ],
                'min' => [
                    'value' => $obj->temperature->min->getValue(),
                    'unit' => $obj->temperature->min->getUnit()
                ],
                'max' => [
                    'value' => $obj->temperature->max->getValue(),
                    'unit' => $obj->temperature->max->getUnit()
                ]
            ],
            'humidity' => [
                'value' => $obj->humidity->getValue(),
                'unit' => $obj->humidity->getUnit()
            ],
            'pressure' => [
                'value' => $obj->pressure->getValue(),
                'unit' => $obj->pressure->getUnit()
            ],
            'wind' => [
                'speed' => [
                    'value' => $obj->wind->speed->getValue(),
                    'unit' => $obj->wind->speed->getUnit(),
                    'description' => $obj->wind->speed->getDescription(),
                    'description_slug' => str_slug($obj->wind->speed->getDescription())
                ],
                'direction' => [
                    'value' => $obj->wind->direction->getValue(),
                    'unit' => $obj->wind->direction->getUnit(),
                    'description' => $obj->wind->direction->getDescription(),
                    'description_slug' => str_slug($obj->wind->direction->getDescription())
                ]
            ],
            'clouds' => [
                'value' => $obj->clouds->getValue(),
                'unit' => $obj->clouds->getUnit(),
                'description' => $obj->clouds->getDescription(),
                'description_slug' => str_slug($obj->clouds->getDescription())
            ],
            'precipitation' => [
                'value' => $obj->precipitation->getValue(),
                'unit' => $obj->precipitation->getUnit(),
                'description' => $obj->precipitation->getDescription(),
                'description_slug' => str_slug($obj->precipitation->getDescription())
            ],
            'weather' => [
                'id' => $obj->weather->id,
                'description' => $obj->weather->description,
                'description_slug' => str_slug($obj->weather->description),
                'icon' => $obj->weather->icon
            ],
        ];

        return $data;
    }
1090759
public function getPileContentID(&$obj)
    {
        $db = Loader::db();
        switch (strtolower(get_class($obj))) {
            case "page":
                $v = array($this->pID, $obj->getCollectionID(), "COLLECTION");
                $q = "select pcID from PileContents where pID = ? and itemID = ? and itemType = ?";
                $pcID = $db->getOne($q, $v);
                if ($pcID > 0) {
                    return $pcID;
                }
                break;
        }
    }
603709
public static Scriptable getTopLevelScope(Scriptable obj)
    {
        for (;;) {
            Scriptable parent = obj.getParentScope();
            if (parent == null) {
                return obj;
            }
            obj = parent;
        }
    }