Convert an array to object

NOTE: in case of any issues during the conversion, this
method will return an empty \stdClass instance and NOT throw
any exceptions.

@param mixed[] $source Array to convert
@return \stdClass
498939
public static function arrayToObject(array $source): \stdClass
    {
        $result = new stdClass();

        $json = json_encode($source);
        if ($json === false) {
            return $result;
        }

        $object = json_decode($json);
        if ($object === null) {
            return $result;
        }
        $result = $object;

        return $result;
    }
218242
public function fromArray(array $object = array())
    {
        if (count($object) > 0) {
            $reflector = new \ReflectionClass($this);
            $properties = InjectorHelper::extractProperties($reflector, \ReflectionProperty::IS_PUBLIC, InjectorHelper::VAR_PATTERN);
            unset($reflector);
            foreach ($object as $key => $value) {
                if (property_exists($this, $key) && null !== $value) {
                    $this->parseDtoField($properties, $key, $value);
                }
            }
        }
    }
913378
protected function convertToObject($arrayElements)
	{
		$objects = array();
		
		foreach ($arrayElements as $key => $value) {
			$object = new \stdClass();
			$object->name = $key;
			$object->value = $value;
			$objects[] = $object;
		}

		return $objects;
	}
452490
function jsonSerialize(): \stdClass {
    return (object) [
      'sourceFile' => $this->getSourceFile(),
      'branches' => ($branches = $this->getBranches()) ? $branches->jsonSerialize() : null,
      'functions' => ($functions = $this->getFunctions()) ? $functions->jsonSerialize() : null,
      'lines' => ($lines = $this->getLines()) ? $lines->jsonSerialize() : null
    ];
  }
218133
private static function cloneArray(array $source): array
    {
        $ret = [];
        foreach ($source as $key => $value) {
            if (is_array($value)) {
                $ret[$key] = self::cloneArray($value);
            } else if (is_object($value)) {
                $ret[$key] = clone $value;
            } else {
                $ret[$key] = $value;
            }
        }
        return $ret;
    }
661911
protected static function objectRecursive(Array $array, stdClass &$std) : stdClass
    {
        foreach( $array as $key => $value )
        {
            if( is_array($value) )
            {
                $std->$key = new stdClass;

                self::objectRecursive($value, $std->$key);
            }
            else
            {
                $std->$key = $value;
            }
        }

        return $std;
    }
302445
public function fromJSON( $source )
	{
		$types = json_decode( $source, true );

		if ( json_last_error() !== JSON_ERROR_NONE )
		{
			$message = sprintf( "Error parsing JSON %s", XBRL::json_last_error_msg() );
			XBRL_Log::getInstance()->err( $message );
			return false;
		}

		return $this->fromArray( $types );
	}
984836
public static function object_to_array($d) {
		if ( is_object( $d ) ) {
			// Gets the properties of the given object with get_object_vars function
			$d = get_object_vars( $d );
		}

		if ( is_array( $d ) ) {
			/*
			 * Return array converted to object
			 * Using __FUNCTION__ (Magic constant)
			 * for recursive call
			 */
			return array_map( array( __CLASS__, __FUNCTION__ ), $d);
		}
		else {
			// Return array
			return $d;
		}
	}
22947
public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = NULL) {
		$object = $this->buildObject($convertedChildProperties, $targetType);
		foreach ($convertedChildProperties as $propertyName => $propertyValue) {
			ObjectAccess::setProperty($object, $propertyName, $propertyValue);
		}

		return $object;
	}
1133168
public function convertToString($source)
    {
        if (is_object($source)) {
            if ($source instanceof NamedInterface) {
                return $source->getName();
            } elseif (method_exists($source, '__toString')) {
                return (string) $source;
            } else {
                return get_class($source);
            }
        } elseif (is_scalar($source) || is_null($source)) {
            return (string) $source;
        } else {
            return gettype($source);
        }
    }
629312
protected function objectToArray($object) 
    {
        if (is_object($object)) {
            // Gets the properties of the given object
            // with get_object_vars function
            $object = get_object_vars($object);
        }

        if (is_array($object)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            return array_map(__METHOD__, $object);
        } else {
            // Return array
            return $object;
        }
    }
