Read from a string and create an array

@param  string   $string
@param  bool     $object  If TRUE return a ObjectConfig, if FALSE return an array. Default TRUE.
@throws \DomainException
@return ObjectConfigXml|array
766331
public function fromString($string, $object = true)
    {
        $data = array();

        if(!empty($string))
        {
            $xml  = simplexml_load_string($string);

            if($xml === false) {
                throw new \DomainException('Cannot parse XML string');
            }

            foreach ($xml->children() as $node) {
                $data[(string) $node['name']] = self::_decodeValue($node);
            }
        }

        return $object ? $this->merge($data) : $data;
    }
971891
protected function parse($object)
    {
        if (! is_object($object)) {
            throw new ValidationException(
                'DocumentLink has to be an object, "' . gettype($object) . '" given.'
            );
        }

        $links = get_object_vars($object);

        if (array_key_exists('self', $links)) {
            if (! is_string($links['self']) and ! is_object($links['self'])) {
                throw new ValidationException(
                    'property "self" has to be a string or object, "' .
                    gettype($links['self']) . '" given.'
                );
            }

            $this->setLink('self', $links['self']);

            unset($links['self']);
        }

        if (array_key_exists('related', $links)) {
            if (! is_string($links['related']) and ! is_object($links['related'])) {
                throw new ValidationException(
                    'property "related" has to be a string or object, "' .
                    gettype($links['related']) . '" given.'
                );
            }

            $this->setLink('related', $links['related']);

            unset($links['related']);
        }

        // Pagination links, if data in parent attributes exists
        if ($this->getParent()->has('data')) {
            if (array_key_exists('first', $links)) {
                $this->setPaginationLink('first', $links['first']);

                unset($links['first']);
            }

            if (array_key_exists('last', $links)) {
                $this->setPaginationLink('last', $links['last']);

                unset($links['last']);
            }

            if (array_key_exists('prev', $links)) {
                $this->setPaginationLink('prev', $links['prev']);

                unset($links['prev']);
            }

            if (array_key_exists('next', $links)) {
                $this->setPaginationLink('next', $links['next']);

                unset($links['next']);
            }
        }

        // custom links
        foreach ($links as $name => $value) {
            $this->setLink($name, $value);
        }
    }
1201625
public static function fromString($string)
    {
        if (preg_match(self::PATTERN_FROM_STRING, trim($string), $matches)) {
            if (2 === count($matches)) {
                // whole number
                return new self((int) $matches[1]);
            } else {
                // either x y/z or x/y
                if ($matches[2]) {
                    // x y/z
                    $whole = new self((int) $matches[1]);

                    return $whole->add(new self(
                        (int) $matches[2],
                        (int) $matches[3]
                    ));
                }

                // x/y
                return new self((int) $matches[1], (int) $matches[3]);
            }
        }

        throw new InvalidArgumentException(sprintf(
            'Cannot parse "%s"',
            $string
        ));
    }
815556
public static function decode(string $string)
    {
        $content = json_decode($string, true);

        self::throwOnError();

        return $content;
    }
392987
protected function createObject($object)
    {
        $type = new ObjectType(['class'=>get_class($object)]);

        foreach (get_object_vars($object) as $property=>$value) {
            $type[$property] = $this->toType($value);
        }

        return $type;
    }
996435
public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
	{
		if ($object === null) {
			$object = new SourceCodeInfo();
		}

		if ($end === null) {
			$end = strlen($input);
		}

		while ($start < $end) {
			$tag = Binary::decodeVarint($input, $start);
			$wireType = $tag & 0x7;
			$number = $tag >> 3;
			switch ($number) {
				case 1:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					if (!(isset($object->location) && is_array($object->location))) {
						$object->location = array();
					}
					$length = Binary::decodeVarint($input, $start);
					$expectedStart = $start + $length;
					if ($expectedStart > $end) {
						throw new ProtobufException('Not enough data.');
					}
					$object->location[] = LocationMeta::fromProtobuf($input, null, $start, $start + $length);
					if ($start !== $expectedStart) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
					}
					break;
				default:
					switch ($wireType) {
						case 0:
							Binary::decodeVarint($input, $start);
							break;
						case 1:
							$start += 8;
							break;
						case 2:
							$start += Binary::decodeVarint($input, $start);
							break;
						case 5:
							$start += 4;
							break;
						default:
							throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
					}
			}
		}

		return $object;
	}
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;
    }
609070
public static function FromString( string $objectString )
   {

      $hits = null;

      if ( ! \preg_match( '~^x=(\d{1,4});\s*y=(\d{1,4});\s*width=(\d{1,4});\s*height=(\d{1,4})$~',
         $objectString, $hits ) )
      {
         return false;
      }

      return self::Init(
         \intval( $hits[ 1 ] ),
         \intval( $hits[ 2 ] ),
         \intval( $hits[ 3 ] ),
         \intval( $hits[ 4 ] )
      );

   }
