標籤:href foreach class color config func 命令列 令行 pos
接著之前的文章:php根據命令列參數組建組態檔案
ghostinit.php
<?php class ghostinit{ static $v = ‘ghost version is 1.1‘; static function init(){ echo "pls input project name?" . PHP_EOL; $projName = fgets( STDIN ); echo "pls input author?" . PHP_EOL; $author = fgets( STDIN ); echo self::buildConfig( [ ‘proj‘ => $projName, ‘author‘ => $author ] ); } static function buildConfig( $info ){ return file_put_contents( getcwd() . ‘/go.json‘, json_encode( $info ) ) . ‘ bytes has written,‘ . ‘config file has created‘ . PHP_EOL; } static function show(){ $conf = json_decode( file_get_contents( getcwd() . ‘/go.json‘ ) ); foreach( $conf as $k => $v ){ echo $k . ‘:‘ . $v; } } static function getConfig( $conf ){ $std = new stdClass(); foreach( $conf as $k => $v ){ $std->$k = $v; } return $std; } static function __callstatic( $m, $args ){ echo ‘error function‘; } }?>
php命令列產生與讀取設定檔