意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

phplaravel框架自带命令的实现

来源:恒创科技 编辑:恒创科技编辑部
2024-01-11 09:38:59
这篇文章主要讲解了“php laravel框架自带命令的实现”,文中的讲解内容简单、清晰、详细,对大家学习或是工作可能会有一定的帮助,希望大家阅读完这篇文章能有所收获。下面就请大家跟着小编的思路一起来学习一下吧。


在PHP的框架学习中,我们已经对laravel的安装和配置有所掌握,那么除此之外,在该框架中有一种自带命令,不知道小伙伴们有没有在使用的时候留意过呢?之前没有接触过artisan的也不要着急,本篇就laravel框架自带命令会带来使用的步骤介绍,一起来看看接下来的命令实现吧。


phplaravel框架自带命令的实现

1、作为服务提供者,加载到程序中。

//config/app.php中。
'providers'=>[
//这个便是laravel自带的artisan命令提供者
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
]

2、然后找到 Up/Down命令入口

/**
*Registerthecommand.
*
*@returnvoid
*/
protectedfunctionregisterUpCommand()
{
$this->app->singleton('command.up',function(){
returnnewUpCommand;
});
}

3、DownCommand实现

classDownCommandextendsCommand
{
/**
*Theconsolecommandname.
*
*@varstring
*/
protected$name='down';

/**
*Theconsolecommanddescription.
*
*@varstring
*/
protected$description='Puttheapplicationintomaintenancemode';

/**
*Executetheconsolecommand.
*
*@returnvoid
*/
publicfunctionfire()
{
//关键点:在当前存储目录/framework下面创建一个down文件
touch($this->laravel->storagePath().'/framework/down');

$this->comment('Applicationisnowinmaintenancemode.');
}
}


//touch()函数php文档解释
/**
*Setsaccessandmodificationtimeoffile
*@linkhttp://php.net/manual/en/function.touch.php
*@paramstring$filename<p>
*Thenameofthefilebeingtouched.
*</p>
*@paramint$time[optional]<p>
*Thetouchtime.Iftimeisnotsupplied,
*thecurrentsystemtimeisused.
*</p>
*@paramint$atime[optional]<p>
*Ifpresent,theaccesstimeofthegivenfilenameissetto
*thevalueofatime.Otherwise,itissetto
*time.
*</p>
*@returnbooltrueonsuccessorfalseonfailure.
*@since4.0
*@since5.0
*/
functiontouch($filename,$time=null,$atime=null){}


到此这篇关于“php laravel框架自带命令的实现”的文章就介绍到这了,更多相关内容请搜索恒创科技以前的文章或继续浏览下面的相关文章,希望大家以后多多支持恒创科技!
上一篇: 专业名词缩写 下一篇: 手机怎么远程登录云服务器?