Create a new Type from an object or a class string.

@param mixed $object

@return Type
960968
public static function from($object): self
    {
        if ($object instanceof self) {
            return $object;
        }

        if (\is_object($object)) {
            $object = \get_class($object);
        }

        if (! \is_string($object)) {
            throw new InvalidArgumentException('Cannot create a type from '.\gettype($object));
        }

        return new self($object);
    }
441715
public function getValue($object) {
		if(null === $this->reflectionClass) {
			$this->reflectionClass = new \ReflectionClass($this->class);
		}
		$method = $this->reflectionClass->getMethod($this->getter);
		return $method->invoke($object);
	}
780810
static function addInstance($object){
		$name = str_replace(DS,'.',get_class($object));
		self::$instance[$name] = $object;
	}
1079710
protected function doExtract($object)
    {
        $originalFieldNames = $this->metadata->getOriginalFieldNames();

        /*
        $filter = $object instanceof FilterProviderInterface
            ? $object->getFilter()
            : $this->filterComposite;
        */

        $data = [];
        if (! $this->metadata->hasCustomHydrator()) {

            $this->executeMethods($object, $this->metadata->getPreExtractListeners());

            foreach ($originalFieldNames as $originalFieldName) {
                $mappedFieldName = $this->metadata->getMappedFieldName($originalFieldName);

                if ($this->metadata->isNotManaged($mappedFieldName)) {
                    continue;
                }

                if ($this->metadata->isValueObject($mappedFieldName)) {
                    continue;
                }

                /*if ($filter && !$filter->filter($mappedFieldName)) {
                    continue;
                }*/

                try {
                    $value = $this->memberAccessStrategy->getValue($object, $mappedFieldName);             
                } catch (NotFoundMemberException $e) {
                    continue;
                }

                if (null === $value) {
                    $data[$originalFieldName] = null;
                    continue;
                }

                if ($fieldClass = $this->metadata->getClassOfMappedField($mappedFieldName)) {
                    $fieldHydrator = $this->objectManager->createHydratorFor($fieldClass);
                    $fieldValue = $value;

                    /*if (! is_array($fieldValue)) {
                        throw new ObjectMappingException(
                            sprintf(
                                'Cannot hydrate field "%s" of class "%s" from raw data.'
                                . ' Raw data should be an array but got "%s".', 
                                $mappedFieldName,
                                $fieldClass,
                                is_object($fieldValue) ? get_class($fieldValue) : gettype($fieldValue)
                                )
                        );
                    }   */
                    
                    reset($fieldValue);
                    if (0 !== count($fieldValue) && ! is_numeric(key($fieldValue))) {
                        $fieldRawData = $fieldHydrator->extract($fieldValue);
                        $data[$originalFieldName] = $fieldRawData;                              
                    } else {

                        $fieldRawData = [];
                        foreach ($fieldValue as $itemFieldValue) {              
                            $fieldRawData[] = $fieldHydrator->extract($itemFieldValue);                
                        }
                        $data[$originalFieldName] = $fieldRawData;
                    }   
                } else {
                    $value = $this->extractValue($mappedFieldName, $value, $object, $data);
                    $data[$originalFieldName] = $value;    
                }
            }
        } else {
            list($customHydratorClass, , $customExtractMethod) = $this->metadata->getCustomHydratorInfo();            
            $this->executeMethod($object, new ClassMetadata\Model\Method($customHydratorClass, $customExtractMethod, [$object]));
        }

        //Value objects extraction.
        foreach ($this->metadata->getFieldsWithValueObjects() as $mappedFieldName) {

            if ($this->metadata->isNotManaged($mappedFieldName)) {
                continue;
            }

            $info = $this->metadata->getValueObjectInfo($mappedFieldName);
            list($voClassName, $voResource, $voResourceType) = $info;

            $valueObjectHydrator = $this->objectManager->createHydratorFor($voClassName);
            $objectKey = $this->pushRuntimeConfiguration($mappedFieldName, $object, $voClassName, $voResourceType, $voResource);

            $valueObject = $this->memberAccessStrategy->getValue($object, $mappedFieldName);
            $valueObjectData = $valueObjectHydrator->extract($valueObject, $objectKey);
            $this->popRuntimeConfiguration();

            $data = array_merge($data, $valueObjectData);
        }

        $this->executeMethods($object, $this->metadata->getPostExtractListeners());

        return $data;
    }
