Skip to content
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

Merged
merged 6 commits into from Aug 5, 2019

Conversation

wenbinye
Copy link
Contributor

@wenbinye wenbinye commented Aug 4, 2019

不是所有项目都会按 hyperf 定的命名规则。我们公司之前项目的命名规则类似 java ,名字空间使用小写字母开始,代码位于 src 目录下。而且也不能强制项目都使用 App 这样的命名空间。
所以最好的方式是从 composer.json 中 psr-4 规则推导路径和命名空间之间的转换

@huangzhhui
Copy link
Member

@wenbinye 这个 PR 你提供几个具体的命名规则,我们也验证一些

@wenbinye
Copy link
Contributor Author

wenbinye commented Aug 4, 2019

不用设置特别的命名规则,就是按 PSR-4 规范就行了。我们公司现在的命名是所有项目代码在 src 目录下,名字空间为 winwin{project},autoload 配置是:

{
  "autoload": {
    "psr-4": {
      "winwin\\fooProject\\": "src/"
    }
  }
}

@limingxinleo
Copy link
Member

我觉得这个还是挺有用的

@huangzhhui
Copy link
Member

@wenbinye 你的 Git Config 貌似还是有问题,你的 commit 记录依旧没能被 Github 识别出现在 https://github.com/hyperf-cloud/hyperf/graphs/contributors 中,你需要配置一下你 Git 的 Email 跟 Github 的账号一致

*/
class Project
{
public function namespaceFor(string $path): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太理解 namespaceFor 里面的 for 体现什么意思?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 For 就跟 byPath 一样。。。以前我习惯这里命名是 namespaceByPath,但是后来就觉得很累赘,所以现在都是直接 namespace

@limingxinleo
Copy link
Member

@huangzhhui 抽空再看一下,没啥问题我就合并了

@limingxinleo limingxinleo merged commit e356ca9 into hyperf:master Aug 5, 2019
@wenbinye wenbinye deleted the feature-path-from-psr4-rule branch August 6, 2019 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants