lithium\net\Message::to()

public method

Converts the data in the record set to a different format, i.e. an array. Available options: array, url, context, or string.

Parameters

  • string $format

    Format to convert to.

  • array $options

Returns

mixed

Source

	public function to($format, array $options = []) {
		switch ($format) {
			case 'array':
				$array = [];
				$class = new ReflectionClass(get_class($this));

				foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) {
					$array[$prop->getName()] = $prop->getValue($this);
				}
				return $array;
			case 'url':
				$host = $this->host . ($this->port ? ":{$this->port}" : '');
				return "{$this->scheme}://{$host}{$this->path}";
			case 'context':
				$defaults = ['content' => $this->body(), 'ignore_errors' => true];
				return [$this->scheme => $options + $defaults];
			case 'string':
			default:
				return (string) $this;
		}
	}