Source for file Ethna_Plugin_Generator_Project.php

Documentation is available at Ethna_Plugin_Generator_Project.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Generator_Project.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: Ethna_Plugin_Generator_Project.php 523 2008-05-01 19:38:03Z mumumu-org $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Generator_Project
  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  $id         プロジェクトID
  26.      *  @param  string  $basedir    プロジェクトベースディレクトリ
  27.      *  @return bool    true:成功 false:失敗
  28.      */
  29.     function generate($id$basedir)
  30.     {
  31.         $dir_list array(
  32.             array("app"0755),
  33.             array("app/action"0755),
  34.             array("app/action_cli"0755),
  35.             array("app/action_xmlrpc"0755),
  36.             array("app/filter"0755),
  37.             array("app/plugin"0755),
  38.             array("app/plugin/Filter"0755),
  39.             array("app/plugin/Validator"0755),
  40.             array("app/view"0755),
  41.             array("app/test"0755),
  42.             array("bin"0755),
  43.             array("etc"0755),
  44.             array("lib"0755),
  45.             array("locale"0755),
  46.             array("locale/ja"0755),
  47.             array("locale/ja/LC_MESSAGES"0755),
  48.             array("log"0777),
  49.             array("schema"0755),
  50.             array("skel"0755),
  51.             array("template"0755),
  52.             array("template/ja"0755),
  53.             array("tmp"0777),
  54.             array("www"0755),
  55.             array("www/css"0755),
  56.             array("www/js"0755),
  57.         );
  58.  
  59.         // double check.
  60.         $id strtolower($id);
  61.         $r Ethna_Controller::checkAppId($id);
  62.         if (Ethna::isError($r)) {
  63.             return $r;
  64.         }
  65.  
  66.         $basedir sprintf("%s/%s"$basedir$id);
  67.  
  68.         // ディレクトリ作成
  69.         if (is_dir($basedir== false{
  70.             // confirm
  71.             printf("creating directory ($basedir) [y/n]: ");
  72.             flush();
  73.             $fp fopen("php://stdin""r");
  74.             $r trim(fgets($fp128));
  75.             fclose($fp);
  76.             if (strtolower($r!= 'y'{
  77.                 return Ethna::raiseError('aborted by user');
  78.             }
  79.  
  80.             if (mkdir($basedir0775== false{
  81.                 return Ethna::raiseError('directory creation failed');
  82.             }
  83.         }
  84.         foreach ($dir_list as $dir{
  85.             $mode $dir[1];
  86.             $dir $dir[0];
  87.             $target "$basedir/$dir";
  88.             if (is_dir($target)) {
  89.                 printf("%s already exists -> skipping...\n"$target);
  90.                 continue;
  91.             }
  92.             if (mkdir($target$mode== false{
  93.                 return Ethna::raiseError('directory creation failed');
  94.             else {
  95.                 printf("project sub directory created [%s]\n"$target);
  96.             }
  97.             if (chmod($target$mode== false{
  98.                 return Ethna::raiseError('chmod failed');
  99.             }
  100.         }
  101.  
  102.         // スケルトンファイル作成
  103.         $macro['ethna_version'ETHNA_VERSION;
  104.         $macro['application_id'strtoupper($id);
  105.         $macro['project_id'ucfirst($id);
  106.         $macro['project_prefix'$id;
  107.         $macro['basedir'realpath($basedir);
  108.  
  109.         $macro['action_class''{$action_class}';
  110.         $macro['action_form''{$action_form}';
  111.         $macro['action_name''{$action_name}';
  112.         $macro['action_path''{$action_path}';
  113.         $macro['forward_name''{$forward_name}';
  114.         $macro['view_name''{$view_name}';
  115.         $macro['view_path''{$view_path}';
  116.  
  117.         $user_macro $this->_getUserMacro();
  118.         $default_macro $macro;
  119.         $macro array_merge($macro$user_macro);
  120.  
  121.         // the longest if? :)
  122.         if ($this->_generateFile("www.index.php""$basedir/www/index.php"$macro== false ||
  123.             $this->_generateFile("www.info.php""$basedir/www/info.php"$macro== false ||
  124.             $this->_generateFile("www.unittest.php""$basedir/www/unittest.php"$macro== false ||
  125.             $this->_generateFile("www.xmlrpc.php""$basedir/www/xmlrpc.php"$macro== false ||
  126.             $this->_generateFile("www.css.ethna.css""$basedir/www/css/ethna.css"$macro== false ||
  127.             $this->_generateFile("dot.ethna""$basedir/.ethna"$macro== false ||
  128.             $this->_generateFile("app.controller.php"sprintf("$basedir/app/%s_Controller.php"$macro['project_id'])$macro== false ||
  129.             $this->_generateFile("app.error.php"sprintf("$basedir/app/%s_Error.php"$macro['project_id'])$macro== false ||
  130.             $this->_generateFile("app.actionclass.php"sprintf("$basedir/app/%s_ActionClass.php"$macro['project_id'])$macro== false ||
  131.             $this->_generateFile("app.actionform.php"sprintf("$basedir/app/%s_ActionForm.php"$macro['project_id'])$macro== false ||
  132.             $this->_generateFile("app.viewclass.php"sprintf("$basedir/app/%s_ViewClass.php"$macro['project_id'])$macro== false ||
  133.             $this->_generateFile("app.action.default.php""$basedir/app/action/Index.php"$macro== false ||
  134.             $this->_generateFile("app.plugin.filter.default.php"sprintf("$basedir/app/plugin/Filter/%s_Plugin_Filter_ExecutionTime.php"$macro['project_id'])$macro== false ||
  135.             $this->_generateFile("app.view.default.php""$basedir/app/view/Index.php"$macro== false ||
  136.             $this->_generateFile("app.unittest.php"sprintf("$basedir/app/%s_UnitTestManager.php"$macro['project_id'])$macro== false ||
  137.             $this->_generateFile("app.url_handler.php"sprintf("$basedir/app/%s_UrlHandler.php"$macro['project_id'])$macro== false ||
  138.             $this->_generateFile("etc.ini.php"sprintf("$basedir/etc/%s-ini.php"$macro['project_prefix'])$macro== false ||
  139.             $this->_generateFile("skel.action.php"sprintf("$basedir/skel/skel.action.php")$default_macro== false ||
  140.             $this->_generateFile("skel.action_cli.php"sprintf("$basedir/skel/skel.action_cli.php")$default_macro== false ||
  141.             $this->_generateFile("skel.action_test.php"sprintf("$basedir/skel/skel.action_test.php")$default_macro== false ||
  142.             $this->_generateFile("skel.app_object.php"sprintf("$basedir/skel/skel.app_object.php")$default_macro== false ||
  143.             $this->_generateFile("skel.entry_www.php"sprintf("$basedir/skel/skel.entry_www.php")$default_macro== false ||
  144.             $this->_generateFile("skel.entry_cli.php"sprintf("$basedir/skel/skel.entry_cli.php")$default_macro== false ||
  145.             $this->_generateFile("skel.view.php"sprintf("$basedir/skel/skel.view.php")$default_macro== false ||
  146.             $this->_generateFile("skel.template.tpl"sprintf("$basedir/skel/skel.template.tpl")$default_macro== false ||
  147.             $this->_generateFile("skel.view_test.php"sprintf("$basedir/skel/skel.view_test.php")$default_macro== false ||
  148.             $this->_generateFile("template.index.tpl"sprintf("$basedir/template/ja/index.tpl")$default_macro== false{
  149.             return Ethna::raiseError('generating files failed');
  150.         }
  151.  
  152.         return true;
  153.     }
  154. }
  155. // }}}
  156. ?>

Documentation generated on Thu, 08 May 2008 00:15:09 +0900 by phpDocumentor 1.4.2