Created
January 2, 2018 23:29
-
-
Save lloc/cb0134ef067179e53f8b4323d9a9ad1c to your computer and use it in GitHub Desktop.
Class of the changelog.php post
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 lloc\changelog; | |
class Logs { | |
/** | |
* @var array | |
*/ | |
protected $logs = []; | |
/** | |
* Add changes to your logs | |
* | |
* @param array $arr | |
* | |
* @return $this | |
*/ | |
public function add( array $arr ) { | |
foreach ( $arr as $line ) { | |
$parts = explode( ' ', $line, 2 ); | |
if ( isset( $parts[1] ) && preg_match( '#([a-z]+)\((.+)\): (.+)#', $parts[1], $matches ) ) { | |
$this->logs[ $matches[1] ][] = sprintf( '**%s:** %s', $matches[2], $matches[3] ); | |
} | |
} | |
return $this; | |
} | |
public function get( $type, $header ) { | |
if ( ! isset( $this->logs[ $type ] ) ) { | |
return ''; | |
} | |
$logs = array_unique( $this->logs[ $type ] ); | |
sort( $logs ); | |
$str = '### ' . $header . PHP_EOL . PHP_EOL; | |
foreach( $logs as $log ) { | |
$str .= "* {$log}" . PHP_EOL; | |
} | |
return $str . PHP_EOL . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment