lithium\net\Socket::send PHP Method

send() public method

Aggregates read and write methods into a coherent request response
public send ( Message $message = null, array $options = [] ) : object
$message Message
$options array - '`response`': a fully-namespaced string for the response object
return object a response object based on `\lithium\net\Message`
    public function send($message = null, array $options = array())
    {
        $defaults = array('response' => $this->_classes['response']);
        $options += $defaults;
        if ($this->write($message)) {
            $config = array('message' => $this->read()) + $this->_config;
            return $this->_instance($options['response'], $config);
        }
    }

Usage Example

Example #1
0
 /**
  * Send request and return response data.
  *
  * @param string $method
  * @param string $path
  * @param array $data
  * @param array $options
  * @return string
  */
 public function send($method, $path = null, $data = null, $options = array())
 {
     $defaults = array('return' => 'body');
     $options += $defaults;
     if (!$this->connect()) {
         return;
     }
     $request = $this->_request($method, $path, $data, $options);
     $response = $this->_connection->send($request, array('classes' => $this->_classes));
     if ($response) {
         $this->last = (object) compact('request', 'response');
         $this->disconnect();
         return $options['return'] == 'body' ? $response->body() : $response;
     }
 }