forked from apiaryio/language-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp.html
30 lines (29 loc) · 1.26 KB
/
php.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<section name="php" class="php">
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-php"><% headerFirst = true %><%= "<?php\n" %>
<% eos = "<<<EOT\n" %>
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "<%= @apiUrl %><%= @url %>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
<% if @method is 'POST': %>
curl_setopt($ch, CURLOPT_POST, TRUE);
<% end %>
<% if @method is 'HEAD': %>
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
<% end %>
<% if @method isnt 'GET' and @method isnt 'POST': %>
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "<%= @method %>");
<% end %>
<% if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
$fields = <%= eos %><%= @body or '' %>EOT;
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
<% else if @body and @body.length > 0: %>
curl_setopt($ch, CURLOPT_POSTFIELDS, <%= @helpers.escape @body %>);
<% end %>
<% if @headers and @helpers.isNotEmpty(@headers): %>curl_setopt($ch, CURLOPT_HTTPHEADER, array(<% for header, value of @headers: %><% if headerFirst: %><% headerFirst = false %><% else: %>, <% end %><%= @helpers.escape "#{header}: #{value}" %><% end %>));
<% end %>
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);</code></pre>
</section>