Ejemplo n.º 1
0
 /**
  * Render view template
  * @param string $template php file in views/(without .php extension)
  * @param array $_____params render variable
  * @param null $self use to pass $this ($self represent $this in template)
  * @return string
  * @throws CException
  */
 public static function render($template, $_____params = array(), &$self = null)
 {
     if (file_exists($template)) {
         $f = $template;
     } else {
         $f = "views/{$template}.php";
     }
     if (file_exists($f)) {
         extract($_____params, EXTR_SKIP);
         ob_start();
         include $f;
         $return = ob_get_contents();
         ob_end_clean();
         return $return;
     } else {
         $exception = new CException("View : template {$template} not found");
         $exception->set("template", $f);
         $exception->set("service", $_REQUEST->service);
         $exception->set("request", $_REQUEST->request);
         throw $exception;
     }
 }
Ejemplo n.º 2
0
 /**
  * recursively delete a directory / file
  * @param $str
  * @return bool
  * @throws CException
  */
 public static function delete($str)
 {
     if (!is_string($str)) {
         $exception = new CException("Core_Directory:delete error");
         $exception->set("dir", $str);
         //$exception->set("service", $_REQUEST["service"]);
         //$exception->set("request", $_REQUEST["request"]);
         throw $exception;
     }
     if (is_file($str)) {
         return @unlink($str);
     } elseif (is_dir($str)) {
         $scan = glob(rtrim($str, '/') . '/*');
         foreach ($scan as $index => $path) {
             self::delete($path);
         }
         return @rmdir($str);
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Execute $r method of a class or instance $Obj
  * @param string|object $Obj Class name or an instance of the class
  * @param string $r Method name
  * @param array $params Method parameters
  * @return mixed
  * @throws CException
  * @throws null
  */
 public static function execTask($Obj, $r, array $params = array())
 {
     // Si nom de classe renseigné
     if (!is_object($Obj)) {
         $s = $Obj;
         try {
             // static class
             if (self::isStatic($s, $r)) {
                 $Obj = $s;
             } else {
                 $Obj = new $s();
             }
         } catch (CException $exception) {
             $exception = new CException("service {$s}:{$r} not found");
             $exception->set("service", $s);
             $exception->set("request", $r);
             throw $exception;
         }
     } else {
         // Si objet passé en paramètres
         $s = get_class($Obj);
     }
     if (method_exists($s, $r) && is_callable(array($s, $r))) {
         // TODO à corriger
         if (!is_array($params)) {
             $params = array($params);
         }
         // Limit parameter to method definition (pour securité ?)
         $Met = new \ReflectionMethod($s, $r);
         $Param = $Met->getParameters();
         if (empty($Param)) {
             $Param = array();
         }
         $params = array_slice($params, 0, count($Param));
         $res = call_user_func_array(array($Obj, $r), $params);
         // Log les appels des services
         // TODO disable for prod
         $logParams = array();
         foreach ($params as $p) {
             if (is_scalar($p)) {
                 $l = strip_tags($p);
                 if (strlen($l) > 20) {
                     $l = substr($l, 0, 20) . "...";
                 }
                 $logParams[] = $l;
             } elseif (is_array($p)) {
                 $logParams[] = "Array";
             } elseif (is_object($p)) {
                 $logParams[] = "Object[" . get_class($p) . "]";
             }
         }
         FirePHP::fbLog("info", "{$s}/{$r}(" . implode(", ", $logParams) . ")");
         return $res;
     } else {
         $exception = null;
         if (!method_exists($s, $r)) {
             $exception = new CException("service {$s}:{$r} not found");
         } elseif (!is_callable(array($s, $r))) {
             $exception = new CException("serviceNotCallable");
         }
         $exception->set("service", $s);
         $exception->set("request", $r);
         throw $exception;
     }
 }