Source for file CreatePlugin.php

Documentation is available at CreatePlugin.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  CreatePlugin.php
  5.  *
  6.  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: d1507c3241e27776f51f9d886d668f4e127ad90e $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Generator_CreatePlugin
  13. /**
  14.  *  プラグインパッケージスケルトン生成クラス
  15.  *
  16.  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**
  22.      *  テンプレートのスケルトンを生成する
  23.      *
  24.      *  @access public
  25.      *  @param  string  $basedir        ベースディレクトリ
  26.      *  @param  array   $types          プラグインのtype (Validator, Handle等)
  27.      *  @param  string  $forpackage     iniファイル生成フラグ
  28.      *  @param  string  $plugin_name    プラグイン名
  29.      *  @return true|Ethna_Error       true:成功 Ethna_Error:失敗
  30.      */
  31.     function generate($basedir$types array()$forpackage false$plugin_name)
  32.     {
  33.         $plugin_dir "$basedir/plugin";
  34.         if (!$forpackage{
  35.             $chk_ctl Ethna_Handle::getAppController(getcwd());
  36.             if (Ethna::isError($chk_ctl)) {
  37.                 return Ethna::raiseError(
  38.                            "ERROR: You are not in Ethna project. specify [-p|--plugin-package] option, or change directory to the Ethna Project\n"
  39.                 );
  40.             }
  41.             $plugin_dir $chk_ctl->getDirectory('plugin');
  42.         }
  43.  
  44.         //  create plugin directory
  45.         if (!file_exists($plugin_dir)) {
  46.             Ethna_Util::mkdir($plugin_dir0755);
  47.         }
  48.  
  49.         //   type check.
  50.         if (empty($types)) {
  51.             return Ethna::raiseError('please specify plugin type.');
  52.         }
  53.  
  54.         //
  55.         //   type check
  56.         //
  57.         foreach ($types as $type{
  58.             switch (strtolower($type)) {
  59.             case 'f':
  60.             case 'v':
  61.             case 'sm':
  62.             case 'sb':
  63.             case 'sf':
  64.                 break;
  65.             default:
  66.                 return Ethna::raiseError("unknown plugin type: ${type}"'usage');
  67.             }
  68.         }
  69.  
  70.         //
  71.         //   Generate Plugin PHP File   
  72.         //
  73.         $plugin_name ucfirst(strtolower($plugin_name));
  74.         $lplugin_name strtolower($plugin_name);
  75.         $macro['plugin_name'$plugin_name;
  76.         foreach ($types as $type{
  77.             $ltype strtolower($type);
  78.             $macro['plugin_type'$type;
  79.             $plugin_file_skel "plugin/skel.plugin.${ltype}.php";
  80.         
  81.             //   create directory
  82.             switch ($type{
  83.             case 'f':
  84.                 $type 'Filter';
  85.                 $pfilename "${plugin_name}.php";
  86.                 break;
  87.             case 'v':
  88.                 $type 'Validator';
  89.                 $pfilename "${plugin_name}.php";
  90.                 break;
  91.             case 'sm':
  92.                 $type 'Smarty';
  93.                 $pfilename "modifier.${lplugin_name}.php";
  94.                 $macro['plugin_name'$lplugin_name;
  95.                 break;
  96.             case 'sb':
  97.                 $type 'Smarty';
  98.                 $pfilename "block.${lplugin_name}.php";
  99.                 $macro['plugin_name'$lplugin_name;
  100.                 break;
  101.             case 'sf':
  102.                 $type 'Smarty';
  103.                 $pfilename "function.${lplugin_name}.php";
  104.                 $macro['plugin_name'$lplugin_name;
  105.                 break;
  106.             }
  107.             $type_dir "$plugin_dir/$type";
  108.             if (!file_exists($type_dir)) {
  109.                 Ethna_Util::mkdir($type_dir0755);
  110.             }
  111.  
  112.             $type_file_path "$type_dir/${pfilename}";
  113.  
  114.             // generate
  115.             if (file_exists($type_file_path)) {
  116.                 printf("file [%s] already exists -> skip\n"$type_file_path);
  117.             else if ($this->_generateFile($plugin_file_skel$type_file_path$macro== false{
  118.                 printf("[warning] file creation failed [%s]\n"$type_file_path);
  119.             else {
  120.                 printf("plugin php file successfully created [%s]\n"$type_file_path);
  121.             }
  122.         
  123.  
  124.         //   generate ini file
  125.         if ($forpackage{
  126.             $ini_skel 'plugin/skel.plugin.ini';
  127.             $ini_file strtolower($plugin_name'.ini';
  128.             $ini_path "$plugin_dir/$ini_file";
  129.         
  130.             if (file_exists($ini_path)) {
  131.                 printf("file [%s] already exists -> skip\n"$ini_file);
  132.             else if ($this->_generateFile($ini_skel$ini_path$macro== false{
  133.                 printf("[warning] file creation failed [%s]\n"$ini_file);
  134.             else {
  135.                 printf("plugin ini file successfully created [%s]\n"$ini_file);
  136.             }
  137.         }
  138.  
  139.         $true true;
  140.         return $true;
  141.     }
  142. }
  143. // }}}

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