コード例 #1
0
 /**
  * Purge cache
  * 
  * Clean cache folder; errors are not caught nor thrown.
  *
  * @return  bool
  */
 public function purge($request = null)
 {
     if (is_null($request)) {
         $this->logger->info('Purging whole cache');
         $cache_files_number = 0;
         $cache_path = opendir($this->cache_path);
         if ($cache_path === false) {
             $this->logger->error('Unable to open cache folder', array('CACHEFOLDER' => $this->cache_path));
             return false;
         }
         while (false !== ($cache_file = readdir($cache_path))) {
             if (pathinfo($cache_file, PATHINFO_EXTENSION) == "cache") {
                 if (unlink($this->cache_path . ($this->cache_path[strlen($this->cache_path) - 1] == "/" ? "" : "/") . $cache_file) == false) {
                     return false;
                 } else {
                     $cache_files_number++;
                 }
             } else {
                 continue;
             }
         }
         closedir($cache_path);
     } else {
         $this->logger->info('Purging request cache', array('REQUEST' => $request));
         $cacheTag = md5($request) . ".cache";
         $cacheFile = $this->cache_path . ($this->cache_path[strlen($this->cache_path) - 1] == "/" ? "" : "/") . $cacheTag;
         if (is_readable($cacheFile)) {
             $unlink = unlink($cacheFile);
             $cache_files_number = $unlink ? 1 : false;
         } else {
             $cache_files_number = 0;
         }
     }
     return $cache_files_number;
 }
コード例 #2
0
 /**
  * Fire an event
  *
  * @param   string  $event      Event name
  * @param   string  $type       the type of event
  * @param   Object  $data       Data to provide to callback
  *
  * @return  Object|null
  */
 public final function fire($event, $type, $data)
 {
     $this->logger->info('Firing event', array('EVENT' => $event));
     $value = $data;
     if (isset($this->hooks[$event])) {
         foreach ($this->hooks[$event] as $callback) {
             $return_value = null;
             if (is_array($callback)) {
                 if (is_callable(array($callback[0], $callback[1]))) {
                     try {
                         $return_value = call_user_func(array($callback[0], $callback[1]), $value);
                     } catch (Exception $e) {
                         $this->logger->error('Hook error', array('EVENT' => $event, 'CALLBACK' => $callback[0], 'METHOD' => $callback[1], 'CODE' => $e->getCode(), 'MESSAGE' => $e->getMessage()));
                         continue;
                     }
                 } else {
                     $this->logger->warning('Skipping not-callable hook', array('EVENT' => $event, 'CALLBACK' => $callback[0], 'METHOD' => $callback[1]));
                     continue;
                 }
             } else {
                 if (is_callable($callback)) {
                     try {
                         $return_value = call_user_func($callback, $value);
                     } catch (Exception $e) {
                         $this->logger->error('Hook error', array('EVENT' => $event, 'CALLBACK' => $callback, 'CODE' => $e->getCode(), 'MESSAGE' => $e->getMessage()));
                         continue;
                     }
                 } else {
                     $this->logger->warning('Skipping not-callable hook', array('EVENT' => $event, 'CALLBACK' => $callback));
                     continue;
                 }
             }
             switch ($type) {
                 case 'REQUEST':
                     $value = $return_value instanceof \Comodojo\Dispatcher\ObjectRequest\ObjectRequest ? $return_value : $value;
                     break;
                 case 'TABLE':
                     $value = $return_value instanceof \Comodojo\Dispatcher\ObjectRoutingTable\ObjectRoutingTable ? $return_value : $value;
                     break;
                 case 'ROUTE':
                     $value = $return_value instanceof \Comodojo\Dispatcher\ObjectRoute\ObjectRoute ? $return_value : $value;
                     break;
                 case 'RESULT':
                     $value = $return_value instanceof \Comodojo\Dispatcher\ObjectResult\ObjectResultInterface ? $return_value : $value;
                     break;
                 case 'VOID':
                 default:
                     $value = $value;
                     break;
             }
         }
         return $value;
     }
     return $data;
 }