예제 #1
0
 /**
  * Converts a Request entity into an array that is batch-friendly.
  *
  * @param FacebookRequest $request       The request entity to convert.
  * @param string|null     $requestName   The name of the request.
  * @param string|null     $attachedFiles Names of files associated with the request.
  *
  * @return array
  */
 public function requestEntityToBatchArray(FacebookRequest $request, $requestName = null, $attachedFiles = null)
 {
     $compiledHeaders = [];
     $headers = $request->getHeaders();
     foreach ($headers as $name => $value) {
         $compiledHeaders[] = $name . ': ' . $value;
     }
     $batch = ['headers' => $compiledHeaders, 'method' => $request->getMethod(), 'relative_url' => $request->getUrl()];
     // Since file uploads are moved to the root request of a batch request,
     // the child requests will always be URL-encoded.
     $body = $request->getUrlEncodedBody()->getBody();
     if ($body) {
         $batch['body'] = $body;
     }
     if (isset($requestName)) {
         $batch['name'] = $requestName;
     }
     if (isset($attachedFiles)) {
         $batch['attached_files'] = $attachedFiles;
     }
     // @TODO Add support for "omit_response_on_success"
     // @TODO Add support for "depends_on"
     // @TODO Add support for JSONP with "callback"
     return $batch;
 }
예제 #2
0
 /**
  * Prepares the request for sending to the client handler.
  *
  * @param FacebookRequest $request
  *
  * @return array
  */
 public function prepareRequestMessage(FacebookRequest $request)
 {
     $postToVideoUrl = $request->containsVideoUploads();
     $url = $this->getBaseGraphUrl($postToVideoUrl) . $request->getUrl();
     // If we're sending files they should be sent as multipart/form-data
     if ($request->containsFileUploads()) {
         $requestBody = $request->getMultipartBody();
         $request->setHeaders(['Content-Type' => 'multipart/form-data; boundary=' . $requestBody->getBoundary()]);
     } else {
         $requestBody = $request->getUrlEncodedBody();
         $request->setHeaders(['Content-Type' => 'application/x-www-form-urlencoded']);
     }
     return [$url, $request->getMethod(), $request->getHeaders(), $requestBody->getBody()];
 }