コード例 #1
0
  /**
   * @param string $url
   * @param string $username
   * @param string $password
   * @throws NuxeoClientException
   */
  public function __construct($url = 'http://localhost:8080/nuxeo', $username = '******', $password = '******') {
    try {
      $this->baseUrl = Url::factory($url);
      $this->httpClient = new Client($url, array(
        Client::REQUEST_OPTIONS => array(
          'headers' => array(
            'Content-Type' => 'application/json+nxrequest'
          )
        )
      ));
    } catch(GuzzleException $ex) {
      throw NuxeoClientException::fromPrevious($ex);
    }

    $this->httpClient->setRequestFactory(new RequestFactory());

    $self = $this;

    /**
     * @param RequestInterface $request
     */
    $this->interceptors[] = function($request) use ($self, $username, $password) {
      try {
        $request->setAuth($username, $password);
      } catch(GuzzleException $ex) {
        throw NuxeoClientException::fromPrevious($ex);
      }
    };

  }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function createHttpClient()
 {
     $guzzleClient = new Client();
     $guzzleClient->setRequestFactory($this->getRequestFactory());
     $event = new GenericEvent($guzzleClient);
     $this->getEventDispatcher()->dispatch('client.created', $event);
     $client = new HttpClient($guzzleClient);
     return $client;
 }