php命令行按模板生成应用的入口文件
接着这篇文章php命令行生成项目结构 继续改造:
ghostwu@dev:~/php/php1/12$ tree
.
├── app
│ └── index.php
├── core
│ ├── frame
│ │ ├── ghost_frame.php
│ │ └── template
│ │ └── index.tpl
│ └── ghostinit.php
├── function.php
├── ghost
└── go.json
index.tpl:
<?php echo '<?php' . 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";
生成的入口文件就是按照这个 模板解释的, 模板中的变量从go.json读取
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 ) );
$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;
class ghost_frame{ public $proj = '';
public $entrace_file = ''; public function __construct( $proj ) {
$this->proj = $proj;
} public function run(){
$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 );
} }
应用:
ghostwu@dev:~/php/php1/$ tree
.
├── core
│ ├── frame
│ │ ├── ghost_frame.php
│ │ └── template
│ │ └── index.tpl
│ └── ghostinit.php
├── function.php
└── ghost directories, files
ghostwu@dev:~/php/php1/$ ./ghost init pls input project name?
Application
pls input author?
ghostwu
bytes has written,config file has created ghostwu@dev:~/php/php1/$ tree
.
├── core
│ ├── frame
│ │ ├── ghost_frame.php
│ │ └── template
│ │ └── index.tpl
│ └── ghostinit.php
├── function.php
├── ghost
└── go.json directories, files
ghostwu@dev:~/php/php1/$ ./ghost start ghostwu@dev:~/php/php1/$ tree
.
├── Application
│ └── index.php
├── core
│ ├── frame
│ │ ├── ghost_frame.php
│ │ └── template
│ │ └── index.tpl
│ └── ghostinit.php
├── function.php
├── ghost
└── go.json directories, files
ghostwu@dev:~/php/php1/$ cat Application/index.php
<?php
/**
* project name: Application
* author: ghostwu
* date: 2018-04-29 *
*/
echo "hello ghostwu";
ghostwu@dev:~/php/php1/$
php命令行按模板生成应用的入口文件的更多相关文章
- 由angular命令行工具(angular-cli)生成的目录和文件
e2e目录:是端到端的测试目录,包含基本的测试桩.是用来做自动测试的. src:应用源代码目录.我们写的所有代码都应该在这里面. app:包括应用的组件和模块.我们自己写的绝大部分代码都是写在这个目录 ...
- VS2010-使用“预先生成事件命令行”和“后期生成事件命令行”功能
原文:VS2010-使用"预先生成事件命令行"和"后期生成事件命令行"功能 xcopy /r /y $(TargetPath) $(ProjectDir)..\ ...
- C# “预先生成事件命令行”和“后期生成事件命令行”
概述 Visual studio 项目允许在项目属性生成事件一栏中指定预先生成和后期生成事件来实现项目生成与部署的自动化. 实例1: 我自己写了一个调试工具,该工具处于一边开发一边使用过程中.实际工作 ...
- mysql中如何在命令行中,执行一个SQL脚本文件?
需求描述: 在mysql数据库的使用中,有的时候,需要直接在shell的命令行中,执行某个SQL脚本文件, 比如,要初始化数据库,创建特定的存储过程,创建表等操作,这里进行一个基本的测试. 一般情况, ...
- Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本
Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本 在 mac 或者 linux 系统中,我们的浏览器或者其他下载软件下载的文件全部都下载再 ~/Downloads/ 文 ...
- jmeter命令行运行与生成报告
一. 使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...
- jmeter 命令行运行与生成报告
一. 使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...
- [转]轻松学习Ionic (四) 修改应用图标及添加启动画面(更新官方命令行工具自动生成)
本文转自:http://blog.csdn.net/zapzqc/article/details/42237935 由于Ionic更新了命令行工具,以后修改应用图标和添加启动画面就简单了,最新方法见最 ...
- 轻松学习Ionic (四) 修改应用图标及添加启动画面(更新官方命令行工具自动生成)
由于Ionic更新了命令行工具,以后修改应用图标和添加启动画面就简单了,最新方法见最下方: 应用图标: 1.在整个项目所在文件夹下创建res文件夹,里边再分别创建两个文件夹android和io ...
随机推荐
- 关于ajax访问webservice查询数据量稍微大一点,就会返回error500的解决方案
只需要在web.config的configeration节点中增加如下子节点即可: <system.web.extensions> <scripting> ...
- vue.js 常用组件库
vux github ui demo:https://github.com/airyland/vux Mint UI 项目主页:http://mint-ui.github.io/#!/zh-cndem ...
- 《Python黑帽子:黑客与渗透测试编程之道》 玩转浏览器
基于浏览器的中间人攻击: #coding=utf-8 import win32com.client import time import urlparse import urllib data_rec ...
- BZOJ 3940--[Usaco2015 Feb]Censoring(AC自动机)
3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 723 Solved: 360[Subm ...
- 面向对象多继承(c3算法)、网络基础和编写网络相关的程序
一.面向对象多继承(c3算法) a.有多个父类先找左,再找右,如下示例: class A(object): pass class B(object): def f1(self): print('B') ...
- canvas制作完美适配分享海报
基于mpvue实现的1080*1900小程序海报 html <canvas class="canvas" :style="'width:'+windowWidt ...
- 修改ssh远程默认端口
修改ssh远程默认端口 Linuxssh端口修改 1. 修改ssh配置文件 [root@distzabbix ~]# vim /etc/ssh/sshd_config 找到第17行附近#Port 22 ...
- JPA-style positional param was not an integral ordinal
参数错误 多为SQL语句问题 例如SQL拼装中的空格,换行时首位应多加空格保持语句效果
- 不用函数库求一个数的平方根 (java版)
一.题目 编写程序求一个整数的平方根,精确到小数点后三位 二.解法 1) 采用 牛顿迭代法. 2)牛顿迭代法简介 假设方程 在 附近有一个根,那么用以下迭代式子: ...
- 集成学习算法总结----Boosting和Bagging
1.集成学习概述 1.1 集成学习概述 集成学习在机器学习算法中具有较高的准去率,不足之处就是模型的训练过程可能比较复杂,效率不是很高.目前接触较多的集成学习主要有2种:基于Boosting的和基于B ...