@@ -3,9 +3,9 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | use FlexyProject\GitHub\AbstractApi; |
| 5 | 5 | use FlexyProject\GitHub\Receiver\{ |
| 6 | - Activity\AbstractActivity, Enterprise\AbstractEnterprise, Gists\AbstractGists, GitData\AbstractGitData, |
|
| 7 | - Issues\AbstractIssues, Miscellaneous\AbstractMiscellaneous, Organizations\AbstractOrganizations, |
|
| 8 | - PullRequests\AbstractPullRequests, Repositories\AbstractRepositories |
|
| 6 | + Activity\AbstractActivity, Enterprise\AbstractEnterprise, Gists\AbstractGists, GitData\AbstractGitData, |
|
| 7 | + Issues\AbstractIssues, Miscellaneous\AbstractMiscellaneous, Organizations\AbstractOrganizations, |
|
| 8 | + PullRequests\AbstractPullRequests, Repositories\AbstractRepositories |
|
| 9 | 9 | }; |
| 10 | 10 | |
| 11 | 11 | /** |
@@ -15,30 +15,30 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | trait Api |
| 17 | 17 | { |
| 18 | - /** @var mixed */ |
|
| 19 | - protected $api; |
|
| 18 | + /** @var mixed */ |
|
| 19 | + protected $api; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Get api |
|
| 23 | - * |
|
| 24 | - * @return AbstractApi|AbstractActivity|AbstractEnterprise|AbstractGists|AbstractGitData|AbstractIssues|AbstractMiscellaneous|AbstractOrganizations|AbstractPullRequests|AbstractRepositories |
|
| 25 | - */ |
|
| 26 | - public function getApi() |
|
| 27 | - { |
|
| 28 | - return $this->api; |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * Get api |
|
| 23 | + * |
|
| 24 | + * @return AbstractApi|AbstractActivity|AbstractEnterprise|AbstractGists|AbstractGitData|AbstractIssues|AbstractMiscellaneous|AbstractOrganizations|AbstractPullRequests|AbstractRepositories |
|
| 25 | + */ |
|
| 26 | + public function getApi() |
|
| 27 | + { |
|
| 28 | + return $this->api; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Set api |
|
| 33 | - * |
|
| 34 | - * @param AbstractApi|AbstractActivity|AbstractEnterprise|AbstractGists|AbstractGitData|AbstractIssues|AbstractMiscellaneous|AbstractOrganizations|AbstractPullRequests|AbstractRepositories $api |
|
| 35 | - * |
|
| 36 | - * @return Api |
|
| 37 | - */ |
|
| 38 | - public function setApi($api): self |
|
| 39 | - { |
|
| 40 | - $this->api = $api; |
|
| 31 | + /** |
|
| 32 | + * Set api |
|
| 33 | + * |
|
| 34 | + * @param AbstractApi|AbstractActivity|AbstractEnterprise|AbstractGists|AbstractGitData|AbstractIssues|AbstractMiscellaneous|AbstractOrganizations|AbstractPullRequests|AbstractRepositories $api |
|
| 35 | + * |
|
| 36 | + * @return Api |
|
| 37 | + */ |
|
| 38 | + public function setApi($api): self |
|
| 39 | + { |
|
| 40 | + $this->api = $api; |
|
| 41 | 41 | |
| 42 | - return $this; |
|
| 43 | - } |
|
| 42 | + return $this; |
|
| 43 | + } |
|
| 44 | 44 | } |
| 45 | 45 | \ No newline at end of file |
@@ -13,321 +13,321 @@ |
||
| 13 | 13 | class Repositories extends AbstractReceiver |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** Available sub-Receiver */ |
|
| 17 | - const COLLABORATORS = 'Collaborators'; |
|
| 18 | - const COMMENTS = 'Comments'; |
|
| 19 | - const COMMITS = 'Commits'; |
|
| 20 | - const CONTENTS = 'Contents'; |
|
| 21 | - const DEPLOY_KEYS = 'DeployKeys'; |
|
| 22 | - const DEPLOYMENTS = 'Deployments'; |
|
| 23 | - const FORKS = 'Forks'; |
|
| 24 | - const HOOKS = 'Hooks'; |
|
| 25 | - const MERGING = 'Merging'; |
|
| 26 | - const PAGES = 'Pages'; |
|
| 27 | - const RELEASES = 'Releases'; |
|
| 28 | - const STATISTICS = 'Statistics'; |
|
| 29 | - const STATUSES = 'Statuses'; |
|
| 16 | + /** Available sub-Receiver */ |
|
| 17 | + const COLLABORATORS = 'Collaborators'; |
|
| 18 | + const COMMENTS = 'Comments'; |
|
| 19 | + const COMMITS = 'Commits'; |
|
| 20 | + const CONTENTS = 'Contents'; |
|
| 21 | + const DEPLOY_KEYS = 'DeployKeys'; |
|
| 22 | + const DEPLOYMENTS = 'Deployments'; |
|
| 23 | + const FORKS = 'Forks'; |
|
| 24 | + const HOOKS = 'Hooks'; |
|
| 25 | + const MERGING = 'Merging'; |
|
| 26 | + const PAGES = 'Pages'; |
|
| 27 | + const RELEASES = 'Releases'; |
|
| 28 | + const STATISTICS = 'Statistics'; |
|
| 29 | + const STATUSES = 'Statuses'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * List repositories for the authenticated user. |
|
| 33 | - * |
|
| 34 | - * @link https://developer.github.com/v3/repos/#list-your-repositories |
|
| 35 | - * |
|
| 36 | - * @param string $type |
|
| 37 | - * @param string $sort |
|
| 38 | - * @param string $direction |
|
| 39 | - * |
|
| 40 | - * @return array |
|
| 41 | - */ |
|
| 42 | - public function listYourRepositories(string $type = AbstractApi::TYPE_ALL, |
|
| 43 | - string $sort = AbstractApi::SORT_FULL_NAME, |
|
| 44 | - string $direction = AbstractApi::DIRECTION_DESC): array |
|
| 45 | - { |
|
| 46 | - return $this->getApi()->request($this->getApi()->sprintf('/user/repos?:args', |
|
| 47 | - http_build_query(['type' => $type, 'sort' => $sort, 'direction' => $direction]))); |
|
| 48 | - } |
|
| 31 | + /** |
|
| 32 | + * List repositories for the authenticated user. |
|
| 33 | + * |
|
| 34 | + * @link https://developer.github.com/v3/repos/#list-your-repositories |
|
| 35 | + * |
|
| 36 | + * @param string $type |
|
| 37 | + * @param string $sort |
|
| 38 | + * @param string $direction |
|
| 39 | + * |
|
| 40 | + * @return array |
|
| 41 | + */ |
|
| 42 | + public function listYourRepositories(string $type = AbstractApi::TYPE_ALL, |
|
| 43 | + string $sort = AbstractApi::SORT_FULL_NAME, |
|
| 44 | + string $direction = AbstractApi::DIRECTION_DESC): array |
|
| 45 | + { |
|
| 46 | + return $this->getApi()->request($this->getApi()->sprintf('/user/repos?:args', |
|
| 47 | + http_build_query(['type' => $type, 'sort' => $sort, 'direction' => $direction]))); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * List public repositories for the specified user. |
|
| 52 | - * |
|
| 53 | - * @link https://developer.github.com/v3/repos/#list-user-repositories |
|
| 54 | - * |
|
| 55 | - * @param string $username |
|
| 56 | - * @param string $type |
|
| 57 | - * @param string $sort |
|
| 58 | - * @param string $direction |
|
| 59 | - * |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public function listUserRepositories(string $username, string $type = AbstractApi::TYPE_OWNER, |
|
| 63 | - string $sort = AbstractApi::SORT_FULL_NAME, |
|
| 64 | - string $direction = AbstractApi::DIRECTION_DESC): array |
|
| 65 | - { |
|
| 66 | - return $this->getApi()->request($this->getApi()->sprintf('/users/:username/repos?:args', $username, |
|
| 67 | - http_build_query(['type' => $type, 'sort' => $sort, 'direction' => $direction]))); |
|
| 68 | - } |
|
| 50 | + /** |
|
| 51 | + * List public repositories for the specified user. |
|
| 52 | + * |
|
| 53 | + * @link https://developer.github.com/v3/repos/#list-user-repositories |
|
| 54 | + * |
|
| 55 | + * @param string $username |
|
| 56 | + * @param string $type |
|
| 57 | + * @param string $sort |
|
| 58 | + * @param string $direction |
|
| 59 | + * |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public function listUserRepositories(string $username, string $type = AbstractApi::TYPE_OWNER, |
|
| 63 | + string $sort = AbstractApi::SORT_FULL_NAME, |
|
| 64 | + string $direction = AbstractApi::DIRECTION_DESC): array |
|
| 65 | + { |
|
| 66 | + return $this->getApi()->request($this->getApi()->sprintf('/users/:username/repos?:args', $username, |
|
| 67 | + http_build_query(['type' => $type, 'sort' => $sort, 'direction' => $direction]))); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * List repositories for the specified org. |
|
| 72 | - * |
|
| 73 | - * @link https://developer.github.com/v3/repos/#list-organization-repositories |
|
| 74 | - * |
|
| 75 | - * @param string $organization |
|
| 76 | - * @param string $type |
|
| 77 | - * |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 80 | - public function listOrganizationRepositories(string $organization, string $type = AbstractApi::TYPE_ALL): array |
|
| 81 | - { |
|
| 82 | - return $this->getApi()->request($this->getApi()->sprintf('/orgs/:org/repos?:args', $organization, |
|
| 83 | - http_build_query(['type' => $type]))); |
|
| 84 | - } |
|
| 70 | + /** |
|
| 71 | + * List repositories for the specified org. |
|
| 72 | + * |
|
| 73 | + * @link https://developer.github.com/v3/repos/#list-organization-repositories |
|
| 74 | + * |
|
| 75 | + * @param string $organization |
|
| 76 | + * @param string $type |
|
| 77 | + * |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | + public function listOrganizationRepositories(string $organization, string $type = AbstractApi::TYPE_ALL): array |
|
| 81 | + { |
|
| 82 | + return $this->getApi()->request($this->getApi()->sprintf('/orgs/:org/repos?:args', $organization, |
|
| 83 | + http_build_query(['type' => $type]))); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * List all public repositories |
|
| 88 | - * |
|
| 89 | - * @link https://developer.github.com/v3/repos/#list-all-public-repositories |
|
| 90 | - * |
|
| 91 | - * @param string $since |
|
| 92 | - * |
|
| 93 | - * @return array |
|
| 94 | - */ |
|
| 95 | - public function listPublicRepositories(string $since = '1970-01-01'): array |
|
| 96 | - { |
|
| 97 | - return $this->getApi()->request($this->getApi() |
|
| 98 | - ->sprintf('/repositories?:arg', http_build_query(['since', $since]))); |
|
| 99 | - } |
|
| 86 | + /** |
|
| 87 | + * List all public repositories |
|
| 88 | + * |
|
| 89 | + * @link https://developer.github.com/v3/repos/#list-all-public-repositories |
|
| 90 | + * |
|
| 91 | + * @param string $since |
|
| 92 | + * |
|
| 93 | + * @return array |
|
| 94 | + */ |
|
| 95 | + public function listPublicRepositories(string $since = '1970-01-01'): array |
|
| 96 | + { |
|
| 97 | + return $this->getApi()->request($this->getApi() |
|
| 98 | + ->sprintf('/repositories?:arg', http_build_query(['since', $since]))); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Create a new repository for the authenticated user. |
|
| 103 | - * |
|
| 104 | - * @link https://developer.github.com/v3/repos/#create |
|
| 105 | - * |
|
| 106 | - * @param string $name |
|
| 107 | - * @param string $description |
|
| 108 | - * @param string $homepage |
|
| 109 | - * @param bool $private |
|
| 110 | - * @param bool $hasIssues |
|
| 111 | - * @param bool $hasWiki |
|
| 112 | - * @param bool $hasDownloads |
|
| 113 | - * @param int $teamId |
|
| 114 | - * @param bool $autoInit |
|
| 115 | - * @param string $gitignoreTemplate |
|
| 116 | - * @param string $licenseTemplate |
|
| 117 | - * |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - public function createRepository(string $name, string $description = '', string $homepage = '', |
|
| 121 | - bool $private = false, bool $hasIssues = true, bool $hasWiki = true, |
|
| 122 | - bool $hasDownloads = true, int $teamId = 0, bool $autoInit = false, |
|
| 123 | - string $gitignoreTemplate = '', string $licenseTemplate = ''): array |
|
| 124 | - { |
|
| 125 | - return $this->getApi()->request(sprintf('/user/repos'), Request::METHOD_POST, [ |
|
| 126 | - 'name' => $name, |
|
| 127 | - 'description' => $description, |
|
| 128 | - 'homepage' => $homepage, |
|
| 129 | - 'private' => $private, |
|
| 130 | - 'has_issues' => $hasIssues, |
|
| 131 | - 'has_wiki' => $hasWiki, |
|
| 132 | - 'has_downloads' => $hasDownloads, |
|
| 133 | - 'team_id' => $teamId, |
|
| 134 | - 'auto_init' => $autoInit, |
|
| 135 | - 'gitignore_template' => $gitignoreTemplate, |
|
| 136 | - 'license_template' => $licenseTemplate |
|
| 137 | - ]); |
|
| 138 | - } |
|
| 101 | + /** |
|
| 102 | + * Create a new repository for the authenticated user. |
|
| 103 | + * |
|
| 104 | + * @link https://developer.github.com/v3/repos/#create |
|
| 105 | + * |
|
| 106 | + * @param string $name |
|
| 107 | + * @param string $description |
|
| 108 | + * @param string $homepage |
|
| 109 | + * @param bool $private |
|
| 110 | + * @param bool $hasIssues |
|
| 111 | + * @param bool $hasWiki |
|
| 112 | + * @param bool $hasDownloads |
|
| 113 | + * @param int $teamId |
|
| 114 | + * @param bool $autoInit |
|
| 115 | + * @param string $gitignoreTemplate |
|
| 116 | + * @param string $licenseTemplate |
|
| 117 | + * |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + public function createRepository(string $name, string $description = '', string $homepage = '', |
|
| 121 | + bool $private = false, bool $hasIssues = true, bool $hasWiki = true, |
|
| 122 | + bool $hasDownloads = true, int $teamId = 0, bool $autoInit = false, |
|
| 123 | + string $gitignoreTemplate = '', string $licenseTemplate = ''): array |
|
| 124 | + { |
|
| 125 | + return $this->getApi()->request(sprintf('/user/repos'), Request::METHOD_POST, [ |
|
| 126 | + 'name' => $name, |
|
| 127 | + 'description' => $description, |
|
| 128 | + 'homepage' => $homepage, |
|
| 129 | + 'private' => $private, |
|
| 130 | + 'has_issues' => $hasIssues, |
|
| 131 | + 'has_wiki' => $hasWiki, |
|
| 132 | + 'has_downloads' => $hasDownloads, |
|
| 133 | + 'team_id' => $teamId, |
|
| 134 | + 'auto_init' => $autoInit, |
|
| 135 | + 'gitignore_template' => $gitignoreTemplate, |
|
| 136 | + 'license_template' => $licenseTemplate |
|
| 137 | + ]); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Create a new repository in this organization. The authenticated user must be a member of the specified |
|
| 142 | - * organization. |
|
| 143 | - * |
|
| 144 | - * @link https://developer.github.com/v3/repos/#create |
|
| 145 | - * |
|
| 146 | - * @param string $organization |
|
| 147 | - * @param string $name |
|
| 148 | - * @param string $description |
|
| 149 | - * @param string $homepage |
|
| 150 | - * @param bool $private |
|
| 151 | - * @param bool $hasIssues |
|
| 152 | - * @param bool $hasWiki |
|
| 153 | - * @param bool $hasDownloads |
|
| 154 | - * @param int $teamId |
|
| 155 | - * @param bool $autoInit |
|
| 156 | - * @param string $gitignoreTemplate |
|
| 157 | - * @param string $licenseTemplate |
|
| 158 | - * |
|
| 159 | - * @return array |
|
| 160 | - */ |
|
| 161 | - public function createOrganizationRepository(string $organization, string $name, string $description = '', |
|
| 162 | - string $homepage = '', bool $private = false, bool $hasIssues = true, |
|
| 163 | - bool $hasWiki = true, bool $hasDownloads = true, int $teamId = 0, |
|
| 164 | - bool $autoInit = false, string $gitignoreTemplate = '', |
|
| 165 | - string $licenseTemplate = ''): array |
|
| 166 | - { |
|
| 167 | - return $this->getApi()->request($this->getApi()->sprintf('/orgs/:org/repos', $organization), |
|
| 168 | - Request::METHOD_POST, [ |
|
| 169 | - 'name' => $name, |
|
| 170 | - 'description' => $description, |
|
| 171 | - 'homepage' => $homepage, |
|
| 172 | - 'private' => $private, |
|
| 173 | - 'has_issues' => $hasIssues, |
|
| 174 | - 'has_wiki' => $hasWiki, |
|
| 175 | - 'has_downloads' => $hasDownloads, |
|
| 176 | - 'team_id' => $teamId, |
|
| 177 | - 'auto_init' => $autoInit, |
|
| 178 | - 'gitignore_template' => $gitignoreTemplate, |
|
| 179 | - 'license_template' => $licenseTemplate |
|
| 180 | - ]); |
|
| 181 | - } |
|
| 140 | + /** |
|
| 141 | + * Create a new repository in this organization. The authenticated user must be a member of the specified |
|
| 142 | + * organization. |
|
| 143 | + * |
|
| 144 | + * @link https://developer.github.com/v3/repos/#create |
|
| 145 | + * |
|
| 146 | + * @param string $organization |
|
| 147 | + * @param string $name |
|
| 148 | + * @param string $description |
|
| 149 | + * @param string $homepage |
|
| 150 | + * @param bool $private |
|
| 151 | + * @param bool $hasIssues |
|
| 152 | + * @param bool $hasWiki |
|
| 153 | + * @param bool $hasDownloads |
|
| 154 | + * @param int $teamId |
|
| 155 | + * @param bool $autoInit |
|
| 156 | + * @param string $gitignoreTemplate |
|
| 157 | + * @param string $licenseTemplate |
|
| 158 | + * |
|
| 159 | + * @return array |
|
| 160 | + */ |
|
| 161 | + public function createOrganizationRepository(string $organization, string $name, string $description = '', |
|
| 162 | + string $homepage = '', bool $private = false, bool $hasIssues = true, |
|
| 163 | + bool $hasWiki = true, bool $hasDownloads = true, int $teamId = 0, |
|
| 164 | + bool $autoInit = false, string $gitignoreTemplate = '', |
|
| 165 | + string $licenseTemplate = ''): array |
|
| 166 | + { |
|
| 167 | + return $this->getApi()->request($this->getApi()->sprintf('/orgs/:org/repos', $organization), |
|
| 168 | + Request::METHOD_POST, [ |
|
| 169 | + 'name' => $name, |
|
| 170 | + 'description' => $description, |
|
| 171 | + 'homepage' => $homepage, |
|
| 172 | + 'private' => $private, |
|
| 173 | + 'has_issues' => $hasIssues, |
|
| 174 | + 'has_wiki' => $hasWiki, |
|
| 175 | + 'has_downloads' => $hasDownloads, |
|
| 176 | + 'team_id' => $teamId, |
|
| 177 | + 'auto_init' => $autoInit, |
|
| 178 | + 'gitignore_template' => $gitignoreTemplate, |
|
| 179 | + 'license_template' => $licenseTemplate |
|
| 180 | + ]); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Get |
|
| 185 | - * |
|
| 186 | - * @link https://developer.github.com/v3/repos/#get |
|
| 187 | - * @return array |
|
| 188 | - */ |
|
| 189 | - public function get(): array |
|
| 190 | - { |
|
| 191 | - return $this->getApi()->request($this->getApi() |
|
| 192 | - ->sprintf('/repos/:owner/:repo', $this->getOwner(), $this->getRepo())); |
|
| 193 | - } |
|
| 183 | + /** |
|
| 184 | + * Get |
|
| 185 | + * |
|
| 186 | + * @link https://developer.github.com/v3/repos/#get |
|
| 187 | + * @return array |
|
| 188 | + */ |
|
| 189 | + public function get(): array |
|
| 190 | + { |
|
| 191 | + return $this->getApi()->request($this->getApi() |
|
| 192 | + ->sprintf('/repos/:owner/:repo', $this->getOwner(), $this->getRepo())); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Edit |
|
| 197 | - * |
|
| 198 | - * @link https://developer.github.com/v3/repos/#edit |
|
| 199 | - * |
|
| 200 | - * @param string $name |
|
| 201 | - * @param string $description |
|
| 202 | - * @param string $homepage |
|
| 203 | - * @param bool $private |
|
| 204 | - * @param bool $hasIssues |
|
| 205 | - * @param bool $hasWiki |
|
| 206 | - * @param bool $hasDownloads |
|
| 207 | - * @param string $defaultBranch |
|
| 208 | - * |
|
| 209 | - * @return array |
|
| 210 | - */ |
|
| 211 | - public function edit(string $name, string $description = '', string $homepage = '', bool $private = false, |
|
| 212 | - bool $hasIssues = true, bool $hasWiki = true, bool $hasDownloads = true, |
|
| 213 | - string $defaultBranch = ''): array |
|
| 214 | - { |
|
| 215 | - return $this->getApi()->request($this->getApi() |
|
| 216 | - ->sprintf('/repos/:owner/:repo', $this->getOwner(), $this->getRepo()), |
|
| 217 | - Request::METHOD_PATCH, [ |
|
| 218 | - 'name' => $name, |
|
| 219 | - 'description' => $description, |
|
| 220 | - 'homepage' => $homepage, |
|
| 221 | - 'private' => $private, |
|
| 222 | - 'has_issues' => $hasIssues, |
|
| 223 | - 'has_wiki' => $hasWiki, |
|
| 224 | - 'has_downloads' => $hasDownloads, |
|
| 225 | - 'default_branch' => $defaultBranch |
|
| 226 | - ]); |
|
| 227 | - } |
|
| 195 | + /** |
|
| 196 | + * Edit |
|
| 197 | + * |
|
| 198 | + * @link https://developer.github.com/v3/repos/#edit |
|
| 199 | + * |
|
| 200 | + * @param string $name |
|
| 201 | + * @param string $description |
|
| 202 | + * @param string $homepage |
|
| 203 | + * @param bool $private |
|
| 204 | + * @param bool $hasIssues |
|
| 205 | + * @param bool $hasWiki |
|
| 206 | + * @param bool $hasDownloads |
|
| 207 | + * @param string $defaultBranch |
|
| 208 | + * |
|
| 209 | + * @return array |
|
| 210 | + */ |
|
| 211 | + public function edit(string $name, string $description = '', string $homepage = '', bool $private = false, |
|
| 212 | + bool $hasIssues = true, bool $hasWiki = true, bool $hasDownloads = true, |
|
| 213 | + string $defaultBranch = ''): array |
|
| 214 | + { |
|
| 215 | + return $this->getApi()->request($this->getApi() |
|
| 216 | + ->sprintf('/repos/:owner/:repo', $this->getOwner(), $this->getRepo()), |
|
| 217 | + Request::METHOD_PATCH, [ |
|
| 218 | + 'name' => $name, |
|
| 219 | + 'description' => $description, |
|
| 220 | + 'homepage' => $homepage, |
|
| 221 | + 'private' => $private, |
|
| 222 | + 'has_issues' => $hasIssues, |
|
| 223 | + 'has_wiki' => $hasWiki, |
|
| 224 | + 'has_downloads' => $hasDownloads, |
|
| 225 | + 'default_branch' => $defaultBranch |
|
| 226 | + ]); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * List contributors |
|
| 231 | - * |
|
| 232 | - * @link https://developer.github.com/v3/repos/#list-contributors |
|
| 233 | - * |
|
| 234 | - * @param string $anon |
|
| 235 | - * |
|
| 236 | - * @return array |
|
| 237 | - */ |
|
| 238 | - public function listContributors(string $anon = '0'): array |
|
| 239 | - { |
|
| 240 | - return $this->getApi()->request($this->getApi() |
|
| 241 | - ->sprintf('/repos/:owner/:repo/contributors?:args', $this->getOwner(), |
|
| 242 | - $this->getRepo(), http_build_query(['anon' => $anon]))); |
|
| 243 | - } |
|
| 229 | + /** |
|
| 230 | + * List contributors |
|
| 231 | + * |
|
| 232 | + * @link https://developer.github.com/v3/repos/#list-contributors |
|
| 233 | + * |
|
| 234 | + * @param string $anon |
|
| 235 | + * |
|
| 236 | + * @return array |
|
| 237 | + */ |
|
| 238 | + public function listContributors(string $anon = '0'): array |
|
| 239 | + { |
|
| 240 | + return $this->getApi()->request($this->getApi() |
|
| 241 | + ->sprintf('/repos/:owner/:repo/contributors?:args', $this->getOwner(), |
|
| 242 | + $this->getRepo(), http_build_query(['anon' => $anon]))); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * List languages |
|
| 247 | - * |
|
| 248 | - * @link https://developer.github.com/v3/repos/#list-languages |
|
| 249 | - * @return array |
|
| 250 | - */ |
|
| 251 | - public function listLanguages(): array |
|
| 252 | - { |
|
| 253 | - return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/languages', $this->getOwner(), |
|
| 254 | - $this->getRepo())); |
|
| 255 | - } |
|
| 245 | + /** |
|
| 246 | + * List languages |
|
| 247 | + * |
|
| 248 | + * @link https://developer.github.com/v3/repos/#list-languages |
|
| 249 | + * @return array |
|
| 250 | + */ |
|
| 251 | + public function listLanguages(): array |
|
| 252 | + { |
|
| 253 | + return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/languages', $this->getOwner(), |
|
| 254 | + $this->getRepo())); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * List Teams |
|
| 259 | - * |
|
| 260 | - * @link https://developer.github.com/v3/repos/#list-teams |
|
| 261 | - * @return array |
|
| 262 | - */ |
|
| 263 | - public function listTeams(): array |
|
| 264 | - { |
|
| 265 | - return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/teams', $this->getOwner(), |
|
| 266 | - $this->getRepo())); |
|
| 267 | - } |
|
| 257 | + /** |
|
| 258 | + * List Teams |
|
| 259 | + * |
|
| 260 | + * @link https://developer.github.com/v3/repos/#list-teams |
|
| 261 | + * @return array |
|
| 262 | + */ |
|
| 263 | + public function listTeams(): array |
|
| 264 | + { |
|
| 265 | + return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/teams', $this->getOwner(), |
|
| 266 | + $this->getRepo())); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * List Tags |
|
| 271 | - * |
|
| 272 | - * @link https://developer.github.com/v3/repos/#list-tags |
|
| 273 | - * @return array |
|
| 274 | - */ |
|
| 275 | - public function listTags(): array |
|
| 276 | - { |
|
| 277 | - return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/tags', $this->getOwner(), |
|
| 278 | - $this->getRepo())); |
|
| 279 | - } |
|
| 269 | + /** |
|
| 270 | + * List Tags |
|
| 271 | + * |
|
| 272 | + * @link https://developer.github.com/v3/repos/#list-tags |
|
| 273 | + * @return array |
|
| 274 | + */ |
|
| 275 | + public function listTags(): array |
|
| 276 | + { |
|
| 277 | + return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/tags', $this->getOwner(), |
|
| 278 | + $this->getRepo())); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * List Branches |
|
| 283 | - * |
|
| 284 | - * @link https://developer.github.com/v3/repos/#list-branches |
|
| 285 | - * @return array |
|
| 286 | - */ |
|
| 287 | - public function listBranches(): array |
|
| 288 | - { |
|
| 289 | - return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/branches', $this->getOwner(), |
|
| 290 | - $this->getRepo())); |
|
| 291 | - } |
|
| 281 | + /** |
|
| 282 | + * List Branches |
|
| 283 | + * |
|
| 284 | + * @link https://developer.github.com/v3/repos/#list-branches |
|
| 285 | + * @return array |
|
| 286 | + */ |
|
| 287 | + public function listBranches(): array |
|
| 288 | + { |
|
| 289 | + return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/branches', $this->getOwner(), |
|
| 290 | + $this->getRepo())); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Get Branch |
|
| 295 | - * |
|
| 296 | - * @link https://developer.github.com/v3/repos/#get-branch |
|
| 297 | - * |
|
| 298 | - * @param string $branch |
|
| 299 | - * |
|
| 300 | - * @return array |
|
| 301 | - */ |
|
| 302 | - public function getBranch(string $branch): array |
|
| 303 | - { |
|
| 304 | - return $this->getApi()->request($this->getApi() |
|
| 305 | - ->sprintf('/repos/:owner/:repo/branches/:branch', $this->getOwner(), |
|
| 306 | - $this->getRepo(), $branch)); |
|
| 307 | - } |
|
| 293 | + /** |
|
| 294 | + * Get Branch |
|
| 295 | + * |
|
| 296 | + * @link https://developer.github.com/v3/repos/#get-branch |
|
| 297 | + * |
|
| 298 | + * @param string $branch |
|
| 299 | + * |
|
| 300 | + * @return array |
|
| 301 | + */ |
|
| 302 | + public function getBranch(string $branch): array |
|
| 303 | + { |
|
| 304 | + return $this->getApi()->request($this->getApi() |
|
| 305 | + ->sprintf('/repos/:owner/:repo/branches/:branch', $this->getOwner(), |
|
| 306 | + $this->getRepo(), $branch)); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Delete a Repository |
|
| 311 | - * |
|
| 312 | - * @link https://developer.github.com/v3/repos/#delete-a-repository |
|
| 313 | - * @return array |
|
| 314 | - */ |
|
| 315 | - public function deleteRepository(): array |
|
| 316 | - { |
|
| 317 | - return $this->getApi()->request($this->getApi() |
|
| 318 | - ->sprintf('/repos/:owner/:repo', $this->getOwner(), $this->getRepo()), |
|
| 319 | - Request::METHOD_DELETE); |
|
| 320 | - } |
|
| 309 | + /** |
|
| 310 | + * Delete a Repository |
|
| 311 | + * |
|
| 312 | + * @link https://developer.github.com/v3/repos/#delete-a-repository |
|
| 313 | + * @return array |
|
| 314 | + */ |
|
| 315 | + public function deleteRepository(): array |
|
| 316 | + { |
|
| 317 | + return $this->getApi()->request($this->getApi() |
|
| 318 | + ->sprintf('/repos/:owner/:repo', $this->getOwner(), $this->getRepo()), |
|
| 319 | + Request::METHOD_DELETE); |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * Get the contents of a repository's license |
|
| 324 | - * |
|
| 325 | - * @link https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license |
|
| 326 | - * @return array |
|
| 327 | - */ |
|
| 328 | - public function getRepositoryLicenseContent(): array |
|
| 329 | - { |
|
| 330 | - return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/license', $this->getOwner(), |
|
| 331 | - $this->getRepo())); |
|
| 332 | - } |
|
| 322 | + /** |
|
| 323 | + * Get the contents of a repository's license |
|
| 324 | + * |
|
| 325 | + * @link https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license |
|
| 326 | + * @return array |
|
| 327 | + */ |
|
| 328 | + public function getRepositoryLicenseContent(): array |
|
| 329 | + { |
|
| 330 | + return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/license', $this->getOwner(), |
|
| 331 | + $this->getRepo())); |
|
| 332 | + } |
|
| 333 | 333 | } |
| 334 | 334 | \ No newline at end of file |
@@ -12,44 +12,44 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | abstract class AbstractIssues |
| 14 | 14 | { |
| 15 | - /** Api trait */ |
|
| 16 | - use Api; |
|
| 15 | + /** Api trait */ |
|
| 16 | + use Api; |
|
| 17 | 17 | |
| 18 | - /** Properties */ |
|
| 19 | - protected $issues; |
|
| 18 | + /** Properties */ |
|
| 19 | + protected $issues; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Constructor |
|
| 23 | - * |
|
| 24 | - * @param Issues $issues |
|
| 25 | - */ |
|
| 26 | - public function __construct(Issues $issues) |
|
| 27 | - { |
|
| 28 | - $this->setIssues($issues); |
|
| 29 | - $this->setApi($issues->getApi()); |
|
| 30 | - } |
|
| 21 | + /** |
|
| 22 | + * Constructor |
|
| 23 | + * |
|
| 24 | + * @param Issues $issues |
|
| 25 | + */ |
|
| 26 | + public function __construct(Issues $issues) |
|
| 27 | + { |
|
| 28 | + $this->setIssues($issues); |
|
| 29 | + $this->setApi($issues->getApi()); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Get issues |
|
| 34 | - * |
|
| 35 | - * @return Issues |
|
| 36 | - */ |
|
| 37 | - public function getIssues(): Issues |
|
| 38 | - { |
|
| 39 | - return $this->issues; |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * Get issues |
|
| 34 | + * |
|
| 35 | + * @return Issues |
|
| 36 | + */ |
|
| 37 | + public function getIssues(): Issues |
|
| 38 | + { |
|
| 39 | + return $this->issues; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Set issues |
|
| 44 | - * |
|
| 45 | - * @param Issues $issues |
|
| 46 | - * |
|
| 47 | - * @return AbstractIssues |
|
| 48 | - */ |
|
| 49 | - public function setIssues(Issues $issues): AbstractIssues |
|
| 50 | - { |
|
| 51 | - $this->issues = $issues; |
|
| 42 | + /** |
|
| 43 | + * Set issues |
|
| 44 | + * |
|
| 45 | + * @param Issues $issues |
|
| 46 | + * |
|
| 47 | + * @return AbstractIssues |
|
| 48 | + */ |
|
| 49 | + public function setIssues(Issues $issues): AbstractIssues |
|
| 50 | + { |
|
| 51 | + $this->issues = $issues; |
|
| 52 | 52 | |
| 53 | - return $this; |
|
| 54 | - } |
|
| 53 | + return $this; |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |
@@ -12,44 +12,44 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | abstract class AbstractActivity |
| 14 | 14 | { |
| 15 | - /** Api trait */ |
|
| 16 | - use Api; |
|
| 15 | + /** Api trait */ |
|
| 16 | + use Api; |
|
| 17 | 17 | |
| 18 | - /** Properties */ |
|
| 19 | - protected $activity; |
|
| 18 | + /** Properties */ |
|
| 19 | + protected $activity; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Constructor |
|
| 23 | - * |
|
| 24 | - * @param Activity $activity |
|
| 25 | - */ |
|
| 26 | - public function __construct(Activity $activity) |
|
| 27 | - { |
|
| 28 | - $this->setActivity($activity); |
|
| 29 | - $this->setApi($activity->getApi()); |
|
| 30 | - } |
|
| 21 | + /** |
|
| 22 | + * Constructor |
|
| 23 | + * |
|
| 24 | + * @param Activity $activity |
|
| 25 | + */ |
|
| 26 | + public function __construct(Activity $activity) |
|
| 27 | + { |
|
| 28 | + $this->setActivity($activity); |
|
| 29 | + $this->setApi($activity->getApi()); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Get activity |
|
| 34 | - * |
|
| 35 | - * @return Activity |
|
| 36 | - */ |
|
| 37 | - public function getActivity(): Activity |
|
| 38 | - { |
|
| 39 | - return $this->activity; |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * Get activity |
|
| 34 | + * |
|
| 35 | + * @return Activity |
|
| 36 | + */ |
|
| 37 | + public function getActivity(): Activity |
|
| 38 | + { |
|
| 39 | + return $this->activity; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Set activity |
|
| 44 | - * |
|
| 45 | - * @param Activity $activity |
|
| 46 | - * |
|
| 47 | - * @return AbstractActivity |
|
| 48 | - */ |
|
| 49 | - public function setActivity(Activity $activity): AbstractActivity |
|
| 50 | - { |
|
| 51 | - $this->activity = $activity; |
|
| 42 | + /** |
|
| 43 | + * Set activity |
|
| 44 | + * |
|
| 45 | + * @param Activity $activity |
|
| 46 | + * |
|
| 47 | + * @return AbstractActivity |
|
| 48 | + */ |
|
| 49 | + public function setActivity(Activity $activity): AbstractActivity |
|
| 50 | + { |
|
| 51 | + $this->activity = $activity; |
|
| 52 | 52 | |
| 53 | - return $this; |
|
| 54 | - } |
|
| 53 | + return $this; |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |
@@ -13,572 +13,572 @@ |
||
| 13 | 13 | abstract class AbstractApi |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** API version */ |
|
| 17 | - const API_VERSION = 'v3'; |
|
| 18 | - |
|
| 19 | - /** API constants */ |
|
| 20 | - const API_URL = 'https://api.github.com'; |
|
| 21 | - const API_UPLOADS = 'https://uploads.github.com'; |
|
| 22 | - const API_RAW_URL = 'https://raw.github.com'; |
|
| 23 | - const CONTENT_TYPE = 'application/json'; |
|
| 24 | - const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json'; |
|
| 25 | - const USER_AGENT = 'FlexyProject-GitHubAPI'; |
|
| 26 | - |
|
| 27 | - /** Archive constants */ |
|
| 28 | - const ARCHIVE_TARBALL = 'tarball'; |
|
| 29 | - const ARCHIVE_ZIPBALL = 'zipball'; |
|
| 30 | - |
|
| 31 | - /** Authentication constants */ |
|
| 32 | - const OAUTH_AUTH = 0; |
|
| 33 | - const OAUTH2_HEADER_AUTH = 1; |
|
| 34 | - const OAUTH2_PARAMETERS_AUTH = 2; |
|
| 35 | - |
|
| 36 | - /** Branch constants */ |
|
| 37 | - const BRANCH_MASTER = 'master'; |
|
| 38 | - const BRANCH_DEVELOP = 'develop'; |
|
| 39 | - |
|
| 40 | - /** Direction constants */ |
|
| 41 | - const DIRECTION_ASC = 'asc'; |
|
| 42 | - const DIRECTION_DESC = 'desc'; |
|
| 43 | - |
|
| 44 | - /** Environment constants */ |
|
| 45 | - const ENVIRONMENT_PRODUCTION = 'production'; |
|
| 46 | - const ENVIRONMENT_STAGING = 'staging'; |
|
| 47 | - const ENVIRONMENT_QA = 'qa'; |
|
| 48 | - |
|
| 49 | - /** Events constants */ |
|
| 50 | - const EVENTS_PULL = 'pull'; |
|
| 51 | - const EVENTS_PULL_REQUEST = 'pull_request'; |
|
| 52 | - const EVENTS_PUSH = 'push'; |
|
| 53 | - |
|
| 54 | - /** Filter constants */ |
|
| 55 | - const FILTER_ALL = 'all'; |
|
| 56 | - const FILTER_ASSIGNED = 'assigned'; |
|
| 57 | - const FILTER_CREATED = 'created'; |
|
| 58 | - const FILTER_MENTIONED = 'mentioned'; |
|
| 59 | - const FILTER_SUBSCRIBED = 'subscribed'; |
|
| 60 | - |
|
| 61 | - /** Media types constants */ |
|
| 62 | - const MEDIA_TYPE_JSON = 'json'; |
|
| 63 | - const MEDIA_TYPE_RAW = 'raw'; |
|
| 64 | - const MEDIA_TYPE_FULL = 'full'; |
|
| 65 | - const MEDIA_TYPE_TEXT = 'text'; |
|
| 66 | - |
|
| 67 | - /** Modes constants */ |
|
| 68 | - const MODE_MARKDOWN = 'markdown'; |
|
| 69 | - const MODE_GFM = 'gfm'; |
|
| 70 | - |
|
| 71 | - /** Permissions constants */ |
|
| 72 | - const PERMISSION_ADMIN = 'admin'; |
|
| 73 | - const PERMISSION_PULL = 'pull'; |
|
| 74 | - const PERMISSION_PUSH = 'push'; |
|
| 75 | - |
|
| 76 | - /** Sort constants */ |
|
| 77 | - const SORT_COMPLETENESS = 'completeness'; |
|
| 78 | - const SORT_CREATED = 'created'; |
|
| 79 | - const SORT_DUE_DATE = 'due_date'; |
|
| 80 | - const SORT_FULL_NAME = 'full_name'; |
|
| 81 | - const SORT_NEWEST = 'newest'; |
|
| 82 | - const SORT_OLDEST = 'oldest'; |
|
| 83 | - const SORT_PUSHED = 'pushed'; |
|
| 84 | - const SORT_STARGAZERS = 'stargazers'; |
|
| 85 | - const SORT_UPDATED = 'updated'; |
|
| 86 | - |
|
| 87 | - /** State constants */ |
|
| 88 | - const STATE_ACTIVE = 'active'; |
|
| 89 | - const STATE_ALL = 'all'; |
|
| 90 | - const STATE_CLOSED = 'closed'; |
|
| 91 | - const STATE_ERROR = 'error'; |
|
| 92 | - const STATE_FAILURE = 'failure'; |
|
| 93 | - const STATE_OPEN = 'open'; |
|
| 94 | - const STATE_PENDING = 'pending'; |
|
| 95 | - const STATE_SUCCESS = 'success'; |
|
| 96 | - |
|
| 97 | - /** Task constants */ |
|
| 98 | - const TASK_DEPLOY = 'deploy'; |
|
| 99 | - const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations'; |
|
| 100 | - |
|
| 101 | - /** Type constants */ |
|
| 102 | - const TYPE_ALL = 'all'; |
|
| 103 | - const TYPE_COMMENTS = 'comments'; |
|
| 104 | - const TYPE_GISTS = 'gists'; |
|
| 105 | - const TYPE_HOOKS = 'hooks'; |
|
| 106 | - const TYPE_ISSUES = 'issues'; |
|
| 107 | - const TYPE_MEMBER = 'member'; |
|
| 108 | - const TYPE_MILESTONES = 'milestones'; |
|
| 109 | - const TYPE_ORGS = 'orgs'; |
|
| 110 | - const TYPE_OWNER = 'owner'; |
|
| 111 | - const TYPE_PAGES = 'pages'; |
|
| 112 | - const TYPE_PUBLIC = 'public'; |
|
| 113 | - const TYPE_PULLS = 'pulls'; |
|
| 114 | - const TYPE_PRIVATE = 'private'; |
|
| 115 | - const TYPE_REPOS = 'repos'; |
|
| 116 | - const TYPE_USERS = 'users'; |
|
| 117 | - |
|
| 118 | - /** Properties */ |
|
| 119 | - protected $accept = self::DEFAULT_ACCEPT; |
|
| 120 | - protected $apiUrl = self::API_URL; |
|
| 121 | - protected $authentication = self::OAUTH_AUTH; |
|
| 122 | - protected $clientId; |
|
| 123 | - protected $clientSecret; |
|
| 124 | - protected $contentType = self::CONTENT_TYPE; |
|
| 125 | - protected $failure; |
|
| 126 | - protected $headers = []; |
|
| 127 | - protected $httpAuth = ['username' => '', 'password' => '']; |
|
| 128 | - protected $success; |
|
| 129 | - protected $timeout = 240; |
|
| 130 | - protected $token = ''; |
|
| 131 | - protected $request; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Constructor |
|
| 135 | - */ |
|
| 136 | - public function __construct() |
|
| 137 | - { |
|
| 138 | - $this->request = Request::createFromGlobals(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Get request |
|
| 143 | - * |
|
| 144 | - * @return Request |
|
| 145 | - */ |
|
| 146 | - public function getRequest(): Request |
|
| 147 | - { |
|
| 148 | - return $this->request; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Get accept |
|
| 153 | - * |
|
| 154 | - * @return mixed |
|
| 155 | - */ |
|
| 156 | - public function getAccept() |
|
| 157 | - { |
|
| 158 | - return $this->accept; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Set accept |
|
| 163 | - * |
|
| 164 | - * @param array|string $accept |
|
| 165 | - * |
|
| 166 | - * @return AbstractApi |
|
| 167 | - */ |
|
| 168 | - public function setAccept($accept): AbstractApi |
|
| 169 | - { |
|
| 170 | - $this->accept = $accept; |
|
| 171 | - |
|
| 172 | - return $this; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Get authentication |
|
| 177 | - * |
|
| 178 | - * @return int |
|
| 179 | - */ |
|
| 180 | - public function getAuthentication(): int |
|
| 181 | - { |
|
| 182 | - return $this->authentication; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Set authentication |
|
| 187 | - * |
|
| 188 | - * @param int $authentication |
|
| 189 | - * |
|
| 190 | - * @return AbstractApi |
|
| 191 | - */ |
|
| 192 | - public function setAuthentication(int $authentication): AbstractApi |
|
| 193 | - { |
|
| 194 | - $this->authentication = $authentication; |
|
| 195 | - |
|
| 196 | - return $this; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Get apiUrl |
|
| 201 | - * |
|
| 202 | - * @return string |
|
| 203 | - */ |
|
| 204 | - public function getApiUrl(): string |
|
| 205 | - { |
|
| 206 | - return $this->apiUrl; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Set apiUrl |
|
| 211 | - * |
|
| 212 | - * @param mixed $apiUrl |
|
| 213 | - * |
|
| 214 | - * @return AbstractApi |
|
| 215 | - */ |
|
| 216 | - public function setApiUrl($apiUrl): AbstractApi |
|
| 217 | - { |
|
| 218 | - $this->apiUrl = $apiUrl; |
|
| 219 | - |
|
| 220 | - return $this; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Get clientId |
|
| 225 | - * |
|
| 226 | - * @return null|int |
|
| 227 | - */ |
|
| 228 | - public function getClientId() |
|
| 229 | - { |
|
| 230 | - return $this->clientId; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Set clientId |
|
| 235 | - * |
|
| 236 | - * @param mixed $clientId |
|
| 237 | - * |
|
| 238 | - * @return AbstractApi |
|
| 239 | - */ |
|
| 240 | - public function setClientId($clientId): AbstractApi |
|
| 241 | - { |
|
| 242 | - $this->clientId = $clientId; |
|
| 243 | - |
|
| 244 | - return $this; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Get clientSecret |
|
| 249 | - * |
|
| 250 | - * @return null|string |
|
| 251 | - */ |
|
| 252 | - public function getClientSecret() |
|
| 253 | - { |
|
| 254 | - return $this->clientSecret; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Set clientSecret |
|
| 259 | - * |
|
| 260 | - * @param mixed $clientSecret |
|
| 261 | - * |
|
| 262 | - * @return AbstractApi |
|
| 263 | - */ |
|
| 264 | - public function setClientSecret($clientSecret): AbstractApi |
|
| 265 | - { |
|
| 266 | - $this->clientSecret = $clientSecret; |
|
| 267 | - |
|
| 268 | - return $this; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Get httpAuth |
|
| 273 | - * |
|
| 274 | - * @return array |
|
| 275 | - */ |
|
| 276 | - public function getHttpAuth(): array |
|
| 277 | - { |
|
| 278 | - return $this->httpAuth; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Set httpAuth |
|
| 283 | - * |
|
| 284 | - * @param string $username |
|
| 285 | - * @param string $password |
|
| 286 | - * |
|
| 287 | - * @return AbstractApi |
|
| 288 | - */ |
|
| 289 | - public function setHttpAuth(string $username, string $password = ''): AbstractApi |
|
| 290 | - { |
|
| 291 | - $this->httpAuth['username'] = $username; |
|
| 292 | - $this->httpAuth['password'] = $password; |
|
| 293 | - |
|
| 294 | - return $this; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Get token |
|
| 299 | - * |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - public function getToken(): string |
|
| 303 | - { |
|
| 304 | - return $this->token; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Set token |
|
| 309 | - * |
|
| 310 | - * @param string $token |
|
| 311 | - * @param int $authentication |
|
| 312 | - * |
|
| 313 | - * @return AbstractApi |
|
| 314 | - */ |
|
| 315 | - public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi |
|
| 316 | - { |
|
| 317 | - $this->token = $token; |
|
| 318 | - $this->setAuthentication($authentication); |
|
| 319 | - |
|
| 320 | - return $this; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Get timeout |
|
| 325 | - * |
|
| 326 | - * @return int |
|
| 327 | - */ |
|
| 328 | - public function getTimeout(): int |
|
| 329 | - { |
|
| 330 | - return $this->timeout; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Set timeout |
|
| 335 | - * |
|
| 336 | - * @param int $timeout |
|
| 337 | - * |
|
| 338 | - * @return AbstractApi |
|
| 339 | - */ |
|
| 340 | - public function setTimeout(int $timeout): AbstractApi |
|
| 341 | - { |
|
| 342 | - $this->timeout = $timeout; |
|
| 343 | - |
|
| 344 | - return $this; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Get contentType |
|
| 349 | - * |
|
| 350 | - * @return string |
|
| 351 | - */ |
|
| 352 | - public function getContentType(): string |
|
| 353 | - { |
|
| 354 | - return $this->contentType; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Set contentType |
|
| 359 | - * |
|
| 360 | - * @param string $contentType |
|
| 361 | - * |
|
| 362 | - * @return AbstractApi |
|
| 363 | - */ |
|
| 364 | - public function setContentType(string $contentType): AbstractApi |
|
| 365 | - { |
|
| 366 | - $this->contentType = $contentType; |
|
| 367 | - |
|
| 368 | - return $this; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Get headers |
|
| 373 | - * |
|
| 374 | - * @return array |
|
| 375 | - */ |
|
| 376 | - public function getHeaders(): array |
|
| 377 | - { |
|
| 378 | - return $this->headers; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Curl request |
|
| 383 | - * |
|
| 384 | - * @param string $url |
|
| 385 | - * @param string $method |
|
| 386 | - * @param array $postFields |
|
| 387 | - * @param null|string $apiUrl |
|
| 388 | - * |
|
| 389 | - * @return array |
|
| 390 | - */ |
|
| 391 | - public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [], |
|
| 392 | - string $apiUrl = null): array |
|
| 393 | - { |
|
| 394 | - /** Building url */ |
|
| 395 | - if (null === $apiUrl) { |
|
| 396 | - $apiUrl = $this->getApiUrl(); |
|
| 397 | - } |
|
| 398 | - $url = $apiUrl . $url; |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * OAuth2 Key/Secret authentication |
|
| 402 | - * |
|
| 403 | - * @see https://developer.github.com/v3/#oauth2-keysecret |
|
| 404 | - */ |
|
| 405 | - if (null !== $this->getClientId() && null !== $this->getClientSecret()) { |
|
| 406 | - $url .= (strstr($url, '?') !== false ? '&' : '?'); |
|
| 407 | - $url .= http_build_query(['client_id' => $this->getClientId(), |
|
| 408 | - 'client_secret' => $this->getClientSecret() |
|
| 409 | - ]); |
|
| 410 | - } /** |
|
| 411 | - * Basic authentication via OAuth2 Token (sent as a parameter) |
|
| 412 | - * |
|
| 413 | - * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter |
|
| 414 | - */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) { |
|
| 415 | - $url .= http_build_query(['access_token' => $this->getToken()]); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** Call curl */ |
|
| 419 | - $curl = new CurlClient(); |
|
| 420 | - $curl->setOption([ |
|
| 421 | - CURLOPT_USERAGENT => self::USER_AGENT, |
|
| 422 | - CURLOPT_TIMEOUT => $this->getTimeout(), |
|
| 423 | - CURLOPT_HEADER => false, // Use $client->getHeaders() to get full header |
|
| 424 | - CURLOPT_FOLLOWLOCATION => true, |
|
| 425 | - CURLOPT_HTTPHEADER => [ |
|
| 426 | - 'Accept: ' . $this->getAccept(), |
|
| 427 | - 'Content-Type: ' . $this->getContentType() |
|
| 428 | - ], |
|
| 429 | - CURLOPT_URL => $url |
|
| 430 | - ]); |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Basic authentication via username and Password |
|
| 434 | - * |
|
| 435 | - * @see https://developer.github.com/v3/auth/#via-username-and-password |
|
| 436 | - */ |
|
| 437 | - if (!empty($this->getHttpAuth())) { |
|
| 438 | - if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) { |
|
| 439 | - $curl->setOption([ |
|
| 440 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 441 | - CURLOPT_USERPWD => $this->getHttpAuth()['username'] |
|
| 442 | - ]); |
|
| 443 | - } else { |
|
| 444 | - $curl->setOption([ |
|
| 445 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 446 | - CURLOPT_USERPWD => sprintf('%s:%s', $this->getHttpAuth()['username'], |
|
| 447 | - $this->getHttpAuth()['password']) |
|
| 448 | - ]); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) { |
|
| 453 | - /** |
|
| 454 | - * Basic authentication via OAuth token |
|
| 455 | - * |
|
| 456 | - * @see https://developer.github.com/v3/auth/#via-oauth-tokens |
|
| 457 | - **/ |
|
| 458 | - if ($this->getAuthentication() === self::OAUTH_AUTH) { |
|
| 459 | - $curl->setOption([ |
|
| 460 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 461 | - CURLOPT_USERPWD => sprintf('%s:x-oauth-basic', $this->getToken()) |
|
| 462 | - ]); |
|
| 463 | - } /** |
|
| 464 | - * Basic authentication via OAuth2 Token (sent in a header) |
|
| 465 | - * |
|
| 466 | - * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header |
|
| 467 | - */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) { |
|
| 468 | - $curl->setOption([ |
|
| 469 | - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 470 | - CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())] |
|
| 471 | - ]); |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** Methods */ |
|
| 476 | - switch ($method) { |
|
| 477 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */ |
|
| 478 | - case Request::METHOD_DELETE: |
|
| 479 | - /** @see http://tools.ietf.org/html/rfc5789 */ |
|
| 480 | - case Request::METHOD_PATCH: |
|
| 481 | - $curl->setOption([ |
|
| 482 | - CURLOPT_CUSTOMREQUEST => $method, |
|
| 483 | - CURLOPT_POST => true, |
|
| 484 | - CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 485 | - ]); |
|
| 486 | - break; |
|
| 487 | - |
|
| 488 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */ |
|
| 489 | - case Request::METHOD_GET: |
|
| 490 | - $curl->setOption(CURLOPT_HTTPGET, true); |
|
| 491 | - break; |
|
| 492 | - |
|
| 493 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */ |
|
| 494 | - case Request::METHOD_HEAD: |
|
| 495 | - $curl->setOption([ |
|
| 496 | - CURLOPT_CUSTOMREQUEST => $method, |
|
| 497 | - CURLOPT_NOBODY => true |
|
| 498 | - ]); |
|
| 499 | - break; |
|
| 500 | - |
|
| 501 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */ |
|
| 502 | - case Request::METHOD_POST: |
|
| 503 | - $curl->setOption([ |
|
| 504 | - CURLOPT_POST => true, |
|
| 505 | - CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 506 | - ]); |
|
| 507 | - break; |
|
| 508 | - |
|
| 509 | - /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */ |
|
| 510 | - case Request::METHOD_PUT: |
|
| 511 | - $curl->setOption([ |
|
| 512 | - CURLOPT_CUSTOMREQUEST => $method, |
|
| 513 | - CURLOPT_PUT => true, |
|
| 514 | - CURLOPT_HTTPHEADER => [ |
|
| 515 | - 'X-HTTP-Method-Override: PUT', |
|
| 516 | - 'Content-type: application/x-www-form-urlencoded' |
|
| 517 | - ] |
|
| 518 | - ]); |
|
| 519 | - break; |
|
| 520 | - |
|
| 521 | - default: |
|
| 522 | - break; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $curl->success(function (CurlClient $instance) { |
|
| 526 | - $this->headers = $instance->getHeaders(); |
|
| 527 | - $this->success = $instance->getResponse(); |
|
| 528 | - $data = json_decode($this->success, true); |
|
| 529 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
| 530 | - $this->success = $data; |
|
| 531 | - } |
|
| 532 | - }); |
|
| 533 | - $curl->error(function (CurlClient $instance) { |
|
| 534 | - $this->headers = $instance->getHeaders(); |
|
| 535 | - $this->failure = $instance->getResponse(); |
|
| 536 | - $data = json_decode($this->failure, true); |
|
| 537 | - if (JSON_ERROR_NONE === json_last_error()) { |
|
| 538 | - $this->failure = $data; |
|
| 539 | - } |
|
| 540 | - }); |
|
| 541 | - $curl->perform(); |
|
| 542 | - |
|
| 543 | - return (array)($this->success ?? $this->failure); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Return a formatted string. Modified version of sprintf using colon(:) |
|
| 548 | - * |
|
| 549 | - * @param string $string |
|
| 550 | - * @param array $params |
|
| 551 | - * |
|
| 552 | - * @return String |
|
| 553 | - * @throws Exception |
|
| 554 | - */ |
|
| 555 | - public function sprintf(string $string, ...$params): string |
|
| 556 | - { |
|
| 557 | - preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches); |
|
| 558 | - $matches = $matches[1]; |
|
| 559 | - |
|
| 560 | - if (count($matches)) { |
|
| 561 | - $tokens = []; |
|
| 562 | - $replaces = []; |
|
| 563 | - |
|
| 564 | - foreach ($matches as $key => $value) { |
|
| 565 | - if (count($params) > 1 || !is_array($params[0])) { |
|
| 566 | - if (!array_key_exists($key, $params)) { |
|
| 567 | - throw new Exception('Too few arguments, missing argument: ' . $key); |
|
| 568 | - } |
|
| 569 | - $replaces[] = $params[$key]; |
|
| 570 | - } else { |
|
| 571 | - if (!array_key_exists($value, $params[0])) { |
|
| 572 | - throw new Exception('Missing array argument: ' . $key); |
|
| 573 | - } |
|
| 574 | - $replaces[] = $params[0][$value]; |
|
| 575 | - } |
|
| 576 | - $tokens[] = ':' . $value; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - $string = str_replace($tokens, $replaces, $string); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - return $string; |
|
| 583 | - } |
|
| 16 | + /** API version */ |
|
| 17 | + const API_VERSION = 'v3'; |
|
| 18 | + |
|
| 19 | + /** API constants */ |
|
| 20 | + const API_URL = 'https://api.github.com'; |
|
| 21 | + const API_UPLOADS = 'https://uploads.github.com'; |
|
| 22 | + const API_RAW_URL = 'https://raw.github.com'; |
|
| 23 | + const CONTENT_TYPE = 'application/json'; |
|
| 24 | + const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json'; |
|
| 25 | + const USER_AGENT = 'FlexyProject-GitHubAPI'; |
|
| 26 | + |
|
| 27 | + /** Archive constants */ |
|
| 28 | + const ARCHIVE_TARBALL = 'tarball'; |
|
| 29 | + const ARCHIVE_ZIPBALL = 'zipball'; |
|
| 30 | + |
|
| 31 | + /** Authentication constants */ |
|
| 32 | + const OAUTH_AUTH = 0; |
|
| 33 | + const OAUTH2_HEADER_AUTH = 1; |
|
| 34 | + const OAUTH2_PARAMETERS_AUTH = 2; |
|
| 35 | + |
|
| 36 | + /** Branch constants */ |
|
| 37 | + const BRANCH_MASTER = 'master'; |
|
| 38 | + const BRANCH_DEVELOP = 'develop'; |
|
| 39 | + |
|
| 40 | + /** Direction constants */ |
|
| 41 | + const DIRECTION_ASC = 'asc'; |
|
| 42 | + const DIRECTION_DESC = 'desc'; |
|
| 43 | + |
|
| 44 | + /** Environment constants */ |
|
| 45 | + const ENVIRONMENT_PRODUCTION = 'production'; |
|
| 46 | + const ENVIRONMENT_STAGING = 'staging'; |
|
| 47 | + const ENVIRONMENT_QA = 'qa'; |
|
| 48 | + |
|
| 49 | + /** Events constants */ |
|
| 50 | + const EVENTS_PULL = 'pull'; |
|
| 51 | + const EVENTS_PULL_REQUEST = 'pull_request'; |
|
| 52 | + const EVENTS_PUSH = 'push'; |
|
| 53 | + |
|
| 54 | + /** Filter constants */ |
|
| 55 | + const FILTER_ALL = 'all'; |
|
| 56 | + const FILTER_ASSIGNED = 'assigned'; |
|
| 57 | + const FILTER_CREATED = 'created'; |
|
| 58 | + const FILTER_MENTIONED = 'mentioned'; |
|
| 59 | + const FILTER_SUBSCRIBED = 'subscribed'; |
|
| 60 | + |
|
| 61 | + /** Media types constants */ |
|
| 62 | + const MEDIA_TYPE_JSON = 'json'; |
|
| 63 | + const MEDIA_TYPE_RAW = 'raw'; |
|
| 64 | + const MEDIA_TYPE_FULL = 'full'; |
|
| 65 | + const MEDIA_TYPE_TEXT = 'text'; |
|
| 66 | + |
|
| 67 | + /** Modes constants */ |
|
| 68 | + const MODE_MARKDOWN = 'markdown'; |
|
| 69 | + const MODE_GFM = 'gfm'; |
|
| 70 | + |
|
| 71 | + /** Permissions constants */ |
|
| 72 | + const PERMISSION_ADMIN = 'admin'; |
|
| 73 | + const PERMISSION_PULL = 'pull'; |
|
| 74 | + const PERMISSION_PUSH = 'push'; |
|
| 75 | + |
|
| 76 | + /** Sort constants */ |
|
| 77 | + const SORT_COMPLETENESS = 'completeness'; |
|
| 78 | + const SORT_CREATED = 'created'; |
|
| 79 | + const SORT_DUE_DATE = 'due_date'; |
|
| 80 | + const SORT_FULL_NAME = 'full_name'; |
|
| 81 | + const SORT_NEWEST = 'newest'; |
|
| 82 | + const SORT_OLDEST = 'oldest'; |
|
| 83 | + const SORT_PUSHED = 'pushed'; |
|
| 84 | + const SORT_STARGAZERS = 'stargazers'; |
|
| 85 | + const SORT_UPDATED = 'updated'; |
|
| 86 | + |
|
| 87 | + /** State constants */ |
|
| 88 | + const STATE_ACTIVE = 'active'; |
|
| 89 | + const STATE_ALL = 'all'; |
|
| 90 | + const STATE_CLOSED = 'closed'; |
|
| 91 | + const STATE_ERROR = 'error'; |
|
| 92 | + const STATE_FAILURE = 'failure'; |
|
| 93 | + const STATE_OPEN = 'open'; |
|
| 94 | + const STATE_PENDING = 'pending'; |
|
| 95 | + const STATE_SUCCESS = 'success'; |
|
| 96 | + |
|
| 97 | + /** Task constants */ |
|
| 98 | + const TASK_DEPLOY = 'deploy'; |
|
| 99 | + const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations'; |
|
| 100 | + |
|
| 101 | + /** Type constants */ |
|
| 102 | + const TYPE_ALL = 'all'; |
|
| 103 | + const TYPE_COMMENTS = 'comments'; |
|
| 104 | + const TYPE_GISTS = 'gists'; |
|
| 105 | + const TYPE_HOOKS = 'hooks'; |
|
| 106 | + const TYPE_ISSUES = 'issues'; |
|
| 107 | + const TYPE_MEMBER = 'member'; |
|
| 108 | + const TYPE_MILESTONES = 'milestones'; |
|
| 109 | + const TYPE_ORGS = 'orgs'; |
|
| 110 | + const TYPE_OWNER = 'owner'; |
|
| 111 | + const TYPE_PAGES = 'pages'; |
|
| 112 | + const TYPE_PUBLIC = 'public'; |
|
| 113 | + const TYPE_PULLS = 'pulls'; |
|
| 114 | + const TYPE_PRIVATE = 'private'; |
|
| 115 | + const TYPE_REPOS = 'repos'; |
|
| 116 | + const TYPE_USERS = 'users'; |
|
| 117 | + |
|
| 118 | + /** Properties */ |
|
| 119 | + protected $accept = self::DEFAULT_ACCEPT; |
|
| 120 | + protected $apiUrl = self::API_URL; |
|
| 121 | + protected $authentication = self::OAUTH_AUTH; |
|
| 122 | + protected $clientId; |
|
| 123 | + protected $clientSecret; |
|
| 124 | + protected $contentType = self::CONTENT_TYPE; |
|
| 125 | + protected $failure; |
|
| 126 | + protected $headers = []; |
|
| 127 | + protected $httpAuth = ['username' => '', 'password' => '']; |
|
| 128 | + protected $success; |
|
| 129 | + protected $timeout = 240; |
|
| 130 | + protected $token = ''; |
|
| 131 | + protected $request; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Constructor |
|
| 135 | + */ |
|
| 136 | + public function __construct() |
|
| 137 | + { |
|
| 138 | + $this->request = Request::createFromGlobals(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Get request |
|
| 143 | + * |
|
| 144 | + * @return Request |
|
| 145 | + */ |
|
| 146 | + public function getRequest(): Request |
|
| 147 | + { |
|
| 148 | + return $this->request; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Get accept |
|
| 153 | + * |
|
| 154 | + * @return mixed |
|
| 155 | + */ |
|
| 156 | + public function getAccept() |
|
| 157 | + { |
|
| 158 | + return $this->accept; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Set accept |
|
| 163 | + * |
|
| 164 | + * @param array|string $accept |
|
| 165 | + * |
|
| 166 | + * @return AbstractApi |
|
| 167 | + */ |
|
| 168 | + public function setAccept($accept): AbstractApi |
|
| 169 | + { |
|
| 170 | + $this->accept = $accept; |
|
| 171 | + |
|
| 172 | + return $this; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Get authentication |
|
| 177 | + * |
|
| 178 | + * @return int |
|
| 179 | + */ |
|
| 180 | + public function getAuthentication(): int |
|
| 181 | + { |
|
| 182 | + return $this->authentication; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Set authentication |
|
| 187 | + * |
|
| 188 | + * @param int $authentication |
|
| 189 | + * |
|
| 190 | + * @return AbstractApi |
|
| 191 | + */ |
|
| 192 | + public function setAuthentication(int $authentication): AbstractApi |
|
| 193 | + { |
|
| 194 | + $this->authentication = $authentication; |
|
| 195 | + |
|
| 196 | + return $this; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Get apiUrl |
|
| 201 | + * |
|
| 202 | + * @return string |
|
| 203 | + */ |
|
| 204 | + public function getApiUrl(): string |
|
| 205 | + { |
|
| 206 | + return $this->apiUrl; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Set apiUrl |
|
| 211 | + * |
|
| 212 | + * @param mixed $apiUrl |
|
| 213 | + * |
|
| 214 | + * @return AbstractApi |
|
| 215 | + */ |
|
| 216 | + public function setApiUrl($apiUrl): AbstractApi |
|
| 217 | + { |
|
| 218 | + $this->apiUrl = $apiUrl; |
|
| 219 | + |
|
| 220 | + return $this; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Get clientId |
|
| 225 | + * |
|
| 226 | + * @return null|int |
|
| 227 | + */ |
|
| 228 | + public function getClientId() |
|
| 229 | + { |
|
| 230 | + return $this->clientId; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Set clientId |
|
| 235 | + * |
|
| 236 | + * @param mixed $clientId |
|
| 237 | + * |
|
| 238 | + * @return AbstractApi |
|
| 239 | + */ |
|
| 240 | + public function setClientId($clientId): AbstractApi |
|
| 241 | + { |
|
| 242 | + $this->clientId = $clientId; |
|
| 243 | + |
|
| 244 | + return $this; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Get clientSecret |
|
| 249 | + * |
|
| 250 | + * @return null|string |
|
| 251 | + */ |
|
| 252 | + public function getClientSecret() |
|
| 253 | + { |
|
| 254 | + return $this->clientSecret; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Set clientSecret |
|
| 259 | + * |
|
| 260 | + * @param mixed $clientSecret |
|
| 261 | + * |
|
| 262 | + * @return AbstractApi |
|
| 263 | + */ |
|
| 264 | + public function setClientSecret($clientSecret): AbstractApi |
|
| 265 | + { |
|
| 266 | + $this->clientSecret = $clientSecret; |
|
| 267 | + |
|
| 268 | + return $this; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Get httpAuth |
|
| 273 | + * |
|
| 274 | + * @return array |
|
| 275 | + */ |
|
| 276 | + public function getHttpAuth(): array |
|
| 277 | + { |
|
| 278 | + return $this->httpAuth; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Set httpAuth |
|
| 283 | + * |
|
| 284 | + * @param string $username |
|
| 285 | + * @param string $password |
|
| 286 | + * |
|
| 287 | + * @return AbstractApi |
|
| 288 | + */ |
|
| 289 | + public function setHttpAuth(string $username, string $password = ''): AbstractApi |
|
| 290 | + { |
|
| 291 | + $this->httpAuth['username'] = $username; |
|
| 292 | + $this->httpAuth['password'] = $password; |
|
| 293 | + |
|
| 294 | + return $this; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Get token |
|
| 299 | + * |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + public function getToken(): string |
|
| 303 | + { |
|
| 304 | + return $this->token; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Set token |
|
| 309 | + * |
|
| 310 | + * @param string $token |
|
| 311 | + * @param int $authentication |
|
| 312 | + * |
|
| 313 | + * @return AbstractApi |
|
| 314 | + */ |
|
| 315 | + public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi |
|
| 316 | + { |
|
| 317 | + $this->token = $token; |
|
| 318 | + $this->setAuthentication($authentication); |
|
| 319 | + |
|
| 320 | + return $this; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Get timeout |
|
| 325 | + * |
|
| 326 | + * @return int |
|
| 327 | + */ |
|
| 328 | + public function getTimeout(): int |
|
| 329 | + { |
|
| 330 | + return $this->timeout; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Set timeout |
|
| 335 | + * |
|
| 336 | + * @param int $timeout |
|
| 337 | + * |
|
| 338 | + * @return AbstractApi |
|
| 339 | + */ |
|
| 340 | + public function setTimeout(int $timeout): AbstractApi |
|
| 341 | + { |
|
| 342 | + $this->timeout = $timeout; |
|
| 343 | + |
|
| 344 | + return $this; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Get contentType |
|
| 349 | + * |
|
| 350 | + * @return string |
|
| 351 | + */ |
|
| 352 | + public function getContentType(): string |
|
| 353 | + { |
|
| 354 | + return $this->contentType; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Set contentType |
|
| 359 | + * |
|
| 360 | + * @param string $contentType |
|
| 361 | + * |
|
| 362 | + * @return AbstractApi |
|
| 363 | + */ |
|
| 364 | + public function setContentType(string $contentType): AbstractApi |
|
| 365 | + { |
|
| 366 | + $this->contentType = $contentType; |
|
| 367 | + |
|
| 368 | + return $this; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Get headers |
|
| 373 | + * |
|
| 374 | + * @return array |
|
| 375 | + */ |
|
| 376 | + public function getHeaders(): array |
|
| 377 | + { |
|
| 378 | + return $this->headers; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Curl request |
|
| 383 | + * |
|
| 384 | + * @param string $url |
|
| 385 | + * @param string $method |
|
| 386 | + * @param array $postFields |
|
| 387 | + * @param null|string $apiUrl |
|
| 388 | + * |
|
| 389 | + * @return array |
|
| 390 | + */ |
|
| 391 | + public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [], |
|
| 392 | + string $apiUrl = null): array |
|
| 393 | + { |
|
| 394 | + /** Building url */ |
|
| 395 | + if (null === $apiUrl) { |
|
| 396 | + $apiUrl = $this->getApiUrl(); |
|
| 397 | + } |
|
| 398 | + $url = $apiUrl . $url; |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * OAuth2 Key/Secret authentication |
|
| 402 | + * |
|
| 403 | + * @see https://developer.github.com/v3/#oauth2-keysecret |
|
| 404 | + */ |
|
| 405 | + if (null !== $this->getClientId() && null !== $this->getClientSecret()) { |
|
| 406 | + $url .= (strstr($url, '?') !== false ? '&' : '?'); |
|
| 407 | + $url .= http_build_query(['client_id' => $this->getClientId(), |
|
| 408 | + 'client_secret' => $this->getClientSecret() |
|
| 409 | + ]); |
|
| 410 | + } /** |
|
| 411 | + * Basic authentication via OAuth2 Token (sent as a parameter) |
|
| 412 | + * |
|
| 413 | + * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter |
|
| 414 | + */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) { |
|
| 415 | + $url .= http_build_query(['access_token' => $this->getToken()]); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** Call curl */ |
|
| 419 | + $curl = new CurlClient(); |
|
| 420 | + $curl->setOption([ |
|
| 421 | + CURLOPT_USERAGENT => self::USER_AGENT, |
|
| 422 | + CURLOPT_TIMEOUT => $this->getTimeout(), |
|
| 423 | + CURLOPT_HEADER => false, // Use $client->getHeaders() to get full header |
|
| 424 | + CURLOPT_FOLLOWLOCATION => true, |
|
| 425 | + CURLOPT_HTTPHEADER => [ |
|
| 426 | + 'Accept: ' . $this->getAccept(), |
|
| 427 | + 'Content-Type: ' . $this->getContentType() |
|
| 428 | + ], |
|
| 429 | + CURLOPT_URL => $url |
|
| 430 | + ]); |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Basic authentication via username and Password |
|
| 434 | + * |
|
| 435 | + * @see https://developer.github.com/v3/auth/#via-username-and-password |
|
| 436 | + */ |
|
| 437 | + if (!empty($this->getHttpAuth())) { |
|
| 438 | + if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) { |
|
| 439 | + $curl->setOption([ |
|
| 440 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 441 | + CURLOPT_USERPWD => $this->getHttpAuth()['username'] |
|
| 442 | + ]); |
|
| 443 | + } else { |
|
| 444 | + $curl->setOption([ |
|
| 445 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 446 | + CURLOPT_USERPWD => sprintf('%s:%s', $this->getHttpAuth()['username'], |
|
| 447 | + $this->getHttpAuth()['password']) |
|
| 448 | + ]); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) { |
|
| 453 | + /** |
|
| 454 | + * Basic authentication via OAuth token |
|
| 455 | + * |
|
| 456 | + * @see https://developer.github.com/v3/auth/#via-oauth-tokens |
|
| 457 | + **/ |
|
| 458 | + if ($this->getAuthentication() === self::OAUTH_AUTH) { |
|
| 459 | + $curl->setOption([ |
|
| 460 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 461 | + CURLOPT_USERPWD => sprintf('%s:x-oauth-basic', $this->getToken()) |
|
| 462 | + ]); |
|
| 463 | + } /** |
|
| 464 | + * Basic authentication via OAuth2 Token (sent in a header) |
|
| 465 | + * |
|
| 466 | + * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header |
|
| 467 | + */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) { |
|
| 468 | + $curl->setOption([ |
|
| 469 | + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
|
| 470 | + CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())] |
|
| 471 | + ]); |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** Methods */ |
|
| 476 | + switch ($method) { |
|
| 477 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */ |
|
| 478 | + case Request::METHOD_DELETE: |
|
| 479 | + /** @see http://tools.ietf.org/html/rfc5789 */ |
|
| 480 | + case Request::METHOD_PATCH: |
|
| 481 | + $curl->setOption([ |
|
| 482 | + CURLOPT_CUSTOMREQUEST => $method, |
|
| 483 | + CURLOPT_POST => true, |
|
| 484 | + CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 485 | + ]); |
|
| 486 | + break; |
|
| 487 | + |
|
| 488 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */ |
|
| 489 | + case Request::METHOD_GET: |
|
| 490 | + $curl->setOption(CURLOPT_HTTPGET, true); |
|
| 491 | + break; |
|
| 492 | + |
|
| 493 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */ |
|
| 494 | + case Request::METHOD_HEAD: |
|
| 495 | + $curl->setOption([ |
|
| 496 | + CURLOPT_CUSTOMREQUEST => $method, |
|
| 497 | + CURLOPT_NOBODY => true |
|
| 498 | + ]); |
|
| 499 | + break; |
|
| 500 | + |
|
| 501 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */ |
|
| 502 | + case Request::METHOD_POST: |
|
| 503 | + $curl->setOption([ |
|
| 504 | + CURLOPT_POST => true, |
|
| 505 | + CURLOPT_POSTFIELDS => json_encode(array_filter($postFields)) |
|
| 506 | + ]); |
|
| 507 | + break; |
|
| 508 | + |
|
| 509 | + /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */ |
|
| 510 | + case Request::METHOD_PUT: |
|
| 511 | + $curl->setOption([ |
|
| 512 | + CURLOPT_CUSTOMREQUEST => $method, |
|
| 513 | + CURLOPT_PUT => true, |
|
| 514 | + CURLOPT_HTTPHEADER => [ |
|
| 515 | + 'X-HTTP-Method-Override: PUT', |
|
| 516 | + 'Content-type: application/x-www-form-urlencoded' |
|
| 517 | + ] |
|
| 518 | + ]); |
|
| 519 | + break; |
|
| 520 | + |
|
| 521 | + default: |
|
| 522 | + break; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $curl->success(function (CurlClient $instance) { |
|
| 526 | + $this->headers = $instance->getHeaders(); |
|
| 527 | + $this->success = $instance->getResponse(); |
|
| 528 | + $data = json_decode($this->success, true); |
|
| 529 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
| 530 | + $this->success = $data; |
|
| 531 | + } |
|
| 532 | + }); |
|
| 533 | + $curl->error(function (CurlClient $instance) { |
|
| 534 | + $this->headers = $instance->getHeaders(); |
|
| 535 | + $this->failure = $instance->getResponse(); |
|
| 536 | + $data = json_decode($this->failure, true); |
|
| 537 | + if (JSON_ERROR_NONE === json_last_error()) { |
|
| 538 | + $this->failure = $data; |
|
| 539 | + } |
|
| 540 | + }); |
|
| 541 | + $curl->perform(); |
|
| 542 | + |
|
| 543 | + return (array)($this->success ?? $this->failure); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Return a formatted string. Modified version of sprintf using colon(:) |
|
| 548 | + * |
|
| 549 | + * @param string $string |
|
| 550 | + * @param array $params |
|
| 551 | + * |
|
| 552 | + * @return String |
|
| 553 | + * @throws Exception |
|
| 554 | + */ |
|
| 555 | + public function sprintf(string $string, ...$params): string |
|
| 556 | + { |
|
| 557 | + preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches); |
|
| 558 | + $matches = $matches[1]; |
|
| 559 | + |
|
| 560 | + if (count($matches)) { |
|
| 561 | + $tokens = []; |
|
| 562 | + $replaces = []; |
|
| 563 | + |
|
| 564 | + foreach ($matches as $key => $value) { |
|
| 565 | + if (count($params) > 1 || !is_array($params[0])) { |
|
| 566 | + if (!array_key_exists($key, $params)) { |
|
| 567 | + throw new Exception('Too few arguments, missing argument: ' . $key); |
|
| 568 | + } |
|
| 569 | + $replaces[] = $params[$key]; |
|
| 570 | + } else { |
|
| 571 | + if (!array_key_exists($value, $params[0])) { |
|
| 572 | + throw new Exception('Missing array argument: ' . $key); |
|
| 573 | + } |
|
| 574 | + $replaces[] = $params[0][$value]; |
|
| 575 | + } |
|
| 576 | + $tokens[] = ':' . $value; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + $string = str_replace($tokens, $replaces, $string); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + return $string; |
|
| 583 | + } |
|
| 584 | 584 | } |
| 585 | 585 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace FlexyProject\GitHub\Tests\Receiver; |
| 3 | 3 | |
| 4 | 4 | use FlexyProject\GitHub\{ |
| 5 | - AbstractApi, Client, Receiver\Miscellaneous, Tests\AbstractTest |
|
| 5 | + AbstractApi, Client, Receiver\Miscellaneous, Tests\AbstractTest |
|
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -13,153 +13,153 @@ discard block |
||
| 13 | 13 | class MiscellaneousTest extends AbstractTest |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** @var Miscellaneous */ |
|
| 17 | - protected $miscellaneous; |
|
| 18 | - |
|
| 19 | - /** @var Miscellaneous\Emojis */ |
|
| 20 | - protected $emojis; |
|
| 21 | - |
|
| 22 | - /** @var Miscellaneous\Gitignore */ |
|
| 23 | - protected $gitIgnore; |
|
| 24 | - |
|
| 25 | - /** @var Miscellaneous\Licenses */ |
|
| 26 | - protected $licenses; |
|
| 27 | - |
|
| 28 | - /** @var Miscellaneous\Markdown */ |
|
| 29 | - protected $markdown; |
|
| 30 | - |
|
| 31 | - /** @var Miscellaneous\Meta */ |
|
| 32 | - protected $meta; |
|
| 33 | - |
|
| 34 | - /** @var Miscellaneous\RateLimit */ |
|
| 35 | - protected $rateLimit; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * MiscellaneousTest constructor. |
|
| 39 | - * |
|
| 40 | - * @param null $name |
|
| 41 | - * @param array $data |
|
| 42 | - * @param string $dataName |
|
| 43 | - */ |
|
| 44 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
| 45 | - { |
|
| 46 | - parent::__construct($name, $data, $dataName); |
|
| 47 | - |
|
| 48 | - // Miscellaneous |
|
| 49 | - $this->miscellaneous = $this->client->getReceiver(Client::MISCELLANEOUS); |
|
| 50 | - |
|
| 51 | - // Emojis |
|
| 52 | - $this->emojis = $this->miscellaneous->getReceiver(Miscellaneous::EMOJIS); |
|
| 53 | - |
|
| 54 | - // GitIgnore |
|
| 55 | - $this->gitIgnore = $this->miscellaneous->getReceiver(Miscellaneous::GITIGNORE); |
|
| 56 | - |
|
| 57 | - // Licenses |
|
| 58 | - $this->licenses = $this->miscellaneous->getReceiver(Miscellaneous::LICENSES); |
|
| 59 | - |
|
| 60 | - // Markdown |
|
| 61 | - $this->markdown = $this->miscellaneous->getReceiver(Miscellaneous::MARKDOWN); |
|
| 62 | - |
|
| 63 | - // Meta |
|
| 64 | - $this->meta = $this->miscellaneous->getReceiver(Miscellaneous::META); |
|
| 65 | - |
|
| 66 | - // RateLimit |
|
| 67 | - $this->rateLimit = $this->miscellaneous->getReceiver(Miscellaneous::RATE_LIMIT); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Test list available Emojis |
|
| 72 | - */ |
|
| 73 | - public function testGetListEmojis() |
|
| 74 | - { |
|
| 75 | - $this->assertCount(1508, $this->emojis->get()); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Test listing available templates |
|
| 80 | - */ |
|
| 81 | - public function testListingAvailableTemplates() |
|
| 82 | - { |
|
| 83 | - $templates = $this->gitIgnore->listingAvailableTemplates(); |
|
| 84 | - |
|
| 85 | - $this->assertContains('Android', $templates); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Test getting a single template |
|
| 90 | - */ |
|
| 91 | - public function testGetSingleTemplate() |
|
| 92 | - { |
|
| 93 | - $template = $this->gitIgnore->getSingleTemplate('Android'); |
|
| 94 | - |
|
| 95 | - $this->assertArrayHasKey('name', $template); |
|
| 96 | - $this->assertArrayHasKey('source', $template); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Test listing all licenses |
|
| 101 | - */ |
|
| 102 | - public function testListAllLicenses() |
|
| 103 | - { |
|
| 104 | - $licenses = $this->licenses->listAllLicenses(); |
|
| 105 | - $license = array_pop($licenses); |
|
| 106 | - |
|
| 107 | - $this->assertArrayHasKey('key', $license); |
|
| 108 | - $this->assertArrayHasKey('name', $license); |
|
| 109 | - $this->assertArrayHasKey('spdx_id', $license); |
|
| 110 | - $this->assertArrayHasKey('url', $license); |
|
| 111 | - $this->assertArrayHasKey('featured', $license); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Test getting individual license |
|
| 116 | - */ |
|
| 117 | - public function testGettingIndividualLicense() |
|
| 118 | - { |
|
| 119 | - $license = $this->licenses->getIndividualLicense('mit'); |
|
| 120 | - |
|
| 121 | - $this->assertArrayHasKey('body', $license); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Test render markdown text |
|
| 126 | - */ |
|
| 127 | - public function testRender() |
|
| 128 | - { |
|
| 129 | - $output = $this->markdown->render('Hello world FlexyProject/GitHubAPI#43 **cool**, and #43!'); |
|
| 130 | - |
|
| 131 | - $this->assertEquals('<p>Hello world FlexyProject/GitHubAPI#43 <strong>cool</strong>, and #43!</p>', |
|
| 132 | - str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Test render markdown raw text |
|
| 137 | - */ |
|
| 138 | - public function testRenderRaw() |
|
| 139 | - { |
|
| 140 | - $output = $this->markdown->renderRaw('**cool**'); |
|
| 141 | - |
|
| 142 | - $this->assertEquals('<p>{"file":"<strong>cool</strong>"}</p>', |
|
| 143 | - str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Test getting meta about GitHub.com |
|
| 148 | - */ |
|
| 149 | - public function testGetMeta() |
|
| 150 | - { |
|
| 151 | - $meta = $this->meta->get(); |
|
| 152 | - |
|
| 153 | - $this->assertTrue($meta['verifiable_password_authentication']); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Test rate limit |
|
| 158 | - */ |
|
| 159 | - public function testRateLimit() |
|
| 160 | - { |
|
| 161 | - $rateLimit = $this->rateLimit->get(); |
|
| 162 | - |
|
| 163 | - $this->assertArrayHasKey('rate', $rateLimit); |
|
| 164 | - } |
|
| 16 | + /** @var Miscellaneous */ |
|
| 17 | + protected $miscellaneous; |
|
| 18 | + |
|
| 19 | + /** @var Miscellaneous\Emojis */ |
|
| 20 | + protected $emojis; |
|
| 21 | + |
|
| 22 | + /** @var Miscellaneous\Gitignore */ |
|
| 23 | + protected $gitIgnore; |
|
| 24 | + |
|
| 25 | + /** @var Miscellaneous\Licenses */ |
|
| 26 | + protected $licenses; |
|
| 27 | + |
|
| 28 | + /** @var Miscellaneous\Markdown */ |
|
| 29 | + protected $markdown; |
|
| 30 | + |
|
| 31 | + /** @var Miscellaneous\Meta */ |
|
| 32 | + protected $meta; |
|
| 33 | + |
|
| 34 | + /** @var Miscellaneous\RateLimit */ |
|
| 35 | + protected $rateLimit; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * MiscellaneousTest constructor. |
|
| 39 | + * |
|
| 40 | + * @param null $name |
|
| 41 | + * @param array $data |
|
| 42 | + * @param string $dataName |
|
| 43 | + */ |
|
| 44 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
| 45 | + { |
|
| 46 | + parent::__construct($name, $data, $dataName); |
|
| 47 | + |
|
| 48 | + // Miscellaneous |
|
| 49 | + $this->miscellaneous = $this->client->getReceiver(Client::MISCELLANEOUS); |
|
| 50 | + |
|
| 51 | + // Emojis |
|
| 52 | + $this->emojis = $this->miscellaneous->getReceiver(Miscellaneous::EMOJIS); |
|
| 53 | + |
|
| 54 | + // GitIgnore |
|
| 55 | + $this->gitIgnore = $this->miscellaneous->getReceiver(Miscellaneous::GITIGNORE); |
|
| 56 | + |
|
| 57 | + // Licenses |
|
| 58 | + $this->licenses = $this->miscellaneous->getReceiver(Miscellaneous::LICENSES); |
|
| 59 | + |
|
| 60 | + // Markdown |
|
| 61 | + $this->markdown = $this->miscellaneous->getReceiver(Miscellaneous::MARKDOWN); |
|
| 62 | + |
|
| 63 | + // Meta |
|
| 64 | + $this->meta = $this->miscellaneous->getReceiver(Miscellaneous::META); |
|
| 65 | + |
|
| 66 | + // RateLimit |
|
| 67 | + $this->rateLimit = $this->miscellaneous->getReceiver(Miscellaneous::RATE_LIMIT); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Test list available Emojis |
|
| 72 | + */ |
|
| 73 | + public function testGetListEmojis() |
|
| 74 | + { |
|
| 75 | + $this->assertCount(1508, $this->emojis->get()); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Test listing available templates |
|
| 80 | + */ |
|
| 81 | + public function testListingAvailableTemplates() |
|
| 82 | + { |
|
| 83 | + $templates = $this->gitIgnore->listingAvailableTemplates(); |
|
| 84 | + |
|
| 85 | + $this->assertContains('Android', $templates); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Test getting a single template |
|
| 90 | + */ |
|
| 91 | + public function testGetSingleTemplate() |
|
| 92 | + { |
|
| 93 | + $template = $this->gitIgnore->getSingleTemplate('Android'); |
|
| 94 | + |
|
| 95 | + $this->assertArrayHasKey('name', $template); |
|
| 96 | + $this->assertArrayHasKey('source', $template); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Test listing all licenses |
|
| 101 | + */ |
|
| 102 | + public function testListAllLicenses() |
|
| 103 | + { |
|
| 104 | + $licenses = $this->licenses->listAllLicenses(); |
|
| 105 | + $license = array_pop($licenses); |
|
| 106 | + |
|
| 107 | + $this->assertArrayHasKey('key', $license); |
|
| 108 | + $this->assertArrayHasKey('name', $license); |
|
| 109 | + $this->assertArrayHasKey('spdx_id', $license); |
|
| 110 | + $this->assertArrayHasKey('url', $license); |
|
| 111 | + $this->assertArrayHasKey('featured', $license); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Test getting individual license |
|
| 116 | + */ |
|
| 117 | + public function testGettingIndividualLicense() |
|
| 118 | + { |
|
| 119 | + $license = $this->licenses->getIndividualLicense('mit'); |
|
| 120 | + |
|
| 121 | + $this->assertArrayHasKey('body', $license); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Test render markdown text |
|
| 126 | + */ |
|
| 127 | + public function testRender() |
|
| 128 | + { |
|
| 129 | + $output = $this->markdown->render('Hello world FlexyProject/GitHubAPI#43 **cool**, and #43!'); |
|
| 130 | + |
|
| 131 | + $this->assertEquals('<p>Hello world FlexyProject/GitHubAPI#43 <strong>cool</strong>, and #43!</p>', |
|
| 132 | + str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Test render markdown raw text |
|
| 137 | + */ |
|
| 138 | + public function testRenderRaw() |
|
| 139 | + { |
|
| 140 | + $output = $this->markdown->renderRaw('**cool**'); |
|
| 141 | + |
|
| 142 | + $this->assertEquals('<p>{"file":"<strong>cool</strong>"}</p>', |
|
| 143 | + str_replace(["\r\n", "\r", "\n"], "", $output[0])); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Test getting meta about GitHub.com |
|
| 148 | + */ |
|
| 149 | + public function testGetMeta() |
|
| 150 | + { |
|
| 151 | + $meta = $this->meta->get(); |
|
| 152 | + |
|
| 153 | + $this->assertTrue($meta['verifiable_password_authentication']); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Test rate limit |
|
| 158 | + */ |
|
| 159 | + public function testRateLimit() |
|
| 160 | + { |
|
| 161 | + $rateLimit = $this->rateLimit->get(); |
|
| 162 | + |
|
| 163 | + $this->assertArrayHasKey('rate', $rateLimit); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | \ No newline at end of file |
@@ -11,24 +11,24 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | abstract class AbstractTest extends TestCase |
| 13 | 13 | { |
| 14 | - /** @var Client */ |
|
| 15 | - protected $client; |
|
| 14 | + /** @var Client */ |
|
| 15 | + protected $client; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * AbstractTest constructor. |
|
| 19 | - * |
|
| 20 | - * @param null $name |
|
| 21 | - * @param array $data |
|
| 22 | - * @param string $dataName |
|
| 23 | - */ |
|
| 24 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
| 25 | - { |
|
| 26 | - // Create a client object |
|
| 27 | - $this->client = new Client(); |
|
| 17 | + /** |
|
| 18 | + * AbstractTest constructor. |
|
| 19 | + * |
|
| 20 | + * @param null $name |
|
| 21 | + * @param array $data |
|
| 22 | + * @param string $dataName |
|
| 23 | + */ |
|
| 24 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
| 25 | + { |
|
| 26 | + // Create a client object |
|
| 27 | + $this->client = new Client(); |
|
| 28 | 28 | |
| 29 | - // Set auth credentials |
|
| 30 | - $this->client->setHttpAuth($GLOBALS['USERNAME'], $GLOBALS['PASSWORD']); |
|
| 29 | + // Set auth credentials |
|
| 30 | + $this->client->setHttpAuth($GLOBALS['USERNAME'], $GLOBALS['PASSWORD']); |
|
| 31 | 31 | |
| 32 | - parent::__construct($name, $data, $dataName); |
|
| 33 | - } |
|
| 32 | + parent::__construct($name, $data, $dataName); |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |