New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support convert path and namespace from composer psr-4 autoload rules #328
support convert path and namespace from composer psr-4 autoload rules #328
Conversation
@wenbinye 这个 PR 你提供几个具体的命名规则,我们也验证一些 |
不用设置特别的命名规则,就是按 PSR-4 规范就行了。我们公司现在的命名是所有项目代码在 src 目录下,名字空间为 winwin{project},autoload 配置是: {
"autoload": {
"psr-4": {
"winwin\\fooProject\\": "src/"
}
}
} |
我觉得这个还是挺有用的 |
@wenbinye 你的 Git Config 貌似还是有问题,你的 commit 记录依旧没能被 Github 识别出现在 https://github.com/hyperf-cloud/hyperf/graphs/contributors 中,你需要配置一下你 Git 的 Email 跟 Github 的账号一致 |
src/utils/src/CodeGen/Project.php
Outdated
*/ | ||
class Project | ||
{ | ||
public function namespaceFor(string $path): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不太理解 namespaceFor
里面的 for
体现什么意思?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 For 就跟 byPath 一样。。。以前我习惯这里命名是 namespaceByPath,但是后来就觉得很累赘,所以现在都是直接 namespace
@huangzhhui 抽空再看一下,没啥问题我就合并了 |
不是所有项目都会按 hyperf 定的命名规则。我们公司之前项目的命名规则类似 java ,名字空间使用小写字母开始,代码位于 src 目录下。而且也不能强制项目都使用 App 这样的命名空间。
所以最好的方式是从 composer.json 中 psr-4 规则推导路径和命名空间之间的转换