欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php命令行生成与读取配置文件

程序员文章站 2022-07-02 14:30:34
接着之前的文章:php根据命令行参数生成配置文件 ghostinit.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';
        }

    }

?>