139738
public function prepareObject($object)
    {
        $tokenList = $this->getMethodTokenList();

        for ($i = 0, $c = count($tokenList); $i < $c; $i++) {
            if ($this->reflection->hasMethod(self::SETTER_PREFIX . ucfirst($tokenList[$i]['property']))) {
                $m = self::SETTER_PREFIX . ucfirst($tokenList[$i]['property']);
                if ($tokenList[$i]['type'] == RouteMethodAnnotaionParser::TYPE_CLASS) {
                    $value = new $tokenList[$i]['value']();
                } else {
                    $value = $tokenList[$i]['value'];
                }
                $object->$m($value);
            }
        }

        return $object;
    }
1365718
public static function fromObject($object){
        $issue = new \sb\Gitlab\P();
        foreach(get_object_vars($object) as $k=>$v){
           
            switch($k){
                case 'assignee':
                case 'author':
                    if(!is_object($v)){
                        $issue->{$k} = $v;
                        break;
                    }
                    $user = new \sb\Gitlab\User();
                    foreach(get_object_vars($v) as $uk=>$uv){
                        $user->{$uk} = $uv;
                    }
                    $issue->{$k} = $user;
                    break;

                default:
                    $issue->{$k} = $v;
            }
                
        }
        
        return $issue;
    }
800690
public static function createAdapterObject($object)
    {
        $wrapperObject = self::create($object, null, function ($method, $arguments, $result) {
            $data['method']    = $method;
            $data['arguments'] = $arguments;

            $appType = php_sapi_name();
            if ($appType == 'cli') {
                $processName = @cli_get_process_title();
                if (strpos($processName, 'msf') !== false) {
                    $appType = 'msf';
                }
            } else {
                $appType = 'web';
            }

            if ($appType != 'msf' && $result instanceof \Generator) {
                $data['result'] = $result->getReturn();
                return $data;
            }

            $data['result'] = $result;
            return $data;
        });

        return $wrapperObject;
    }
801902
protected static function objectToArray($object)
    {
        if (!\is_object($object)) {
            return $object;
        }

        if (\is_object($object)) {
            $object = \get_object_vars($object);
        }

        return \array_map(['static', 'objectToArray'], $object);
    }
678440
public function oxClone($object)
    {
        $classVariables = get_object_vars($object);
        foreach ($classVariables as $name => $value) {
            if (is_object($object->$name)) {
                $this->$name = clone $object->$name;
            } else {
                $this->$name = $object->$name;
            }
        }
    }
1055608
private function doCreateProxy($object)
    {
        $proxy = $this->factory->createProxy($object);
        /* $this in closures does not work with PHP 5.3
         * so we have to pass the object explicitely
         * with its private properties */
        $_this = $this;
        $securityContext = $this->services['security.context'];

        foreach($this->protected_classes[ClassUtils::getRealClass($object)]['methods'] as $method => $options) {
            $attribute = isset($options['attribute']) ? $options['attribute'] : false;
            $expression = isset($options['expression']) ? $options['expression'] : false;
            $returnProxy = isset($options['return_proxy']) ? $options['return_proxy'] : false;
            $denyValue = isset($options['deny_value']) ? $options['deny_value'] : null;

            if($attribute != false && $expression != false) {
                $proxy->setMethodPrefixInterceptor($method,
                    function($proxy, $instance, $methodName, $params, & $returnEarly) use ($expression, $attribute, $denyValue, $securityContext)
                    {
                        if (!($securityContext->isGranted(new Expression($expression), $instance) && $securityContext->isGranted($attribute, $instance)))  {
                            $returnEarly = true;
                            return $denyValue;
                        } else {
                            $returnEarly = false;
                            return;
                        }
                    }
                );
                continue;
            }

            if($attribute != false) {
                $proxy->setMethodPrefixInterceptor($method,
                    function($proxy, $instance, $methodName, $params, & $returnEarly) use ($attribute, $denyValue, $securityContext)
                    {
                        if (!$securityContext->isGranted($attribute, $instance)) {
                            $returnEarly = true;
                            return $denyValue;
                        } else {
                            $returnEarly = false;
                            return;
                        }
                    }
                );
                continue;
            }

            if($expression != false) {
                $proxy->setMethodPrefixInterceptor($method,
                    function($proxy, $instance, $methodName, $params, & $returnEarly) use ($expression, $denyValue, $securityContext)
                    {
                        if (!$securityContext->isGranted(new Expression($expression), $instance)) {
                            $returnEarly = true;
                            return $denyValue;
                        } else {
                            $returnEarly = false;
                            return;
                        }
                    }
                );
            }

            if($returnProxy) {
                $proxy->setMethodSuffixInterceptor($method,
                    function ($proxy, $instance, $methodName, $params, $returnValue, & $returnEarly) use ($_this)
                    {
                        if(is_object($returnValue) && $returnValue === $proxy) {
                            $returnEarly = false;
                            return;
                        } else if ($_this->isProtected($returnValue)) {
                            $returnEarly = true;
                            return $_this->getProxy($returnValue);
                        } else if (is_array($returnValue)
                            || $returnValue instanceof \Traversable
                            || $returnValue instanceof \ArrayAccess
                        ) {
                            $return = array();
                            foreach($returnValue as $element) {
                                if($_this->isProtected($element)) {
                                    $return[] = $_this->getProxy($element);
                                } else {
                                    $return[] = $element;
                                }
                            }
                            $returnEarly = true;
                            return $return;
                        }
                    }
                );
            }
        } // end foreach

        return $proxy;
    }
