Created
April 6, 2016 15:32
-
-
Save YOzaz/a768fb955ef5ccd9aca35ae58f3368ad to your computer and use it in GitHub Desktop.
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 | |
use Laracasts\Presenter\Presenter; | |
abstract class AbstractPresenter extends Presenter | |
{ | |
/** | |
* @param \Carbon\Carbon $date | |
* | |
* @return string | |
*/ | |
public function niceTime( $date = null ) | |
{ | |
if ( isset($date) ) | |
{ | |
return $date->toTimeString(); | |
} | |
else | |
{ | |
return ''; | |
} | |
} | |
/** | |
* @param \Carbon\Carbon $date | |
* | |
* @return string | |
*/ | |
public function niceDate( $date = null ) | |
{ | |
if ( isset($date) ) | |
{ | |
return $date->toFormattedDateString(); | |
} | |
else | |
{ | |
return ''; | |
} | |
} | |
/** | |
* @param int|float $number | |
* | |
* @return string | |
*/ | |
public function niceNumber( $number = 0 ) | |
{ | |
return number_format( $number, 0, '.', ',' ); | |
} | |
/** | |
* @param int|float $number | |
* | |
* @return string | |
*/ | |
public function nicePercentage( $number = 0 ) | |
{ | |
return number_format( $number*100, 2, '.', ',' ) . '%'; | |
} | |
/** | |
* @param string $format | |
* @param array|string $arguments | |
* | |
* @return string | |
*/ | |
public function formattedString( $format = '', $arguments = [] ) | |
{ | |
$arguments = is_array( $arguments ) ? $arguments : [ $arguments ]; | |
array_unshift( $arguments, $format ); | |
return call_user_func_array( 'sprintf', $arguments ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment