Skip to content
Browse files

Added new Time class. Controller Protected/Private methods are now hi…

…dden.
  • Loading branch information...
1 parent cebcb34 commit 91c8091e5b86efa9e4681d9c0a86261fe5342f5c @Xeoncross Xeoncross committed
Showing with 12 additions and 1 deletion.
  1. +11 −0 classes/time.php
  2. +1 −1 index.php
View
11 classes/time.php
@@ -0,0 +1,11 @@
+<?php
+// Extends the DateTime class to make it easier to caculate time differences and display human-readable representations
+class Time extends DateTime
+{
+function __construct($time='NOW',DateTimeZone$timezone=NULL){if(is_int($time)||ctype_digit($time))$time="@$time";if(is_array($time))$time=self::fromArray($time);if($timezone)parent::__construct($time,$timezone);else parent::__construct($time);}
+function diff($now='NOW',$absolute=FALSE){if(!($now instanceOf DateTime))$now=new Time($now);return parent::diff($now,$absolute);}
+function getSQL(){return $this->format('Y-m-d H:i:s');}
+function difference($d='NOW',$l=1){$d=$this->diff($d);$u=array('y'=>'year','m'=>'month','d'=>'day','h'=>'hour','i'=>'minute','s'=>'second');$r=array();foreach($u as$k=>$n){$v=$d->$k;if($v)$r[]="$v $n".($v>1?'s':'');if(count($r)==$l)return implode(',',$r);}}
+function humanFriendly($format='M j,Y \a\t g:ia'){$d=$this->diff();$t=$this->getTimestamp();if(!$d->d){$s=$this->difference();return$t>time()?"in $s":"$s ago";}return$this->format($format);}
+static function show($time){$t=new Time($time);return$t->humanFriendly();}
+}
View
2 index.php
@@ -9,6 +9,6 @@
function exception($e){$v=new View('exception');$v->e=$e;_log($e->getMessage().' '.$e->getFile());die($v);}
set_exception_handler('exception');
register_shutdown_function(function(){if($e=error_get_last())exception(new ErrorException($e['message'],$e['type'],0,v($e['file']),$e['line']));});
-$c='controller_'.(url(0)?:'home');$m=url(1)?:'index';if(!is_file(p("classes/$c"))||!($c=new$c)||$m=='render'||!method_exists($c,$m)){$c=new controller;$m='show_404';}
+$c='controller_'.(url(0)?:'home');$m=url(1)?:'index';if(!is_file(p("classes/$c"))||!($c=new$c)||$m=='render'||!in_array($m,get_class_methods($c))){$c=new controller;$m='show_404';}
call_user_func_array(array($c,$m),array_slice(url(),2));
$c->render();

0 comments on commit 91c8091

Please sign in to comment.
Something went wrong with that request. Please try again.