Skip to content

Commit d72b10c

Browse files
author
Luc Morin
committed
feat(wiki support): Created the api and models for the Wiki endpoint for the gitlab API.
References #335
1 parent d6e7539 commit d72b10c

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

lib/Gitlab/Api/Wiki.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class Wiki extends AbstractApi
4+
{
5+
6+
/**
7+
* @param int $project_id
8+
* @param array $params
9+
* @return mixed
10+
*/
11+
public function create($project_id, array $params)
12+
{
13+
return $this->post($this->getProjectPath($project_id, 'wikis'), $params);
14+
}
15+
16+
/**
17+
* @param int $project_id
18+
* @param int $wiki_slug
19+
* @return mixed
20+
*/
21+
public function show($project_id, $wiki_slug)
22+
{
23+
return $this->get($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)));
24+
}
25+
26+
/**
27+
* @param int $project_id
28+
* @return mixed
29+
*/
30+
public function showAll($project_id)
31+
{
32+
return $this->get($this->getProjectPath($project_id, 'wikis'));
33+
}
34+
35+
/**
36+
* @param int $project_id
37+
* @param array $params
38+
* @return mixed
39+
*/
40+
public function update($project_id, $wiki_slug, array $params)
41+
{
42+
return $this->put($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)), $params);
43+
}
44+
45+
/**
46+
* @param int $project_id
47+
* @param int $wiki_slug
48+
* @return mixed
49+
*/
50+
public function remove($project_id, $wiki_slug)
51+
{
52+
return $this->delete($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)));
53+
}
54+
}

lib/Gitlab/Client.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ public function schedules()
305305
return new Api\Schedules($this);
306306
}
307307

308+
/**
309+
* @return Api\Wiki
310+
*/
311+
public function wiki()
312+
{
313+
return new Api\Wiki($this);
314+
}
315+
308316
/**
309317
* @param string $name
310318
*
@@ -390,6 +398,9 @@ public function api($name)
390398
case 'schedules':
391399
return $this->schedules();
392400

401+
case 'wiki':
402+
return $this->wiki();
403+
393404
default:
394405
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');
395406
}

lib/Gitlab/Model/Wiki.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Gitlab\Model;
4+
5+
use Gitlab\Client;
6+
7+
/**
8+
* Class Wiki
9+
*
10+
* @property-read string $slug
11+
* @property-read string $title
12+
* @property-read string $format
13+
* @property-read string $content
14+
* @property-read Project $project
15+
*/
16+
class Wiki extends AbstractModel
17+
{
18+
/**
19+
* @var array
20+
*/
21+
protected static $properties = array(
22+
"slug",
23+
"title",
24+
"format",
25+
"content",
26+
);
27+
28+
/**
29+
* @param Client $client
30+
* @param Project $project
31+
* @param array $data
32+
* @return Wiki
33+
*/
34+
public static function fromArray(Client $client, Project $project, array $data)
35+
{
36+
$wiki = new static($project, $data['id'], $client);
37+
38+
return $wiki->hydrate($data);
39+
}
40+
41+
/**
42+
* @param Project $project
43+
* @param int $id
44+
* @param Client $client
45+
*/
46+
public function __construct(Project $project, $id = null, Client $client = null)
47+
{
48+
$this->setClient($client);
49+
$this->setData('project', $project);
50+
$this->setData('id', $id);
51+
}
52+
53+
/**
54+
* @return Wiki
55+
*/
56+
public function show()
57+
{
58+
$data = $this->client->wiki()->show($this->project->id, $this->id);
59+
60+
return static::fromArray($this->getClient(), $this->project, $data);
61+
}
62+
63+
/**
64+
* @param array $params
65+
* @return Schedule
66+
*/
67+
public function update(array $params)
68+
{
69+
$data = $this->client->wiki()->update($this->project->id, $this->id, $params);
70+
71+
return static::fromArray($this->getClient(), $this->project, $data);
72+
}
73+
}

0 commit comments

Comments
 (0)