660268
protected function createPathSegmentForObject($object)
    {
        $matches = [];
        preg_match_all('/(?P<dynamic>{?)(?P<content>[^}{]+)}?/', $this->getUriPattern(), $matches, PREG_SET_ORDER);
        $pathSegment = '';
        foreach ($matches as $match) {
            if (empty($match['dynamic'])) {
                $pathSegment .= $match['content'];
            } else {
                $dynamicPathSegmentParts = explode(':', $match['content']);
                $propertyPath = $dynamicPathSegmentParts[0];
                $dynamicPathSegment = ObjectAccess::getPropertyPath($object, $propertyPath);
                if (is_object($dynamicPathSegment)) {
                    if ($dynamicPathSegment instanceof \DateTimeInterface) {
                        $dateFormat = isset($dynamicPathSegmentParts[1]) ? trim($dynamicPathSegmentParts[1]) : 'Y-m-d';
                        $pathSegment .= $this->rewriteForUri($dynamicPathSegment->format($dateFormat));
                    } else {
                        throw new InvalidUriPatternException(sprintf('Invalid uriPattern "%s" for route part "%s". Property "%s" must be of type string or \DateTime. "%s" given.', $this->getUriPattern(), $this->getName(), $propertyPath, is_object($dynamicPathSegment) ? get_class($dynamicPathSegment) : gettype($dynamicPathSegment)), 1316442409);
                    }
                } else {
                    $pathSegment .= $this->rewriteForUri($dynamicPathSegment);
                }
            }
        }
        return $pathSegment;
    }
600255
public static function createFromObject(\Traversable $object): self
    {
        // init
        $array = new static();

        if ($object instanceof self) {
            $objectArray = $object->getGenerator();
        } else {
            $objectArray = $object;
        }

        foreach ($objectArray as $key => $value) {
            $array[$key] = $value;
        }

        return $array;
    }
396472
protected function sortObject($object)
    {
        $sort_array = get_object_vars($object);
        ksort($sort_array);

        $new_object = new stdClass();
        foreach ($sort_array as $key => $value) {
            if (is_object($value)) {
                $value = $this->sortObject($value);
            }
            $new_object->$key = $value;
        }

        unset($sort_array);
        unset($object);

        return $new_object;
    }
976861
public function from_post( $object )
	{
		if ( is_array( $object ) ) {

			$this->attributes = $object;

		} else if ( is_a( $object, 'WP_Post' ) ) {

			$this->attributes = $object->to_array();

		}

		if ( ! empty( $this->attributes ) ) {

			$this->load_meta();
			
		}

		return $this;
	}
