lithium\data\source\Http::send PHP Метод

send() публичный Метод

Method to send to a specific resource.
public send ( array $query = null, array $options = [] ) : mixed
$query array a query object
$options array array.
Результат mixed
    public function send($query = null, array $options = array())
    {
        $query = !is_object($query) ? new Query((array) $query) : $query;
        $method = $query->method() ?: "get";
        $path = $query->path();
        $data = $query->data();
        $insert = (array) $options + $data + $query->export($this);
        if (preg_match_all('/\\{:(\\w+)\\}/', $path, $matches)) {
            $data = array_diff_key($data, array_flip($matches[1]));
        }
        return $this->connection->{$method}(String::insert($path, $insert, array('clean' => true)), $data + (array) $query->conditions() + array('limit' => $query->limit()), (array) $options);
    }

Usage Example

Пример #1
0
 public function testSendWithQueryObject()
 {
     $http = new Http($this->_testConfig);
     $query = new Query(array('model' => $this->_model, 'data' => array('title' => 'sup'), 'method' => 'post', 'path' => '/some/resource/path'));
     $result = $http->send($query);
     $expected = join("\r\n", array('POST /some/resource/path HTTP/1.1', 'Host: localhost:80', 'Connection: Close', 'User-Agent: Mozilla/5.0', 'Content-Type: application/x-www-form-urlencoded', 'Content-Length: 9', '', 'title=sup'));
     $result = (string) $http->last->request;
     $this->assertEqual($expected, $result);
 }