Source for file ClearCache.php

Documentation is available at ClearCache.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  ClearCache.php
  5.  *
  6.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: 67b3ea376cc12a750d41139576dcab97ed7dc586 $
  10.  */
  11.  
  12. require_once ETHNA_BASE '/class/PearWrapper.php';
  13.  
  14. // {{{ Ethna_Plugin_Handle_ClearCache
  15. /**
  16.  *  clear-cache handler
  17.  *
  18.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  19.  *  @access     public
  20.  *  @package    Ethna
  21.  */
  22. {
  23.     /**
  24.      *  clear cache files.
  25.      *
  26.      *  @access public
  27.      *  @todo   implement Ethna_Renderer::clear_cache();
  28.      *  @todo   implement Ethna_Plugin_Cachemanager::clear_cache();
  29.      *  @todo   avoid echo, printf
  30.      */
  31.     function perform()
  32.     {
  33.         $r $this->_getopt(array('basedir='
  34.                                    'any-tmp-files''smarty''pear''cachemanager'));
  35.         if (Ethna::isError($r)) {
  36.             return $r;
  37.         }
  38.         list($args,$r;
  39.  
  40.         $basedir = isset($args['basedir']realpath(end($args['basedir'])) getcwd();
  41.         $controller Ethna_Handle::getAppController($basedir);
  42.         if (Ethna::isError($controller)) {
  43.             return $controller;
  44.         }
  45.         $tmp_dir $controller->getDirectory('tmp');
  46.  
  47.         if (isset($args['smarty']|| isset($args['any-tmp-files'])) {
  48.             echo "cleaning smarty caches, compiled templates...";
  49.             $renderer $controller->getRenderer();
  50.             if (strtolower(get_class($renderer)) == "ethna_renderer_smarty"{
  51.                 $renderer->engine->clear_all_cache();
  52.                 $renderer->engine->clear_compiled_tpl();
  53.             }
  54.             echo " done\n";
  55.         }
  56.  
  57.         if (isset($args['cachemanager']|| isset($args['any-tmp-files'])) {
  58.             echo "cleaning Ethna_Plugin_Cachemanager caches...";
  59.             $cache_dir sprintf("%s/cache"$tmp_dir);
  60.             Ethna_Util::purgeDir($cache_dir);
  61.             echo " done\n";
  62.         }
  63.  
  64.         if (isset($args['any-tmp-files'])) {
  65.             echo "cleaning tmp dirs...";
  66.             // purge only entries in tmp.
  67.             if ($dh opendir($tmp_dir)) {
  68.                 while (($entry readdir($dh)) !== false{
  69.                     if ($entry === '.' || $entry === '..'{
  70.                         continue;
  71.                     }
  72.                     Ethna_Util::purgeDir("{$tmp_dir}/{$entry}");
  73.                 }
  74.                 closedir($dh);
  75.             }
  76.             echo " done\n";
  77.         }
  78.  
  79.         return true;
  80.     }
  81.  
  82.     // {{{ getDescription()
  83.     /**
  84.      *  @access public
  85.      */
  86.     function getDescription()
  87.     {
  88.         return <<<EOS
  89. clear project's cache files:
  90.     {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]
  91.  
  92. EOS;
  93.     }
  94.     // }}}
  95.  
  96.     // {{{ getUsage()
  97.     /**
  98.      *  @access public
  99.      */
  100.     function getUsage()
  101.     {
  102.         return <<<EOS
  103. ethna {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]
  104. EOS;
  105.     }
  106.     // }}}
  107. }
  108. // }}}

Documentation generated on Fri, 11 Nov 2011 03:57:45 +0900 by phpDocumentor 1.4.3