326362
public static function arrayToObject($array, &$object = null, $type = null) {
        $object = isset($object) ? $object : (isset($type) ? new $type() : new \stdClass());

        ksort($array);

        foreach ($array as $key => $value)
        {
            if (strpos($key, '_') === false) {
                $activeObject = $object;
                
                if (is_array($object) && $type !== null) {
                    $activeObject = new $type();
                    $object[] = $activeObject;
                }

                // is array
                if (substr($key, -1) == ']') {
                    $key = substr($key, 0, strrpos($key, '['));

                    if (!isset($activeObject->$key) || !is_array($activeObject->$key)) {
                        $activeObject->$key = array();
                    }

                    if (is_array($value)) {
                        foreach ($value as $v) {
                            $activeObject->{$key}[] = $v;
                        }
                    }
                    else {
                        $activeObject->{$key}[] = $value;
                    }
                }
                else {
                    $activeObject->$key = $value;
                }
            } else {
                $name = explode('_', $key);
                $activeObject = $object;

                while (count($name) > 1) {
                    $current = array_shift($name);
                    $isArray = false;

                    // is array
                    if (substr($current, -1) == ']') {
                        $index = substr($current, strrpos($current, '[') + 1, -1);
                        $current = substr($current, 0, strrpos($current, '['));
                        $isArray = true;
                    }

                    if (isset($activeObject->$current)) {
                        if ($isArray) {
                            if (!isset($activeObject->$current[$index])) {
                                $activeObject->$current[$index] = (isset($type) ? new $type() : new \stdClass());
                            }

                            $activeObject = $activeObject->$current[$index];
                        }
                        else {
                            $activeObject = $activeObject->$current;
                        }

                        continue;
                    }

                    $reflection = new \ReflectionClass($activeObject);

                    if (isset($reflection) &&  $reflection->hasProperty($current)) {
                        $property = $reflection->getProperty($current);

                        if (($propertyComment = $property->getDocComment()) !== null && $propertyComment !== '' && preg_match('/@var\s+(?<name>[^\n]+)/', $propertyComment, $m) === 1) {
                            $propertyType = trim($m[1]);

                            if (substr($propertyType, -1) == ']') {
                                $propertyType = substr($propertyType, 0, strrpos($propertyType, '['));
                            }

                            if (!class_exists($propertyType)) {
                                if (is_object($object)) {
                                    $objectReflection = new \ReflectionClass($object);
                                    $propertyTypeNamesapce = $objectReflection->getNamespaceName();
                                }
                                elseif ($type !== null && $type != '\stdClass') {
                                    $propertyTypeNamesapce = substr($type, 0, strrpos($type, '\\'));
                                }

                                if (class_exists($propertyTypeNamesapce . '\\' . $propertyType)) {
                                    $propertyType = $propertyTypeNamesapce . '\\' . $propertyType;
                                }
                                else {
                                    $propertyType = '\stdClass';
                                }
                            }
                        }
                        else {
                            $propertyType = '\stdClass';
                        }
                    }
                    else {
                        $propertyType = '\stdClass';
                    }

                    if ($isArray) {
                        $newObject = array();
                        $newObject[$index] = new $propertyType();
                        $type = $propertyType;
                    }
                    else {
                        $newObject = new $propertyType();
                        $type = null;
                    }

                    if (isset($property)) {
                        $property->setValue($activeObject, $newObject);
                    }
                    else {
                        $activeObject->$current = $newObject;
                    }

                    $activeObject = ($isArray ? $newObject[$index] : $newObject);
                }

                self::arrayToObject(array($name[0] => $value), $activeObject, $type);
            }
        }
    }
641664
public function createObjectType() : ObjectConstructorCallbackDefiner
    {
        return new ObjectConstructorCallbackDefiner($this->class, function (callable $typeCallback) {
            $this->createObjectCallback = function (array $input) use ($typeCallback) {
                $className = $this->class->getClassName();

                /** @var TypedObject|string $instanceOrType */
                $instanceOrType = $typeCallback($input);

                if (is_string($instanceOrType)) {
                    if (class_exists($instanceOrType) && is_a($instanceOrType, $className, true)) {
                        $instanceOrType = $instanceOrType::definition()->newCleanInstance();
                    }
                }

                if (!($instanceOrType instanceof $className)) {
                    throw InvalidReturnValueException::format(
                        'Invalid create object callback return value: expecting class compatible with %s, %s given',
                        $className, is_string($instanceOrType) ? $instanceOrType : Debug::getType($instanceOrType)
                    );
                }

                return $instanceOrType;
            };
        });
    }
339279
public function extend($object=null) {
    $args = self::_wrapArgs(func_get_args(), 1);
    
    $num_args = func_num_args();
    if($num_args === 1) return $object;
    
    $is_object = is_object($object);
    $array = (array) $object;
    $__ = new self;
    $extensions = $__->rest(func_get_args());
    foreach($extensions as $extension) {
      $extension = (array) $extension;
      $array = array_merge($array, $extension);
    }
    return self::_wrap(($is_object) ? (object) $array : $array);
  }