Then this article PHP command line build project structure continues to transform:
[Email protected]:~/php/php1/12$ tree. ├──app│└──index. php├──core│├──frame││├──ghost_frame. php││└──template││ └──index. Tpl│└──ghostinit. function. Php├──ghost└──go. JSON
INDEX.TPL:
Echo php_eol;?>* * * *project name: <?php Echo $proj. Php_eol,?> * Author: <?php echo $author. Php_eol;?> * Date: <?php echo date (' y-m-d '). Php_eol,?> * **/echo "Hello Ghostwu";
The resulting portal file is explained by this template, and the variables in the template are read from Go.json
ghostinit.php:
namespace Core; UseCore\frame\ghost_frame; classghostinit{Static $v= ' Ghost version is 1.1 '; Static functioninit () {Echo"Pls input project name?".Php_eol; $projName=fgets(STDIN); Echo"Pls input author?".Php_eol; $author=fgets(STDIN); EchoSelf::buildconfig ([' proj ' =$projName, ' Author ' =$author ] ); } Static functionBuildconfig ($info ){ return file_put_contents(GETCWD() . '/go.json ', Json_encode ($info) ) . ' bytes has written, '. ' config file has created '.Php_eol; } Static functionShow () {$conf= Self::Loadconfig (); foreach($conf as $k=$v ){ Echo $k. ‘:‘ .$v; } } Static functionLoadconfig () {returnJson_decode (file_get_contents(GETCWD() . '/go.json ' ) ); } Static functionstart () {$conf= Self::Loadconfig (); //$GF = new Core\frame\ghost_frame (Trim ($conf->proj)); Using use to introduce namespaces does not need to add namespaces every time to instantiate classes $GF=NewGhost_frame (Trim($conf-proj)); $GF->proj =Trim($conf-proj); $GF->author =Trim($conf-author); $GF-run (); } Static function__callstatic ($m,$args ){ Echo' Error function '; } }
ghost_frame.php
namespace Core\frame; classghost_frame{ Public $proj= ' '; Public $entrace _file= ' '; Public function__construct ($proj ) { $this->proj =$proj; } Public functionrun () {$dir=GETCWD() . ‘/‘ .$this-proj; !file_exists($dir) &&mkdir($dir ); Extract(Get_object_vars($this ) ); Ob_start(); include(dirname(__file__) . '/template/index.tpl ' ); $content=ob_get_contents(); Ob_end_clean(); file_put_contents($dir. '/index.php ',$content ); } }
Application:
[Email protected]:~/php/php1/ A$ tree.├──core│├──frame││├──ghost_frame.php││└──template││└──index.tpl│└──ghostinit. php├──function. Php└──ghost3Directories,5Files[email protected]:~/php/php1/ A$ ./Ghost Initpls Input project name?Applicationpls Input Author?GHOSTWU $Bytes has Written,configfileHas Created[email protected]:~/php/php1/ A$ tree.├──core│├──frame││├──ghost_frame.php││└──template││└──index.tpl│└──ghostinit. php├──function. Php├──ghost└──go.json3Directories,6Files[email protected]:~/php/php1/ A$ ./Ghost Start[email protected]:~/php/php1/ A$ tree.├──application│└──index.php├──core│├──frame││├──ghost_frame.php││└──template││ └──index.tpl│└──ghostinit.php├──function. Php├──ghost└──go.json4Directories,7Files[email protected]:~/php/php1/ A$Catapplication/index.php<?PHP/** * Project Name:application * AUTHOR:GHOSTWU * date:2018-04-29 **/ Echo "Hello Ghostwu"; [Email protected]:~/php/php1/ A$
PHP command line to generate the app's portal file by template