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 ); 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命令行生成项目结构的更多相关文章
- cocos命令行生成项目
cocos命令行生成项目: cocos new GoodDay(项目名称) -p com.boleban.www(包名字) -l cpp(项目类型) -d D:\DevProject\cocos2dx ...
- Maven 命令行创建项目时 Could not find goal ‘create’ in plugin org.apache.maven.plugins:...
使用maven3.3.9 版本,进行命令行创建项目时输入以下命令创建失败 mvn archetype:create -DgroupId=com.zang.maven -DartifactId=sys ...
- thinkphp命令行生成模型类
thinkphp命令行生成模型类 当你需要创建大量的模型类的时候,不妨考虑下命令行生成,可以快速创建模型类. 在windows下面,使用Win+R输入cmd进入命令控制台,切换到项目根目录(也就是th ...
- 《Entity Framework 6 Recipes》中文翻译系列 (40) ------ 第七章 使用对象服务之从跟踪器中获取实体与从命令行生成模型(想解决EF第一次查询慢的,请阅读)
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 7-5 从跟踪器中获取实体 问题 你想创建一个扩展方法,从跟踪器中获取实体,用于数 ...
- egret命令行编译项目时 版本不对应的问题
egret 命令行编译项目时 如使用 egret build -e 会出现版本不对应的问题 分析原因 A,B项目 A项目使用1.8的egret引擎, B项目使用2.5引擎 但本地引擎升级至2.5.5, ...
- Beyond Compare 命令行生成目录下所有文件比对的Html网页report
MAC环境下,使用Beyond Compare命令行生成两个文件夹差异的html,按目录递归生成. #1. 创建compare #2. 创建compare/old #3. compare/new #4 ...
- 用OpenSSL命令行生成证书文件
用OpenSSL命令行生成证书文件 1.首先要生成服务器端的私钥(key文件): openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加 ...
- mysql中用命令行复制表结构(数据)
mysql中用命令行复制表结构的方法主要有一下几种: 1.只复制表结构到新表 CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2; 或 CREATE TABLE 新表 ...
- Jmeter之命令行生成HTML报告
其实每次使用jemter.bat文件启动JMeter时,命令行窗口都会提示我们不要使用GUI窗口进行测试,除非是进行调试脚本 使用命令行生成结果也很测试报告也很简单 jmeter -n -t [jmx ...
随机推荐
- Python 读取文件中unicode编码转成中文显示问题
Python读取文件中的字符串已经是unicode编码,如:\u53eb\u6211,需要转换成中文时有两种方式 1.使用eval: eval("u"+"\'" ...
- 配置iSCSI部署网络存储
iSCSI( Internet Small Computer System Interface 互联网小型计算机系统接口)是由IBM 下属的两大研发机构一一加利福尼亚AImaden和以色列Haifa研 ...
- [学习笔记]普通平衡树Splay
哈哈哈哈哈哈哈终于会打\(splay\)啦 现在我来发一下\(splay\)的讲解吧 小蒟蒻由于码风与他人不同,所以自己找了上百篇码风诡异的\(splay\)合成的,感谢\(zcysky\)的代码与我 ...
- linux(乌班图)下执行pip没有问题,执行sudo pip报错的问题
最近刚装好linux的虚拟机,在装一个套件时提示权限不足,于是添加上了 sudo 命令,结果直接报以下错误, Traceback (most recent call last): File " ...
- vue教程1-08 交互 get、post、jsonp
vue教程1-08 交互 get.post.jsonp 一.如果vue想做交互,引入: vue-resouce 二.get方式 1.get获取一个普通文本数据: <!DOCTYPE html&g ...
- java中连接各种数据的方法
1.oraclethin驱动连接字符串:jdbc:oracle:thin:用户名/密码@localhost:1521:cake驱动类:oracle.jdbc.driver.OracleDriver 2 ...
- 使用.NetCore在Linux上写TCP listen 重启后无法绑定地址
拥抱.net core的过程中, 将公司的一套java项目改成了.net core 2.0版的. 里面的tcp服务被我用msdn的SocketAsyncEventArgs方式重写了, 然而在测试的过程 ...
- JDK8 - Function介绍
注:写这个文档只是为了方便加深记忆,加强理解,重点关注两个default方法中泛型[V]. JDK8作为一个还在维护阶段的长期版本,势必会在企业应用中占据相当大的市场份额,所以还是以JDK8作为例子的 ...
- Azure Storage架构介绍
Windows Azure Storage由三个重要部分或者说三种存储数据服务组成,它们是:Windows Azure Blob.Windows Azure Table和Windows Azure Q ...
- Android Design Support Library——Navigation View
前沿 Android 从5.0开始引入了Material design元素的设计,这种新的设计语言让整个安卓的用户体验焕然一新,google在Android Design Support Librar ...