Inheritance: extends lithium\core\Object
コード例 #1
0
ファイル: Stream.php プロジェクト: fedeisas/lithium
 /**
  * Opens a socket and initializes the internal resource handle.
  *
  * @param array $options update the config settings
  * @return mixed Returns `false` if the socket configuration does not contain the
  *         `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a
  *         resource stream. Throws exception if there is a network error.
  */
 public function open(array $options = array())
 {
     parent::open($options);
     $config = $this->_config;
     if (!$config['scheme'] || !$config['host']) {
         return false;
     }
     $scheme = $config['scheme'] !== 'udp' ? 'tcp' : 'udp';
     $port = $config['port'] ?: 80;
     $host = "{$scheme}://{$config['host']}:{$port}";
     $flags = STREAM_CLIENT_CONNECT;
     if ($config['persistent']) {
         $flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
     }
     $errorCode = $errorMessage = null;
     $this->_resource = stream_socket_client($host, $errorCode, $errorMessage, $config['timeout'], $flags);
     if ($errorCode || $errorMessage) {
         throw new NetworkException($errorMessage);
     }
     $this->timeout($config['timeout']);
     if (!empty($config['encoding'])) {
         $this->encoding($config['encoding']);
     }
     return $this->_resource;
 }
コード例 #2
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;
     }
 }
コード例 #3
0
ファイル: Context.php プロジェクト: fedeisas/lithium
 /**
  * Opens the socket and sets its timeout value.
  *
  * @param array $options Update the config settings.
  * @return mixed Returns `false` if the socket configuration does not contain the
  *         `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a
  *         resource stream.
  */
 public function open(array $options = array())
 {
     parent::open($options);
     $config = $this->_config;
     if (!$config['scheme'] || !$config['host']) {
         return false;
     }
     $url = "{$config['scheme']}://{$config['host']}:{$config['port']}";
     $context = array($config['scheme'] => array('timeout' => $this->_timeout));
     if (is_object($config['message'])) {
         $url = $config['message']->to('url');
         $context = $config['message']->to('context', array('timeout' => $this->_timeout));
     }
     $this->_resource = fopen($url, $config['mode'], false, stream_context_create($context));
     return $this->_resource;
 }
コード例 #4
0
ファイル: Curl.php プロジェクト: romainwurtz/lithium
 /**
  * Opens a curl connection and initializes the internal resource handle.
  *
  * @param array $options update the config settings
  * @return mixed Returns `false` if the socket configuration does not contain the
  *         `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a
  *         resource stream.
  */
 public function open(array $options = array())
 {
     $this->options = array();
     parent::open($options);
     $config = $this->_config;
     if (empty($config['scheme']) || empty($config['host'])) {
         return false;
     }
     $url = "{$config['scheme']}://{$config['host']}";
     $this->_resource = curl_init($url);
     $this->set(array(CURLOPT_PORT => $config['port'], CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true));
     if (!is_resource($this->_resource)) {
         return false;
     }
     $this->_isConnected = true;
     $this->timeout($config['timeout']);
     if (isset($config['encoding'])) {
         $this->encoding($config['encoding']);
     }
     return $this->_resource;
 }
コード例 #5
0
ファイル: MockSocket.php プロジェクト: fedeisas/lithium
 public function open(array $options = array())
 {
     parent::open($options);
     return true;
 }
コード例 #6
0
ファイル: MockSocket.php プロジェクト: EHER/chegamos
 public function __construct(array $config = array())
 {
     $this->configs[] = $config;
     parent::__construct((array) $config);
 }
コード例 #7
0
ファイル: Context.php プロジェクト: EHER/monopolis
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     $defaults = array('mode' => 'r', 'message' => null);
     parent::__construct($config + $defaults);
     $this->timeout($this->_config['timeout']);
 }
コード例 #8
0
ファイル: Curl.php プロジェクト: WarToaster/HangOn
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     $defaults = array('ignoreExpect' => true);
     parent::__construct($config + $defaults);
 }
コード例 #9
0
ファイル: Push.php プロジェクト: keyteqlabs/li3_mixpanel
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     $defaults = array('scheme' => 'http');
     parent::__construct($config + $defaults);
     $this->timeout($this->_config['timeout']);
 }