Skip to content

Instantly share code, notes, and snippets.

@lloc
Created January 2, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloc/cb0134ef067179e53f8b4323d9a9ad1c to your computer and use it in GitHub Desktop.
Save lloc/cb0134ef067179e53f8b4323d9a9ad1c to your computer and use it in GitHub Desktop.
Class of the changelog.php post
<?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