Skip to content

Instantly share code, notes, and snippets.

@lloc
Last active January 2, 2018 23:35
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/1789d00d22f4003c5421bd89ba2097ad to your computer and use it in GitHub Desktop.
Save lloc/1789d00d22f4003c5421bd89ba2097ad to your computer and use it in GitHub Desktop.
Class of the changelog.php post
<?php
namespace lloc\changelog;
/**
* Class Tags
* @package lloc\changelog
*/
class Tags {
/**
* @var array
*/
protected $tags = [];
/**
* @param array $arr
* @param string $delimiter
*/
public function __construct( array $arr, $delimiter = '|' ) {
foreach ( $arr as $line ) {
$this->tags[] = explode( $delimiter, $line );
}
}
/**
* @param int $index
*
* @return mixed
*/
public function get_name( $index = 0 ) {
return $this->tags[ $index ][1];
}
/**
* @param int $index
* @param string $format
*
* @return string
*/
public function get_date( $index = 0, $format = 'Y-m-d' ) {
$date = new \DateTime( $this->tags[ $index ][0] );
return $date->format( $format );
}
/**
* @return string
*/
public function get_title() {
$title = sprintf( '## %s (%s)', $this->get_name( 1 ), $this->get_date() );
return $title . PHP_EOL . PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment