Last active
July 26, 2017 07:20
-
-
Save aarsla/0574f28eaa06273058e0e0f253397e90 to your computer and use it in GitHub Desktop.
Twig Filter - git commit/branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Twig\Extension; | |
class GitExtension extends \Twig_Extension | |
{ | |
public function getFilters() | |
{ | |
return array( | |
new \Twig_SimpleFilter('gitVersion', array($this, 'showCustomGitVersion')), | |
); | |
} | |
/** | |
* Get current git version | |
*/ | |
public function showCustomGitVersion() | |
{ | |
$hash = exec('git rev-parse --short HEAD'); | |
$branch = exec('git rev-parse --abbrev-ref HEAD'); | |
$tag = exec('git describe'); | |
return $tag. ' ' . $hash . ' on '.$branch; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getName() | |
{ | |
return 'twig_git'; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: version: {{ ''|showCustomGitVersion() }}