Source for file Template.php

Documentation is available at Template.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Template.php
  5.  *
  6.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: 289541e22962ba4ef1ae15455675ad72d3b18d49 $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Generator_Template
  13. /**
  14.  *  スケルトン生成クラス
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**
  22.      *  テンプレートのスケルトンを生成する
  23.      *
  24.      *  @access public
  25.      *  @param  string  $forward_name   テンプレート名
  26.      *  @param  string  $skelton        スケルトンファイル名
  27.      *  @param  string  $locale         ロケール名
  28.      *  @param  string  $encoding       エンコーディング
  29.      *  @return true|Ethna_Error       true:成功 Ethna_Error:失敗
  30.      */
  31.     function generate($forward_name$skelton null$locale$encoding)
  32.     {
  33.         //  ロケールが指定された場合は、それを優先する 
  34.         if (!empty($locale)) {
  35.             $this->ctl->setLocale($locale);
  36.         }
  37.  
  38.         //  ロケール名がディレクトリに含まれていない場合は、
  39.         //  ディレクトリがないためなのでそれを補正 
  40.         $tpl_dir $this->ctl->getTemplatedir();
  41.         $tpl_path $this->ctl->getDefaultForwardPath($forward_name);
  42.  
  43.         // entity
  44.         $entity $tpl_dir '/' $tpl_path;
  45.         Ethna_Util::mkdir(dirname($entity)0755);
  46.  
  47.         // skelton
  48.         if ($skelton === null{
  49.             $skelton 'skel.template.tpl';
  50.         }
  51.  
  52.         // macro
  53.         $macro array();
  54.         // add '_' for tpl and no user macro for tpl
  55.         $macro['_project_id'$this->ctl->getAppId();
  56.         $macro['client_enc'$encoding;
  57.  
  58.         // generate
  59.         if (file_exists($entity)) {
  60.             printf("file [%s] already exists -> skip\n"$entity);
  61.         else if ($this->_generateFile($skelton$entity$macro== false{
  62.             printf("[warning] file creation failed [%s]\n"$entity);
  63.         else {
  64.             printf("template file(s) successfully created [%s]\n"$entity);
  65.         }
  66.  
  67.         $true true;
  68.         return $true;
  69.     }
  70. }
  71. // }}}

Documentation generated on Fri, 11 Nov 2011 03:59:09 +0900 by phpDocumentor 1.4.3