Changeset 191 for trunk/trax/trax.php
- Timestamp:
- 03/24/06 09:37:59 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/trax.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/trax.php
r185 r191 23 23 define("SOURCE_DIR", "@DATA-DIR@/PHPonTrax/data/"); 24 24 25 /** 26 * Symbol substitution tables 27 * 28 * $search and $replace below are used to perform substitutions of 29 * symbols in a file being copied. $search is an array of 30 * Perl-compatible regular expressions, and $replace is a congruent 31 * array of replacements for RE matches. So everywhere that the RE 32 * in, for example, $search[3] is matched in a file, the matching 33 * string is replaced by the contents of $replace[3]. 34 */ 35 $search = array( 36 '@TRAX-CONFIG@' // symbol for the full filesystem path 37 // to the Trax config/ directory in 38 // the user's work area 39 ); 40 41 $replace = array( 42 '' // actual value of the full filesystem 43 // path to the Trax config/ directory 44 // in the user's work area 45 ); 46 47 25 48 function trax() { 26 49 … … 40 63 $dstdir = $GLOBALS['argv'][1]; 41 64 42 // Guarantee it ends with '/'43 if (substr($dstdir,-1,1) != '/') {44 $dstdir .= '/';65 // Guarantee it ends with DIRECTORY_SEPARATOR 66 if (substr($dstdir,-1,1) != DIRECTORY_SEPARATOR) { 67 $dstdir .= DIRECTORY_SEPARATOR; 45 68 } 46 69 if (!create_dir($dstdir)) { 47 70 return; 48 71 } 72 73 // Assign real values for symbol substitution 74 $replace[0] = $dstdir.'config'; // actual value of the full 75 // filesystem path to the Trax 76 // config/ directory in the user's 77 // work area 49 78 50 79 $srcdir = SOURCE_DIR; … … 120 149 121 150 // Destination file does not exist. Create it 122 if (!copy ($src_path . $src_file, $dst_path . $src_file)) {151 if (!copy_file($src_path . $src_file, $dst_path . $src_file)) { 123 152 return false; 124 153 } … … 141 170 142 171 // Recursive call to copy directory 143 if (!copy_dir($src_path . $src_file .'/',144 $dst_path . $src_file . '/')) {172 if (!copy_dir($src_path . $src_file . DIRECTORY_SEPARATOR, 173 $dst_path . $src_file . DIRECTORY_SEPARATOR)) { 145 174 return false; 146 175 } … … 165 194 166 195 // A destination directory with this name exists. 167 echo "$dst_dir /exists\n";196 echo "$dst_dir".DIRECTORY_SEPARATOR." exists\n"; 168 197 return true; 169 198 } … … 185 214 return false; 186 215 } 187 echo "$dst_dir /created\n";216 echo "$dst_dir".DIRECTORY_SEPARATOR." created\n"; 188 217 return true; 189 218 } 190 219 191 220 /** 221 * Copy a Trax file into user's work area, substituting @TRAX-...@ 222 * 223 * @param string $src_path Path to source file 224 * @param string $dst_path Path to destination file 225 * @return boolean true=>success, false=>failure. 226 */ 227 function copy_file($src_path, $dst_path) { 228 229 // Read source file into a string 230 if (!$file = file_get_contents($src_path)) { 231 return false; 232 } 233 234 // Substitute @TRAX-...@ symbols for appropriate values 235 236 // Write out file contents 237 @file_put_contents($dst_path, $file); 238 return true; 239 } 240 241 /** 192 242 * Output a Usage message and exit 193 243 */ 194 244 function usage() { 195 echo <<<END 196 Usage: @BIN-DIR@/trax /path/to/your/app 245 echo "Usage: @BIN-DIR@".DIRECTORY_SEPARATOR."trax" 246 ." ".DIRECTORY_SEPARATOR."path".DIRECTORY_SEPARATOR."to" 247 .DIRECTORY_SEPARATOR."your".DIRECTORY_SEPARATOR."app 197 248 198 249 Description: … … 201 252 202 253 Example: 203 trax /var/www/html 204 205 This generates a skeletal Trax installation in /var/www/html. 254 trax ".DIRECTORY_SEPARATOR."var".DIRECTORY_SEPARATOR."www" 255 .DIRECTORY_SEPARATOR."html 256 257 This generates a skeletal Trax installation in " 258 .DIRECTORY_SEPARATOR."var".DIRECTORY_SEPARATOR."www" 259 .DIRECTORY_SEPARATOR."html. 206 260 See the README in the newly created application to get going. 207 208 END; 261 \n"; 209 262 exit; 210 263 }
