Repository navigation
Expand file tree
/
Copy pathSnippet.php
More file actions
100 lines (87 loc) · 2.19 KB
/
Copy pathSnippet.php
File metadata and controls
100 lines (87 loc) · 2.19 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php namespace Gitlab\Model;
use Gitlab\Client;
/**
* Class Snippet
*
* @property-read int $id
* @property-read string $title
* @property-read string $file_name
* @property-read string $expires_at
* @property-read string $updated_at
* @property-read string $created_at
* @property-read Project $project
* @property-read User $author
*/
class Snippet extends AbstractModel
{
/**
* @var array
*/
protected static $properties = array(
'id',
'title',
'file_name',
'author',
'expires_at',
'updated_at',
'created_at',
'project'
);
/**
* @param Client $client
* @param Project $project
* @param array $data
* @return Snippet
*/
public static function fromArray(Client $client, Project $project, array $data)
{
$snippet = new static($project, $data['id'], $client);
if (isset($data['author'])) {
$data['author'] = User::fromArray($client, $data['author']);
}
return $snippet->hydrate($data);
}
/**
* @param Project $project
* @param int $id
* @param Client $client
*/
public function __construct(Project $project, $id = null, Client $client = null)
{
$this->setClient($client);
$this->setData('project', $project);
$this->setData('id', $id);
}
/**
* @return Snippet
*/
public function show()
{
$data = $this->api('snippets')->show($this->project->id, $this->id);
return static::fromArray($this->getClient(), $this->project, $data);
}
/**
* @param array $params
* @return Snippet
*/
public function update(array $params)
{
$data = $this->api('snippets')->update($this->project->id, $this->id, $params);
return static::fromArray($this->getClient(), $this->project, $data);
}
/**
* @return string
*/
public function content()
{
return $this->api('snippets')->content($this->project->id, $this->id);
}
/**
* @return bool
*/
public function remove()
{
$this->api('snippets')->remove($this->project->id, $this->id);
return true;
}
}