1239969
protected static function convert_object_to_array($object) {
	if (is_object($object) == false) {
		throw new \Exception('can only convert objects');
	}
	
	if ($object instanceof \alsvanzelf\jsonapi\resource) {
		return $object->get_array();
	}
	
	return get_object_vars($object);
}
866006
public function xmlToArray($input = false) {

        if($input && Validate::isString($input)) {

            return simplexml_load_string($string);
        }

        return false;
    }
2717
public function parseString($string)
    {
        if (!mb_strlen($string)) {
            throw new \InvalidArgumentException('Option string must not be empty');
        }
        $options = array();
        $eol = mb_strlen($string) - 1;
        $nextCanBeColon = false;
        for ($i = 0; $i <= $eol; ++$i) {
            $ch = $string[$i];
            if (!preg_match('/^[A-Za-z0-9]$/', $ch)) {
                $colon = $nextCanBeColon ? " or ':'" : '';
                throw new \InvalidArgumentException("Option string is not well formed: "
                    ."expected a letter$colon, found '$ch' at position ".($i + 1));
            }
            if ($i == $eol || $string[$i + 1] != ':') {
                $options[] = new Option($ch, null, Getopt::NO_ARGUMENT);
                $nextCanBeColon = true;
            } elseif ($i < $eol - 1 && $string[$i + 2] == ':') {
                $options[] = new Option($ch, null, Getopt::OPTIONAL_ARGUMENT);
                $i += 2;
                $nextCanBeColon = false;
            } else {
                $options[] = new Option($ch, null, Getopt::REQUIRED_ARGUMENT);
                ++$i;
                $nextCanBeColon = true;
            }
        }
        return $options;
    }
1105961
public static function objectToArray($object)
    {
        if (is_object($object)) {
            $object = (array) $object;
        }

        return is_array($object) ? array_map("static::objectToArray", $object) : $object;
    }
487005
public function createNodeFromNQuads($string)
    {
        $regex = '/'.$this->getRegexStringForNodeRecognition(
            true, true, true, true, true, true
        ).'/si';

        $string = trim($string);

        preg_match($regex, $string, $matches);

        if (0 == count($matches)) {
            throw new \Exception('Invalid parameter $string given. Our regex '.$regex.' doesnt apply.');
        }

        $firstChar = substr($matches[0], 0, 1);

        // http://...
        if ('<' == $firstChar) {
            return $this->createNamedNode(str_replace(['<', '>'], '', $matches[1]));
        // ".."^^<
        } elseif (false !== strpos($matches[0], '"^^<')) {
            return $this->createLiteral($matches[9], $matches[10]);
        // "foo"@en
        } elseif (false !== strpos($matches[0], '"@')) {
            return $this->createLiteral($matches[12], null, $matches[13]);
        // "foo"
        } elseif ('"' == $firstChar) {
            return $this->createLiteral($matches[15]);
        // _:foo
        } elseif ($this->simpleCheckBlankNodeId($matches[0])) {
            return $this->createBlankNode($matches[4]);
        // 0-9 (simple number, multi digits)
        } elseif (0 < (int) $matches[0]) {
            return $this->createLiteral(
                $matches[16],
                $this->createNamedNode('http://www.w3.org/2001/XMLSchema#double')
            );
        } else {
            throw new \Exception('Unknown case for: '.$matches[1]);
        }
        throw new \Exception("The given string (\"$string\") is not valid or doesn't represent any RDF node");
    }
1254601
public static function makeFromObject( $object )
    {
        // inistante object without going via constructer to allow us to
        $refl = new \ReflectionClass( __CLASS__ );
        $obj = $refl->newInstanceWithoutConstructor();
        $obj->isValid = true;
        $obj->decoded = $object;
        return $obj;
    }
36453
public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
	{
		if ($object === null) {
			$object = new ClassWithNoProperty();
		}

		if ($end === null) {
			$end = strlen($input);
		}

		while ($start < $end) {
			$tag = Binary::decodeVarint($input, $start);
			$wireType = $tag & 0x7;
			$number = $tag >> 3;
			switch ($number) {
				default:
					switch ($wireType) {
						case 0:
							Binary::decodeVarint($input, $start);
							break;
						case 1:
							$start += 8;
							break;
						case 2:
							$start += Binary::decodeVarint($input, $start);
							break;
						case 5:
							$start += 4;
							break;
						default:
							throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
					}
			}
		}

		return $object;
	}
1275612
protected function serializerFor($object): ObjectXmlSerializer
    {
        if (!annotationsOf($object)->contain('XmlSerializer')) {
            return AnnotationBasedObjectXmlSerializer::fromObject($object);
        }

        return $this->injector->getInstance(
                annotationsOf($object)
                        ->firstNamed('XmlSerializer')
                        ->getValue()
                        ->getName()
        );
    }
1034082
public static function decode($string)
    {
        if (! is_string($string)) {
            throw new JsonException('Json decode parameter must be a string');
        }

        $result = json_decode($string, true);

        if ($result === null) {
            throw new JsonException('Json decode error');
        }
        return $result;
    }