[Wiki] changed: CreatingYourFirstModule

Wiki Guest <[email protected]>
Newsgroups gmane.comp.horde.cvs
Message-ID <[email protected]>
guest [129.187.43.121]  Fri, 06 Feb 2009 14:53:43 -0500

Modified page: http://wiki.horde.org/CreatingYourFirstModule
New Revision:  1.1
Change log:  Rename-Script updated

@@ -11,41 +11,87 @@

  2. Create the following script as prjrename.php - save it somewhere  
sensible, like your home directory:

  <code type="php">
-<?php
+#!/usr/bin/php -q
+<?
+function analysedir( $path_, $list_ )
+{
+  // Verzeichnis lesen
+  //echo "Path: $path_nn";
+  $handle = opendir($path_);
+  while (false !== ($file = readdir($handle)))
+  {
+    if( $file!='.' && $file!='..')
+    {
+        $file = $path_ . DIRECTORY_SEPARATOR . $file;
+        //echo "$filen";
+
+        if( !is_dir( $file ) )  // Wenn Datei: Anhängen
+        {
+          $list_[count($list_)]=$file;
+        }
+        else   // Wenn Ordner: Rekursiv untersuchen
+        {
+          $list_ += analysedir($file, $list_ );
+        }
+   }
+ }      // While ENDE
+ return $list_;
+}
+
+function substitute_skeleton( $filename, $modulname )
+{

-if (count($_SERVER['argv'])==3) {

-  $prjUC=strtoupper(trim($_SERVER['argv'][2]));
+  $prjUC=strtoupper(trim($modulname));
    $prjLC=strtolower($prjUC);
    $prjMC=substr($prjUC, 0, 1) . substr($prjLC, 1, strlen($prjLC)-1);

-  $filehandle=fopen(trim($_SERVER['argv'][1]), 'r');
-  $file=fread($filehandle, filesize($_SERVER['argv'][1]));
+  $filehandle=fopen(trim($filename), 'r');
+  $file=fread($filehandle, filesize($filename));
    fclose($filehandle);
    $newfile=str_replace(array('SKELETON', 'Skeleton', 'skeleton'),  
array($prjUC, $prjMC, $prjLC), $file);
-  $filehandle=fopen(trim($_SERVER['argv'][1]), 'w');
+  $filehandle=fopen(trim($filename), 'w');
    fwrite($filehandle, $newfile);
    fclose($filehandle);
-} else {
-  help();
  }

-function help() {
-  echo "php prjrename.php [filename] [string]
-filename = The file to update
-string = the name of the file to replace
-";
+function help()
+{
+  echo "projectrename.php </path/to/skeleton-folder/> <modulname>n";
  }

+//
+// ------------------- Main-Code --------------------
+//
+
+if (count($_SERVER['argv'])==3)
+{
+  // Preparation
+  $list = array();
+  $path = trim($_SERVER[argv][1]);
+  $modul = trim($_SERVER[argv][2]);
+
+  // Fetch Filelist
+  $list = analysedir( $path, $list );
+
+  // Modify each File
+  foreach( $list as $file )
+  {
+        //echo $modul.": ".$file."n";
+        substitute_skeleton( $file, $modul );
+  }
+}
+else
+  help();
  ?>
  </code>

-3. On a unix system, use the following command to replace all  
skeleton strings with your project name (I don't think there's an  
appropriate command for windows, unless you've got cygwin):
+3. On a unix system, use the following command to replace all  
skeleton strings with your project name (Not tested on Windows, but  
should work):

  <code type="sh">
-find /path/to/skeleton/export -type f -exec php -q  
/path/to/prjrename.php '{}' modulename
+projectrename.php /path/to/skeleton/Checkout/ modulname
  </code>

  4. Perform some file modifications:


--
To unsubscribe, mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.