@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Kendrick\SymfonyDebugToolbarGit\DataCollector; |
| 4 | 4 | |
| 5 | 5 | use Kendrick\SymfonyDebugToolbarGit\Git\Git; |
| 6 | -use Kendrick\SymfonyDebugToolbarGit\Git\GitLastCommit; |
|
| 7 | 6 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 8 | 7 | use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
| 9 | 8 | use Symfony\Component\HttpFoundation\Request; |
@@ -16,238 +16,238 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class GitDataCollector extends DataCollector |
| 18 | 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('symfony_debug_toolbar_git.repository_commit_url'); |
|
| 28 | - $this->data['gitData'] = true; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Collect Git data for DebugBar (branch,commit,author,email,merge,date,message) |
|
| 33 | - * |
|
| 34 | - * @param Request $request |
|
| 35 | - * @param Response $response |
|
| 36 | - * @param \Exception $exception |
|
| 37 | - */ |
|
| 38 | - public function collect(Request $request, Response $response, \Exception $exception = null) |
|
| 39 | - { |
|
| 40 | - if (!$this->gitService->GitDirExist()) { |
|
| 41 | - |
|
| 42 | - $this->data['gitData'] = false; |
|
| 43 | - $this->data['gitDir'] = $this->gitService->getGitDirInConfiguration(); |
|
| 44 | - |
|
| 45 | - return; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - $this->data['branch'] = $this->gitService->shellExec(GitCommand::GIT_CURRENT_BRANCH); |
|
| 49 | - $this->data['commit'] = $this->gitService->shellExec(GitCommand::GIT_HASH_LAST_COMMIT); |
|
| 50 | - $this->data['author'] = $this->gitService->shellExec(GitCommand::GIT_AUTHOR_LAST_COMMIT); |
|
| 51 | - $this->data['email'] = $this->gitService->shellExec(GitCommand::GIT_EMAIL_LAST_COMMIT); |
|
| 52 | - $this->data['message'] = $this->gitService->shellExec(GitCommand::GIT_MESSAGE_LAST_COMMIT); |
|
| 53 | - $this->data['merge'] = $this->gitService->shellExec(GitCommand::GIT_ABBREVIATED_PARENT_HASHES. $this->data['commit']); |
|
| 54 | - $this->getDateCommit(); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * true if there is some data : used by the view |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function getGitData() |
|
| 63 | - { |
|
| 64 | - return $this->getData('gitData'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Actual branch name |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function getBranch() |
|
| 73 | - { |
|
| 74 | - return $this->getData('branch'); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Commit ID |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getCommit() |
|
| 83 | - { |
|
| 84 | - return $this->getData('commit'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Merge information |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function getMerge() |
|
| 93 | - { |
|
| 94 | - return $this->getData('merge'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Merge information |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function getGitDIr() |
|
| 103 | - { |
|
| 104 | - return $this->getData('gitDir'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Author |
|
| 109 | - * |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function getAuthor() |
|
| 113 | - { |
|
| 114 | - return $this->getData('author'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Author's email |
|
| 119 | - * |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public function getEmail() |
|
| 123 | - { |
|
| 124 | - return $this->getData('email'); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Commit date |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function getDate() |
|
| 133 | - { |
|
| 134 | - return $this->getData('date'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Minutes since last commit |
|
| 139 | - * |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function getTimeCommitIntervalMinutes() |
|
| 143 | - { |
|
| 144 | - return $this->getData('timeCommitIntervalMinutes'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Seconds since latest commit |
|
| 149 | - * |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function getTimeCommitIntervalSeconds() |
|
| 153 | - { |
|
| 154 | - return $this->getData('timeCommitIntervalSeconds'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Commit message |
|
| 159 | - * |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function getMessage() |
|
| 163 | - { |
|
| 164 | - return $this->getData('message'); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Commit URL |
|
| 169 | - * |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - public function getCommitUrl() |
|
| 173 | - { |
|
| 174 | - return $this->data['repositoryCommitUrl']; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Checks and returns the data |
|
| 179 | - * |
|
| 180 | - * @param string $data |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - private function getData($data) |
|
| 184 | - { |
|
| 185 | - return (isset($this->data[$data])) ? $this->data[$data] : ''; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * DataCollector name : used by service declaration into container.yml |
|
| 190 | - * |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public function getName() |
|
| 194 | - { |
|
| 195 | - return 'datacollector_git'; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Change icons color according to the version of symfony |
|
| 200 | - * |
|
| 201 | - * #3f3f3f < 2.8 |
|
| 202 | - * #AAAAAA >= 2.8 |
|
| 203 | - * |
|
| 204 | - * @return string |
|
| 205 | - */ |
|
| 206 | - public final function getIconColor() |
|
| 207 | - { |
|
| 208 | - if ((float)$this->getSymfonyVersion() >= 2.8) { |
|
| 209 | - return $this->data['iconColor'] = '#AAAAAA'; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - return $this->data['iconColor'] = '#3F3F3F';#3F3F3F |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - private function getSymfonyVersion() |
|
| 219 | - { |
|
| 220 | - $symfonyVersion = \Symfony\Component\HttpKernel\Kernel::VERSION; |
|
| 221 | - $symfonyVersion = explode('.', $symfonyVersion, -1); |
|
| 222 | - $symfonyMajorMinorVersion = implode('.', $symfonyVersion); |
|
| 223 | - |
|
| 224 | - return $symfonyMajorMinorVersion; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - private function verifyExistMergeInCommit() |
|
| 228 | - { |
|
| 229 | - $lastCommit = $this->gitService->exec(GitCommand::GIT_LOG_MINUS_ONE); |
|
| 230 | - if (strpos($lastCommit, 'Merge') === 0) { |
|
| 231 | - // merge information |
|
| 232 | - $this->data['merge'] = trim(substr($lastCommit, 6)); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - private function getDateCommit() |
|
| 237 | - { |
|
| 238 | - $date = $this->gitService->shellExec(GitCommand::GIT_COMMIT_DATE); |
|
| 239 | - $dateCommit = date_create($date); |
|
| 240 | - |
|
| 241 | - // actual date at runtime |
|
| 242 | - $dateRuntime = new \DateTime(); |
|
| 243 | - $dateNow = date_create($dateRuntime->format('Y-m-d H:i:s')); |
|
| 244 | - // difference |
|
| 245 | - $time = date_diff($dateCommit, $dateNow); |
|
| 246 | - |
|
| 247 | - // static time difference : minutes and seconds |
|
| 248 | - $this->data['timeCommitIntervalMinutes'] = $time->format('%y') * 365 * 24 * 60 + $time->format('%m') * 30 * 24 * 60 + $time->format('%d') * 24 * 60 + $time->format('%h') * 60 + $time->format('%i'); |
|
| 249 | - // full readable date |
|
| 250 | - $this->data['date'] = $date; |
|
| 251 | - } |
|
| 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('symfony_debug_toolbar_git.repository_commit_url'); |
|
| 28 | + $this->data['gitData'] = true; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Collect Git data for DebugBar (branch,commit,author,email,merge,date,message) |
|
| 33 | + * |
|
| 34 | + * @param Request $request |
|
| 35 | + * @param Response $response |
|
| 36 | + * @param \Exception $exception |
|
| 37 | + */ |
|
| 38 | + public function collect(Request $request, Response $response, \Exception $exception = null) |
|
| 39 | + { |
|
| 40 | + if (!$this->gitService->GitDirExist()) { |
|
| 41 | + |
|
| 42 | + $this->data['gitData'] = false; |
|
| 43 | + $this->data['gitDir'] = $this->gitService->getGitDirInConfiguration(); |
|
| 44 | + |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + $this->data['branch'] = $this->gitService->shellExec(GitCommand::GIT_CURRENT_BRANCH); |
|
| 49 | + $this->data['commit'] = $this->gitService->shellExec(GitCommand::GIT_HASH_LAST_COMMIT); |
|
| 50 | + $this->data['author'] = $this->gitService->shellExec(GitCommand::GIT_AUTHOR_LAST_COMMIT); |
|
| 51 | + $this->data['email'] = $this->gitService->shellExec(GitCommand::GIT_EMAIL_LAST_COMMIT); |
|
| 52 | + $this->data['message'] = $this->gitService->shellExec(GitCommand::GIT_MESSAGE_LAST_COMMIT); |
|
| 53 | + $this->data['merge'] = $this->gitService->shellExec(GitCommand::GIT_ABBREVIATED_PARENT_HASHES. $this->data['commit']); |
|
| 54 | + $this->getDateCommit(); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * true if there is some data : used by the view |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function getGitData() |
|
| 63 | + { |
|
| 64 | + return $this->getData('gitData'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Actual branch name |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function getBranch() |
|
| 73 | + { |
|
| 74 | + return $this->getData('branch'); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Commit ID |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getCommit() |
|
| 83 | + { |
|
| 84 | + return $this->getData('commit'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Merge information |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function getMerge() |
|
| 93 | + { |
|
| 94 | + return $this->getData('merge'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Merge information |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function getGitDIr() |
|
| 103 | + { |
|
| 104 | + return $this->getData('gitDir'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Author |
|
| 109 | + * |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function getAuthor() |
|
| 113 | + { |
|
| 114 | + return $this->getData('author'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Author's email |
|
| 119 | + * |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public function getEmail() |
|
| 123 | + { |
|
| 124 | + return $this->getData('email'); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Commit date |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function getDate() |
|
| 133 | + { |
|
| 134 | + return $this->getData('date'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Minutes since last commit |
|
| 139 | + * |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function getTimeCommitIntervalMinutes() |
|
| 143 | + { |
|
| 144 | + return $this->getData('timeCommitIntervalMinutes'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Seconds since latest commit |
|
| 149 | + * |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function getTimeCommitIntervalSeconds() |
|
| 153 | + { |
|
| 154 | + return $this->getData('timeCommitIntervalSeconds'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Commit message |
|
| 159 | + * |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function getMessage() |
|
| 163 | + { |
|
| 164 | + return $this->getData('message'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Commit URL |
|
| 169 | + * |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + public function getCommitUrl() |
|
| 173 | + { |
|
| 174 | + return $this->data['repositoryCommitUrl']; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Checks and returns the data |
|
| 179 | + * |
|
| 180 | + * @param string $data |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + private function getData($data) |
|
| 184 | + { |
|
| 185 | + return (isset($this->data[$data])) ? $this->data[$data] : ''; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * DataCollector name : used by service declaration into container.yml |
|
| 190 | + * |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public function getName() |
|
| 194 | + { |
|
| 195 | + return 'datacollector_git'; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Change icons color according to the version of symfony |
|
| 200 | + * |
|
| 201 | + * #3f3f3f < 2.8 |
|
| 202 | + * #AAAAAA >= 2.8 |
|
| 203 | + * |
|
| 204 | + * @return string |
|
| 205 | + */ |
|
| 206 | + public final function getIconColor() |
|
| 207 | + { |
|
| 208 | + if ((float)$this->getSymfonyVersion() >= 2.8) { |
|
| 209 | + return $this->data['iconColor'] = '#AAAAAA'; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + return $this->data['iconColor'] = '#3F3F3F';#3F3F3F |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + private function getSymfonyVersion() |
|
| 219 | + { |
|
| 220 | + $symfonyVersion = \Symfony\Component\HttpKernel\Kernel::VERSION; |
|
| 221 | + $symfonyVersion = explode('.', $symfonyVersion, -1); |
|
| 222 | + $symfonyMajorMinorVersion = implode('.', $symfonyVersion); |
|
| 223 | + |
|
| 224 | + return $symfonyMajorMinorVersion; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + private function verifyExistMergeInCommit() |
|
| 228 | + { |
|
| 229 | + $lastCommit = $this->gitService->exec(GitCommand::GIT_LOG_MINUS_ONE); |
|
| 230 | + if (strpos($lastCommit, 'Merge') === 0) { |
|
| 231 | + // merge information |
|
| 232 | + $this->data['merge'] = trim(substr($lastCommit, 6)); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + private function getDateCommit() |
|
| 237 | + { |
|
| 238 | + $date = $this->gitService->shellExec(GitCommand::GIT_COMMIT_DATE); |
|
| 239 | + $dateCommit = date_create($date); |
|
| 240 | + |
|
| 241 | + // actual date at runtime |
|
| 242 | + $dateRuntime = new \DateTime(); |
|
| 243 | + $dateNow = date_create($dateRuntime->format('Y-m-d H:i:s')); |
|
| 244 | + // difference |
|
| 245 | + $time = date_diff($dateCommit, $dateNow); |
|
| 246 | + |
|
| 247 | + // static time difference : minutes and seconds |
|
| 248 | + $this->data['timeCommitIntervalMinutes'] = $time->format('%y') * 365 * 24 * 60 + $time->format('%m') * 30 * 24 * 60 + $time->format('%d') * 24 * 60 + $time->format('%h') * 60 + $time->format('%i'); |
|
| 249 | + // full readable date |
|
| 250 | + $this->data['date'] = $date; |
|
| 251 | + } |
|
| 252 | 252 | } |
| 253 | 253 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $this->data['author'] = $this->gitService->shellExec(GitCommand::GIT_AUTHOR_LAST_COMMIT); |
| 51 | 51 | $this->data['email'] = $this->gitService->shellExec(GitCommand::GIT_EMAIL_LAST_COMMIT); |
| 52 | 52 | $this->data['message'] = $this->gitService->shellExec(GitCommand::GIT_MESSAGE_LAST_COMMIT); |
| 53 | - $this->data['merge'] = $this->gitService->shellExec(GitCommand::GIT_ABBREVIATED_PARENT_HASHES. $this->data['commit']); |
|
| 53 | + $this->data['merge'] = $this->gitService->shellExec(GitCommand::GIT_ABBREVIATED_PARENT_HASHES.$this->data['commit']); |
|
| 54 | 54 | $this->getDateCommit(); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public final function getIconColor() |
| 207 | 207 | { |
| 208 | - if ((float)$this->getSymfonyVersion() >= 2.8) { |
|
| 208 | + if ((float) $this->getSymfonyVersion() >= 2.8) { |
|
| 209 | 209 | return $this->data['iconColor'] = '#AAAAAA'; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - return $this->data['iconColor'] = '#3F3F3F';#3F3F3F |
|
| 212 | + return $this->data['iconColor'] = '#3F3F3F'; #3F3F3F |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | $time = date_diff($dateCommit, $dateNow); |
| 246 | 246 | |
| 247 | 247 | // static time difference : minutes and seconds |
| 248 | - $this->data['timeCommitIntervalMinutes'] = $time->format('%y') * 365 * 24 * 60 + $time->format('%m') * 30 * 24 * 60 + $time->format('%d') * 24 * 60 + $time->format('%h') * 60 + $time->format('%i'); |
|
| 248 | + $this->data['timeCommitIntervalMinutes'] = $time->format('%y')*365*24*60+$time->format('%m')*30*24*60+$time->format('%d')*24*60+$time->format('%h')*60+$time->format('%i'); |
|
| 249 | 249 | // full readable date |
| 250 | 250 | $this->data['date'] = $date; |
| 251 | 251 | } |
@@ -4,57 +4,57 @@ |
||
| 4 | 4 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 5 | 5 | class Git |
| 6 | 6 | { |
| 7 | - protected $container; |
|
| 8 | - |
|
| 9 | - public function __construct(ContainerInterface $container) |
|
| 10 | - { |
|
| 11 | - $this->container = $container; |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * |
|
| 16 | - * @return string The Git direcotry especificated in config_dev |
|
| 17 | - */ |
|
| 18 | - public function getGitDirInConfiguration() |
|
| 19 | - { |
|
| 20 | - $gitDir = $this->container->getParameter('symfony_debug_toolbar_git.repository_local_dir') . '/.git'; |
|
| 21 | - return $gitDir; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * verifies that the directory exists |
|
| 26 | - * @return bool |
|
| 27 | - */ |
|
| 28 | - public function GitDirExist() |
|
| 29 | - { |
|
| 30 | - $gitDir = $this->container->get('kernel')->getRootDir() . "/.."; |
|
| 31 | - $gitDir .= $this->getGitDirInConfiguration(); |
|
| 32 | - |
|
| 33 | - return file_exists($gitDir); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param $command |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public final function shellExec($command) |
|
| 41 | - { |
|
| 42 | - $command = sprintf('cd %s && %s', $this->GitDirExist(), $command); |
|
| 43 | - $resultCommand = shell_exec($command); |
|
| 44 | - |
|
| 45 | - return (string)trim($resultCommand); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param $command |
|
| 50 | - * @return array |
|
| 51 | - */ |
|
| 52 | - public final function exec($command) |
|
| 53 | - { |
|
| 54 | - $command = sprintf('cd %s && %s', $this->GitDirExist(), $command); |
|
| 55 | - exec($command, $resultCommand); |
|
| 56 | - |
|
| 57 | - return $resultCommand; |
|
| 58 | - } |
|
| 7 | + protected $container; |
|
| 8 | + |
|
| 9 | + public function __construct(ContainerInterface $container) |
|
| 10 | + { |
|
| 11 | + $this->container = $container; |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * |
|
| 16 | + * @return string The Git direcotry especificated in config_dev |
|
| 17 | + */ |
|
| 18 | + public function getGitDirInConfiguration() |
|
| 19 | + { |
|
| 20 | + $gitDir = $this->container->getParameter('symfony_debug_toolbar_git.repository_local_dir') . '/.git'; |
|
| 21 | + return $gitDir; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * verifies that the directory exists |
|
| 26 | + * @return bool |
|
| 27 | + */ |
|
| 28 | + public function GitDirExist() |
|
| 29 | + { |
|
| 30 | + $gitDir = $this->container->get('kernel')->getRootDir() . "/.."; |
|
| 31 | + $gitDir .= $this->getGitDirInConfiguration(); |
|
| 32 | + |
|
| 33 | + return file_exists($gitDir); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param $command |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public final function shellExec($command) |
|
| 41 | + { |
|
| 42 | + $command = sprintf('cd %s && %s', $this->GitDirExist(), $command); |
|
| 43 | + $resultCommand = shell_exec($command); |
|
| 44 | + |
|
| 45 | + return (string)trim($resultCommand); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param $command |
|
| 50 | + * @return array |
|
| 51 | + */ |
|
| 52 | + public final function exec($command) |
|
| 53 | + { |
|
| 54 | + $command = sprintf('cd %s && %s', $this->GitDirExist(), $command); |
|
| 55 | + exec($command, $resultCommand); |
|
| 56 | + |
|
| 57 | + return $resultCommand; |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | 60 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | public function getGitDirInConfiguration() |
| 19 | 19 | { |
| 20 | - $gitDir = $this->container->getParameter('symfony_debug_toolbar_git.repository_local_dir') . '/.git'; |
|
| 20 | + $gitDir = $this->container->getParameter('symfony_debug_toolbar_git.repository_local_dir').'/.git'; |
|
| 21 | 21 | return $gitDir; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function GitDirExist() |
| 29 | 29 | { |
| 30 | - $gitDir = $this->container->get('kernel')->getRootDir() . "/.."; |
|
| 30 | + $gitDir = $this->container->get('kernel')->getRootDir()."/.."; |
|
| 31 | 31 | $gitDir .= $this->getGitDirInConfiguration(); |
| 32 | 32 | |
| 33 | 33 | return file_exists($gitDir); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $command = sprintf('cd %s && %s', $this->GitDirExist(), $command); |
| 43 | 43 | $resultCommand = shell_exec($command); |
| 44 | 44 | |
| 45 | - return (string)trim($resultCommand); |
|
| 45 | + return (string) trim($resultCommand); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -2,16 +2,16 @@ |
||
| 2 | 2 | namespace Kendrick\SymfonyDebugToolbarGit\Git; |
| 3 | 3 | interface GitCommand |
| 4 | 4 | { |
| 5 | - const GIT_LOG_MINUS_ONE = "git log -1 "; |
|
| 6 | - const GIT_STATUS = "git status "; |
|
| 7 | - const GIT_CURRENT_BRANCH = "git rev-parse --abbrev-ref HEAD "; |
|
| 8 | - const GIT_COMMIT_COUNT_HEAD = "git rev-list --count HEAD"; |
|
| 9 | - //log last commit |
|
| 10 | - const GIT_EMAIL_LAST_COMMIT = "git log -1 --pretty=format:'%cn' "; |
|
| 11 | - const GIT_AUTHOR_LAST_COMMIT = "git log -1 --pretty=format:'%ce' "; |
|
| 12 | - const GIT_HASH_LAST_COMMIT = "git log -1 --pretty=format:' %H' "; |
|
| 13 | - const GIT_MESSAGE_LAST_COMMIT = "git log -1 --pretty=format:' %s' "; |
|
| 14 | - const GIT_ABBREVIATED_PARENT_HASHES = "git log -1 --pretty=%p "; |
|
| 15 | - const GIT_COMMIT_DATE = "git log -1 --pretty=format:'%ad' "; |
|
| 5 | + const GIT_LOG_MINUS_ONE = "git log -1 "; |
|
| 6 | + const GIT_STATUS = "git status "; |
|
| 7 | + const GIT_CURRENT_BRANCH = "git rev-parse --abbrev-ref HEAD "; |
|
| 8 | + const GIT_COMMIT_COUNT_HEAD = "git rev-list --count HEAD"; |
|
| 9 | + //log last commit |
|
| 10 | + const GIT_EMAIL_LAST_COMMIT = "git log -1 --pretty=format:'%cn' "; |
|
| 11 | + const GIT_AUTHOR_LAST_COMMIT = "git log -1 --pretty=format:'%ce' "; |
|
| 12 | + const GIT_HASH_LAST_COMMIT = "git log -1 --pretty=format:' %H' "; |
|
| 13 | + const GIT_MESSAGE_LAST_COMMIT = "git log -1 --pretty=format:' %s' "; |
|
| 14 | + const GIT_ABBREVIATED_PARENT_HASHES = "git log -1 --pretty=%p "; |
|
| 15 | + const GIT_COMMIT_DATE = "git log -1 --pretty=format:'%ad' "; |
|
| 16 | 16 | |
| 17 | 17 | } |
| 18 | 18 | \ No newline at end of file |