1 | <?php |
||
12 | class GitHubMarkdownService extends Object |
||
13 | { |
||
14 | /** |
||
15 | * The Guzzle client |
||
16 | * |
||
17 | * @var GuzzleHttp\Client |
||
18 | */ |
||
19 | protected $client; |
||
20 | |||
21 | /** |
||
22 | * The GitHub repository context |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $context; |
||
27 | |||
28 | /** |
||
29 | * GitHub API configuration |
||
30 | * @var string |
||
31 | */ |
||
32 | const API_BASE_URI = 'https://api.github.com'; |
||
33 | const API_REQUEST_METHOD = 'POST'; |
||
34 | const API_RENDER_ENDPOINT = '/markdown'; |
||
35 | |||
36 | /** |
||
37 | * Use GitHub's API to render markdown to HTML |
||
38 | * |
||
39 | * @param string $markdown Markdown |
||
40 | * @return string HTML |
||
41 | */ |
||
42 | public function toHtml($markdown) |
||
64 | |||
65 | /** |
||
66 | * Get the GitHub repository context |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getContext() |
||
73 | |||
74 | /** |
||
75 | * Set the GitHub repository context |
||
76 | * @param string $context |
||
77 | * @return $this |
||
78 | */ |
||
79 | public function setContext($context) |
||
84 | |||
85 | /** |
||
86 | * Get an instance of a GuzzleHttp client |
||
87 | * @return GuzzleHttp\Client |
||
88 | */ |
||
89 | public function getClient() |
||
97 | |||
98 | /** |
||
99 | * Get the GitHub base URI |
||
100 | * @return string |
||
101 | */ |
||
102 | public function getBaseUri() |
||
106 | |||
107 | /** |
||
108 | * Get the HTTP request method to use for the request |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getRequestMethod() |
||
115 | |||
116 | /** |
||
117 | * Get the markdown parse endpoint for GitHub's API |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getEndpoint() |
||
131 | |||
132 | /** |
||
133 | * Get any custom headers to use for the request |
||
134 | * @return array |
||
135 | */ |
||
136 | public function getHeaders() |
||
143 | |||
144 | /** |
||
145 | * Get the payload for for the GitHub Markdown API endpoint, either in "GFM" mode if there is a repository |
||
146 | * context, or in raw mode if not. |
||
147 | * |
||
148 | * @see https://developer.github.com/v3/markdown/ |
||
149 | * @param string $markdown |
||
150 | * @return string JSON or markdown |
||
151 | */ |
||
152 | public function getPayload($markdown) |
||
166 | } |
||
167 |