1 | <?php |
||
17 | class GitDataCollector extends DataCollector |
||
18 | { |
||
19 | private $gitService; |
||
20 | |||
21 | /** |
||
22 | * @param $repositoryCommitUrl |
||
23 | */ |
||
24 | public function __construct(ContainerInterface $container) |
||
25 | { |
||
26 | $this->gitService = $container->get('debug.toolbar.git'); |
||
27 | $this->data['repositoryCommitUrl'] = $container->getParameter( |
||
28 | 'symfony_debug_toolbar_git.repository_commit_url' |
||
29 | ); |
||
30 | $this->data['gitData'] = true; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Collect Git data for DebugBar (branch,commit,author,email,merge,date,message) |
||
35 | * @param Request $request |
||
36 | * @param Response $response |
||
37 | * @param \Exception $exception |
||
38 | */ |
||
39 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
40 | { |
||
41 | |||
42 | if (!file_exists($this->gitService->getGitDir())) { |
||
43 | $this->data['gitData'] = false; |
||
44 | return; |
||
45 | } |
||
46 | $this->data['gitDir'] = $this->gitService->getGitDir(); |
||
47 | $this->data['branch'] = $this->gitService->shellExec(GitCommand::GIT_CURRENT_BRANCH); |
||
48 | $this->data['commit'] = $this->gitService->shellExec(GitCommand::GIT_HASH_LAST_COMMIT); |
||
49 | $this->data['author'] = $this->gitService->shellExec(GitCommand::GIT_AUTHOR_LAST_COMMIT); |
||
50 | $this->data['email'] = $this->gitService->shellExec(GitCommand::GIT_EMAIL_LAST_COMMIT); |
||
51 | $this->data['message'] = $this->gitService->shellExec(GitCommand::GIT_MESSAGE_LAST_COMMIT); |
||
52 | $this->data['merge'] = $this->gitService->shellExec( |
||
53 | GitCommand::GIT_ABBREVIATED_PARENT_HASHES.$this->data['commit'] |
||
54 | ); |
||
55 | $this->getDateCommit(); |
||
56 | dump($this->data); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * true if there is some data : used by the view |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getGitData() |
||
64 | { |
||
65 | return $this->getData('gitData'); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Actual branch name |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getBranch() |
||
76 | |||
77 | /** |
||
78 | * Commit ID |
||
79 | * @return string |
||
80 | */ |
||
81 | public function getCommit() |
||
85 | |||
86 | /** |
||
87 | * Merge information |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getMerge() |
||
94 | |||
95 | /** |
||
96 | * Merge information |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getGitDIr() |
||
103 | |||
104 | /** |
||
105 | * Author |
||
106 | * @return string |
||
107 | */ |
||
108 | public function getAuthor() |
||
112 | |||
113 | /** |
||
114 | * Author's email |
||
115 | * @return string |
||
116 | */ |
||
117 | public function getEmail() |
||
121 | |||
122 | /** |
||
123 | * Commit date |
||
124 | * @return string |
||
125 | */ |
||
126 | public function getDate() |
||
130 | |||
131 | /** |
||
132 | * Minutes since last commit |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getTimeCommitIntervalMinutes() |
||
139 | |||
140 | /** |
||
141 | * Seconds since latest commit |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getTimeCommitIntervalSeconds() |
||
148 | |||
149 | /** |
||
150 | * Commit message |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getMessage() |
||
157 | |||
158 | /** |
||
159 | * Commit URL |
||
160 | * @return string |
||
161 | */ |
||
162 | public function getCommitUrl() |
||
166 | |||
167 | /** |
||
168 | * Checks and returns the data |
||
169 | * @param string $data |
||
170 | * @return string |
||
171 | */ |
||
172 | private function getData($data) |
||
177 | |||
178 | /** |
||
179 | * DataCollector name : used by service declaration into container.yml |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getName() |
||
186 | |||
187 | /** |
||
188 | * Change icons color according to the version of symfony |
||
189 | * #3f3f3f < 2.8 |
||
190 | * #AAAAAA >= 2.8 |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getIconColor() |
||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | private function getSymfonyVersion() |
||
213 | |||
214 | private function verifyExistMergeInCommit() |
||
222 | |||
223 | private function getDateCommit() |
||
241 | } |
||
242 | |||
243 |