create() public static method

The $transport parameter can be one of the following values: * string: The short name of a transport. For instance "Http" * object: An already instantiated instance of a transport * array: An array with a "type" key which must be set to one of the two options. All other keys in the array will be set as parameters in the transport instance
public static create ( mixed $transport, Connection $connection, array $params = [] ) : AbstractTransport
$transport mixed A transport definition
$connection Elastica\Connection A connection instance
$params array Parameters for the transport class
return AbstractTransport
 public function testCanInjectParamsWhenUsingArray()
 {
     $connection = new Connection();
     $params = array('param1' => 'some value', 'param3' => 'value3');
     $transport = AbstractTransport::create(array('type' => 'Http', 'param1' => 'value1', 'param2' => 'value2'), $connection, $params);
     $this->assertSame('value1', $transport->getParam('param1'));
     $this->assertSame('value2', $transport->getParam('param2'));
     $this->assertSame('value3', $transport->getParam('param3'));
 }
示例#2
0
 /**
  * Returns an instance of the transport type.
  *
  * @throws \Elastica\Exception\InvalidException If invalid transport type
  *
  * @return \Elastica\Transport\AbstractTransport Transport object
  */
 public function getTransportObject()
 {
     $transport = $this->getTransport();
     return AbstractTransport::create($transport, $this);
 }