Source for file Ethna_Plugin_Handle_ClearCache.php

Documentation is available at Ethna_Plugin_Handle_ClearCache.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Handle_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$
  10.  */
  11.  
  12. require_once ETHNA_BASE '/class/Ethna_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['pear']|| isset($args['any-tmp-files'])) {
  65.             echo "cleaning pear caches...";
  66.             ob_start();
  67.             $pear =new Ethna_PearWrapper();
  68.             $r =$pear->init('local'$basedir)
  69.             if (Ethna::isError($r)) {
  70.                 echo ob_get_clean();
  71.                 return $r;
  72.             }
  73.             $r =$pear->doClearCache();
  74.             if (Ethna::isError($r)) {
  75.                 echo ob_get_clean();
  76.                 return $r;
  77.             }
  78.             ob_get_clean();
  79.             echo " done\n";
  80.         }
  81.  
  82.         if (isset($args['any-tmp-files'])) {
  83.             echo "cleaning tmp dirs...";
  84.             // purge only entries in tmp.
  85.             if ($dh opendir($tmp_dir)) {
  86.                 while (($entry readdir($dh)) !== false{
  87.                     if ($entry === '.' || $entry === '..'{
  88.                         continue;
  89.                     }
  90.                     Ethna_Util::purgeDir("{$tmp_dir}/{$entry}");
  91.                 }
  92.                 closedir($dh);
  93.             }
  94.             echo " done\n";
  95.         }
  96.  
  97.         return true;
  98.     }
  99.  
  100.     // {{{ getDescription()
  101.     /**
  102.      *  @access public
  103.      */
  104.     function getDescription()
  105.     {
  106.         return <<<EOS
  107. clear project's cache files:
  108.     {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]
  109.  
  110. EOS;
  111.     }
  112.     // }}}
  113.  
  114.     // {{{ getUsage()
  115.     /**
  116.      *  @access public
  117.      */
  118.     function getUsage()
  119.     {
  120.         return <<<EOS
  121. ethna {$this->id} [-b|--basedir=dir] [-a|--any-tmp-files] [-s|--smarty] [-p|--pear] [-c|--cachemanager]
  122. EOS;
  123.     }
  124.     // }}}
  125. }
  126. // }}}
  127. ?>

Documentation generated on Fri, 11 Nov 2011 04:00:26 +0900 by phpDocumentor 1.4.3