Laravel:在哪里添加启动和启动回调? [英] Laravel: Where to Add booted and booting Callbacks?

查看:33
本文介绍了Laravel:在哪里添加启动和启动回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Laravel应用程序的主要对象有两种方法, booting booted .这些方法使您可以配置回调.应用程序对象将在启动之前和之后调用这些回调.

The main Laravel application object has two methods, booting and booted. These methods allow you to configure callbacks. The application object will call these callbacks before and after it boots.

作为Laravel应用程序开发人员,我可以在哪里参与这些事件?看一下框架,好像是

Where, as a Laravel application developer, can I hook into these events? Looking at the framework it seems like

bootstrap/start.php

是显而易见的地方-但是,如果我在此处放置代码,它将在下一次更新中更改.还有

is the obvious place — but if I put code here it'll be zapped in the next update. There's also

start/global.php
statt/{$env}.php

但是这些文件实际上是 booted 回调所必需的,这意味着 booting 回调点将不可用.

but these files are actually required in by a booted callback, which means the booting callback point would be unavailable.

作为Laravel应用程序开发人员,我是否有合适的位置参加这些事件?还是为核心框架开发人员提供了 booting booted ?还是我做出了一个我什至不知道的错误假设?Laravel 4.2.6,但是如果有其他版本的上下文,我很想听听.

Is there an intended place for me to hook into these events as a Laravel application developer? Or are booting and booted there for the core framework developers? Or has I made an incorrect assumption that I'm not even aware of? Laravel 4.2.6, but if there's context from additional versions I'd love to hear about it.

Laravel的新手,不是编程的新手.尚未要求特定任务(只是),只是要了解什么是最佳实践/预期用途是什么,什么不是最佳实践.

New to Laravel, not new to programming. Not asking for a specific task (yet), just getting a feel for what best practices/intended use is and is not.

推荐答案

作为正式答案,此行为没有定义的位置.但是,请注意您对 start.php 的评论,当您更新laravel时,该文件将不会压缩".

As a formal answer, there's no defined place for this behaviour. But a note against your comments about start.php, this file will not be "zapped" when you update laravel.

只要文件不在vendors文件夹中,任何laravel更新都不会更改您的文件. start.php 是在创建基础项目时生成的,但不应通过进一步的更新进行更改.

As long as a file is not within the vendors folder, any laravel updates won't change your files. start.php is generated when you create a base project, but should not be changed with further updates.

composer创建项目负责创建基本的骨架"应用程序,并且您执行的任何 composer更新都只会修改供应商文件夹中的文件.请记住,不要修改供应商文件夹中的文件,您会没事的!

composer create-project is responsible for creating your base "skeleton" application, and any composer update that you do will just modify files in the vendor folder. Just remember, do not modify files in the vendor folder and you will be fine!

这篇关于Laravel:在哪里添加启动和启动回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