418415
public static function make($source)
    {
        $engines  = config('datatables.engines');
        $builders = config('datatables.builders');

        $args = func_get_args();
        foreach ($builders as $class => $engine) {
            if ($source instanceof $class) {
                return call_user_func_array([$engines[$engine], 'create'], $args);
            }
        }

        foreach ($engines as $engine => $class) {
            if (call_user_func_array([$engines[$engine], 'canCreate'], $args)) {
                return call_user_func_array([$engines[$engine], 'create'], $args);
            }
        }

        throw new \Exception('No available engine for ' . get_class($source));
    }
988180
public static function fromSource(string $source): array
    {
        $constructs = [];

        try {
            $sequence = \token_get_all(
                $source,
                \TOKEN_PARSE
            );
        } catch (\ParseError $exception) {
            throw Exception\ParseError::fromParseError($exception);
        }

        $count = \count($sequence);
        $namespacePrefix = '';

        for ($index = 0; $index < $count; ++$index) {
            $token = $sequence[$index];

            // collect namespace name
            if (\is_array($token) && \T_NAMESPACE === $token[0]) {
                $namespaceSegments = [];

                // collect namespace segments
                for ($index = self::significantAfter($index, $sequence, $count); $index < $count; ++$index) {
                    $token = $sequence[$index];

                    if (\is_array($token) && \T_STRING !== $token[0]) {
                        continue;
                    }

                    $content = self::content($token);

                    if (\in_array($content, ['{', ';'], true)) {
                        break;
                    }

                    $namespaceSegments[] = $content;
                }

                $namespace = \implode('\\', $namespaceSegments);
                $namespacePrefix = $namespace . '\\';
            }

            // skip non-classy tokens
            if (!\is_array($token) || !\in_array($token[0], [\T_CLASS, \T_INTERFACE, \T_TRAIT], true)) {
                continue;
            }

            // skip anonymous classes
            if (\T_CLASS === $token[0]) {
                $current = self::significantBefore($index, $sequence);
                $token = $sequence[$current];

                // if significant token before T_CLASS is T_NEW, it's an instantiation of an anonymous class
                if (\is_array($token) && \T_NEW === $token[0]) {
                    continue;
                }
            }

            $index = self::significantAfter($index, $sequence, $count);
            $token = $sequence[$index];

            $constructs[] = Construct::fromName($namespacePrefix . self::content($token));
        }

        \usort($constructs, static function (Construct $a, Construct $b) {
            return \strcmp(
                $a->name(),
                $b->name()
            );
        });

        return $constructs;
    }
390364
public static function arrayToObject($data)
    {
        if (is_array($data)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            $self_name = 'self::' . __FUNCTION__;

            return (object)array_map($self_name, $data);
        } else {
            // Return object
            return $data;
        }
    }
979615
public static function fromArray($array=array())
    {
        $className = get_called_class();

        // hack that uses object deserialization to bypass constructor
        $object = unserialize(sprintf('O:%d:"%s":0:{}',
            strlen($className),
            $className));

        $object->_data = $array;
        $object->_saved = true;

        return $object;
    }
165893
protected function objectToArray($object, array $exclude)
  {
    $array = (array) $this->objectToPublicObject($object, $exclude);

    foreach ($array as $key => $value)
    {
      if (is_object($value))
      {
        $value = $this->objectToArray($value, $this->excludeNext($key, $exclude));
      }
      $array[$key] = $value;
    }

    return $array;
  }
1314244
public static function fromArray( $source )
	{
		try
		{
			$classname = get_called_class();

			if ( ! class_exists( $classname ) )
			{
				\XBRL_Log::getInstance()->err( "The class '$classname' does not exist" );
				return null;
			}

			$instance = new $classname();

			if ( ! $instance instanceof Resource )
			{
				\XBRL_Log::getInstance()->err( "The class instance being created MUST inherit from 'XBRL\\Formulas\\Resources\\Resources'" );
				return null;
			}

			$has = get_object_vars( $instance );
			foreach ( $has as $name => $oldValue )
			{
	        	if ( ! isset( $source[ $name ] ) ) continue;
	        	$instance->$name = $source[ $name ];
			}

			return $instance;
		}
		catch( \Exception $ex )
		{
			return null;
		}
	}