示例#1
0
 /**
  * Prepare Connection To Make Call
  *
  * - validate connection
  * - manipulate header or something in connection
  * - get connect to resource
  *
  * @param HttpSocketTransporter|iConnection $connection
  * @param iApiMethod|null                   $method
  *
  * @throws \Exception
  * @return HttpSocketTransporter|iHttpTransporter
  */
 function prepareTransporter(iConnection $connection, $method = null)
 {
     $BROWSER_OPTS = $this->browser->optsData();
     $reConnect = false;
     # check if we have something changed in connection options
     if ($BRW_ConOpts = $BROWSER_OPTS->getConnection()) {
         foreach ($BRW_ConOpts->__props()->readable as $prop) {
             if ($BRW_ConOpts->__isset($prop) && (!$connection->optsData()->__isset($prop) || $connection->optsData()->__isset($prop) && $connection->optsData()->__get($prop) !== $BRW_ConOpts->__get($prop))) {
                 $connection->optsData()->__set($prop, $BRW_ConOpts->__get($prop));
                 $reConnect = true;
             }
         }
     }
     # base url as connection server_url option
     ## made absolute server url from given baseUrl, but keep original untouched
     // http://raya-media/path/to/uri --> http://raya-media/
     $absServerUrl = new HttpUri();
     if ($BROWSER_OPTS->__isset('base_url')) {
         $absServerUrl->from($BROWSER_OPTS->getBaseUrl());
     }
     if (!$connection->optsData()->__isset('server_url') || $connection->optsData()->__isset('server_url') && $absServerUrl->toString() !== $connection->optsData()->getServerUrl()) {
         $absServerUrl->getPath() === null ?: $absServerUrl->getPath()->reset();
         ### connect to host
         $connection->optsData()->setServerUrl($absServerUrl);
         $reConnect = true;
     }
     ## disconnect old connection to reconnect with newly options if has
     if ($connection->isConnected() && $reConnect) {
         $connection->getConnect();
     }
     ## reconnect with new options
     $this->_connection = $connection;
     ## used on make expression/response
     return $connection;
 }
 /**
  * @override can give uri objects
  * Server Url That we Will Connect To
  *
  * @param iHttpUri|UriInterface|string $serverUrl
  *
  * @return $this
  */
 public function setServerUrl($serverUrl)
 {
     if ($serverUrl instanceof UriInterface) {
         $serverUrl = new HttpUri($serverUrl);
     }
     if ($serverUrl instanceof iHttpUri) {
         $serverUrl->toString();
     }
     if (is_object($serverUrl)) {
         $serverUrl = (string) $serverUrl;
     }
     if (!is_string($serverUrl)) {
         throw new \InvalidArgumentException(sprintf('Server Url must instance of iHttpUri, UriInterface or string representing url address. given: "%s".', \Poirot\Std\flatten($serverUrl)));
     }
     $this->serverUrl = $serverUrl;
     return $this;
 }