php命令行生成与读取配置文件 php根据命令行参数生成配置文件

接着之前的文章: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';
        }

    }

?>

猜你喜欢

转载自www.cnblogs.com/ghostwu/p/8969816.html