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 ); var_dump( $projName, $author ); 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 = self::loadConfig();
foreach( $conf as $k => $v ){
echo $k . ':' . $v;
}
} static function loadConfig(){
return json_decode( file_get_contents( getcwd() . '/go.json' ) );
} static function start(){
$conf = self::loadConfig();
$dir = getcwd() . '/' . trim( $conf->proj );
!file_exists( $dir ) && mkdir( $dir );
!file_exists( $dir . '/index.php' ) && file_put_contents( $dir . '/index.php', '' );
} static function __callstatic( $m, $args ){
echo 'error function';
} } ?>

用法:

ghostwu@dev:~/php/php1/$ ls
ghost ghostinit.php
ghostwu@dev:~/php/php1/$ ./ghost init
pls input project name?
hello
pls input author?
ghostwu
string() "hello
"
string() "ghostwu
"
bytes has written,config file has created ghostwu@dev:~/php/php1/$ ls
ghost ghostinit.php go.json
ghostwu@dev:~/php/php1/$ ./ghost start ghostwu@dev:~/php/php1/$ ls
ghost ghostinit.php go.json hello
ghostwu@dev:~/php/php1/$ tree hello
hello
└── index.php directories, file
ghostwu@dev:~/php/php1/$

用类来单独改造

ghost_frame.php

<?php
class ghost_frame{ public $proj = '';
public $entrace_file = ''; public function __construct( $proj ) {
$this->proj = $proj;
$dir = getcwd() . '/' . $proj;
!file_exists( $dir ) && mkdir( $dir );
!file_exists( $dir . '/index.php' ) && file_put_contents( $dir . '/index.php', '' );
} }
?>

ghostinit.php,由于调用了ghost_frame,需要在ghostinit.php中require这个文件

         static function start(){
$conf = self::loadConfig();
$gf = new ghost_frame( trim( $conf->proj ) );
}

当然我们可以用自动加载来改造

首先,建立框架的目录结构,类似于thinkphp( Library\Thinkphp.php )

ghostwu@dev:~/php/php1/10$ ls
core ghost ghostinit.php go.json hello
ghostwu@dev:~/php/php1/10$ tree core
core
└── frame
├── ghost_frame.php
└── template
ghostwu@dev:~/php/php1/$ tree
.
├── core
│   └── frame
│   ├── ghost_frame.php
│   └── template
├── ghost
├── ghostinit.php
├── go.json
└── hello
└── index.php

完整的ghostinit.php

<?php
use core\frame\ghost_frame;
function __autoload( $className ) {
$className = str_replace( '\\', '/', $className );
require( $className . '.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 = self::loadConfig();
foreach( $conf as $k => $v ){
echo $k . ':' . $v;
}
} static function loadConfig(){
return json_decode( file_get_contents( getcwd() . '/go.json' ) );
} static function start(){
$conf = self::loadConfig();
//$gf = new core\frame\ghost_frame( trim( $conf->proj ) );
//用use引入命名空间 就不需要每次都加上命名空间去实例化类
$gf = new ghost_frame( trim( $conf->proj ) );
} static function __callstatic( $m, $args ){
echo 'error function';
} } ?>

ghost_frame.php

<?php
namespace core\frame;
class ghost_frame{ public $proj = '';
public $entrace_file = ''; public function __construct( $proj ) {
$this->proj = $proj;
$dir = getcwd() . '/' . $proj;
!file_exists( $dir ) && mkdir( $dir );
!file_exists( $dir . '/index.php' ) && file_put_contents( $dir . '/index.php', '' );
} }
?>

最后的改造:

ghostwu@dev:~/php/php1/$ tree
.
├── core
│   ├── frame
│   │   ├── ghost_frame.php
│   │   └── template
│   └── ghostinit.php
├── function.php
├── ghost
├── go.json
└── hello
└── index.php

ghost:

 #!/usr/bin/php
<?php
use core\ghostinit;
require_once( 'function.php' );
$result = ''; if( $argc >= 2 ) {
$p = $argv[1];
//如果以 '-' 开头, 表示属性
if( substr( $p, 0, 1 ) == '-' ) {
// -v变成v
$p = substr( $p, 1 );
$result = isset( ghostinit::$$p ) ? ghostinit::$$p : 'error';
}else {
$result = ghostinit::$p();
}
} echo $result . PHP_EOL;

ghostinit.php

namespace core;
use core\frame\ghost_frame;
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 = self::loadConfig();
foreach( $conf as $k => $v ){
echo $k . ':' . $v;
}
} static function loadConfig(){
return json_decode( file_get_contents( getcwd() . '/go.json' ) );
} static function start(){
$conf = self::loadConfig();
//$gf = new core\frame\ghost_frame( trim( $conf->proj ) );
//用use引入命名空间 就不需要每次都加上命名空间去实例化类
$gf = new ghost_frame( trim( $conf->proj ) );
} static function __callstatic( $m, $args ){
echo 'error function';
} }

php命令行生成项目结构的更多相关文章

  1. cocos命令行生成项目

    cocos命令行生成项目: cocos new GoodDay(项目名称) -p com.boleban.www(包名字) -l cpp(项目类型) -d D:\DevProject\cocos2dx ...

  2. Maven 命令行创建项目时 Could not find goal ‘create’ in plugin org.apache.maven.plugins:...

    使用maven3.3.9 版本,进行命令行创建项目时输入以下命令创建失败 mvn archetype:create -DgroupId=com.zang.maven  -DartifactId=sys ...

  3. thinkphp命令行生成模型类

    thinkphp命令行生成模型类 当你需要创建大量的模型类的时候,不妨考虑下命令行生成,可以快速创建模型类. 在windows下面,使用Win+R输入cmd进入命令控制台,切换到项目根目录(也就是th ...

  4. 《Entity Framework 6 Recipes》中文翻译系列 (40) ------ 第七章 使用对象服务之从跟踪器中获取实体与从命令行生成模型(想解决EF第一次查询慢的,请阅读)

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 7-5  从跟踪器中获取实体 问题 你想创建一个扩展方法,从跟踪器中获取实体,用于数 ...

  5. egret命令行编译项目时 版本不对应的问题

    egret 命令行编译项目时 如使用 egret build -e 会出现版本不对应的问题 分析原因 A,B项目 A项目使用1.8的egret引擎, B项目使用2.5引擎 但本地引擎升级至2.5.5, ...

  6. Beyond Compare 命令行生成目录下所有文件比对的Html网页report

    MAC环境下,使用Beyond Compare命令行生成两个文件夹差异的html,按目录递归生成. #1. 创建compare #2. 创建compare/old #3. compare/new #4 ...

  7. 用OpenSSL命令行生成证书文件

    用OpenSSL命令行生成证书文件 1.首先要生成服务器端的私钥(key文件): openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加 ...

  8. mysql中用命令行复制表结构(数据)

    mysql中用命令行复制表结构的方法主要有一下几种: 1.只复制表结构到新表 CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2; 或 CREATE TABLE 新表 ...

  9. Jmeter之命令行生成HTML报告

    其实每次使用jemter.bat文件启动JMeter时,命令行窗口都会提示我们不要使用GUI窗口进行测试,除非是进行调试脚本 使用命令行生成结果也很测试报告也很简单 jmeter -n -t [jmx ...

随机推荐

  1. [学习笔记]普通平衡树Splay

    哈哈哈哈哈哈哈终于会打\(splay\)啦 现在我来发一下\(splay\)的讲解吧 小蒟蒻由于码风与他人不同,所以自己找了上百篇码风诡异的\(splay\)合成的,感谢\(zcysky\)的代码与我 ...

  2. Shell - 简明Shell入门04 - 判断语句(If)

    示例脚本及注释 #!/bin/bash var=$1 # 将脚本的第一个参数赋值给变量var if test $var # test - check file types and compare va ...

  3. python安装mysqlclient模块报fatal error: Python.h:解决方法

    在搭建Flask框架安装mysqlclient模块时候老是报fatal error: Python.h:错误,折腾老半天,百度了老半天看了不少大神帖子,就是没解决, 后来发现这不是个BUG,都是自己的 ...

  4. Windows+MyEclipse+MySQL【连接数据库报错caching_sha2_password】

    在MyEclipse中打开[窗口]->[显示视图]-> MyEclipse Database Browser -> (图片里倒三角)New.... ①Driver template: ...

  5. MVC3学习:利用jquery+ajax生成二维码(支持中文)

    二维码越来越热火了,做电子商务网站,不做二维码,你就OUT了. 一.下载DLL文件(ThoughtWorks.QRCode.dll),并在项目中引用.点此下载 如果你还不知道什么是QRCode二维码, ...

  6. Selenium自动化测试Python二:WebDriver基础

    WebDriver基础 欢迎阅读WebDriver基础讲义.本篇讲义将会重点介绍Selenium WebDriver的环境搭建和基本使用方法. WebDriver环境搭建 Selenium WebDr ...

  7. asp.net调用js方法

    C#前台js调用后台代码 前台js <script type="text/javascript" language="javascript"> fu ...

  8. 单例模式——java设计模式

    单例模式 目录: 一.何为单例 二.使用Java EE实现单例模式 三.使用场景 一.何为单例 确保一个类只有一个实例,并且提供了实例的一个全局访问点 1.1 单例模式类图               ...

  9. 互联网IP地址的分配

    IP地址分类 互联网上的每个接口必须有一个唯一的 Internet 地址(也称作 I P 地址). IP 地址长 32 bit .IP 地址具有一定的结构,五类不同的互联网地址格式.    区分各类地 ...

  10. 微信小程序——<radio></radio>大小改变

    css样式改变大小: transform:scale(.7);