在我的composer.json文件中,我写了:
"autoload": {
"psr-4": {
"Pmochine\\MyOwnPackage\\": "src/"
},
"files": [
"src/helpers.php"
]
},
Run Code Online (Sandbox Code Playgroud)
但是,即使在作曲家转储-自动加载后,功能也无法加载。我得到“调用未定义函数”。为了创建包,我使用了包生成器。也许它可以在供应商文件夹中创建符号链接?
我写的内部帮手
<?php
if (! function_exists('myowntest')) {
function myowntest()
{
return 'test';
}
}
Run Code Online (Sandbox Code Playgroud)
在包服务提供者中,尝试添加以下内容:
// if 'src/helpers.php' does not work, try with 'helpers.php'
if (file_exists($file = app_path('src/helpers.php'))) {
require $file;
}
Run Code Online (Sandbox Code Playgroud)
您正在做的事情是最佳实践并且应该有效。我以 barryvdh/laravel-debugbar 中的composer.json 为例。https://github.com/barryvdh/laravel-debugbar/blob/master/composer.json
{
"name": "barryvdh/laravel-debugbar",
"description": "PHP Debugbar integration for Laravel",
"keywords": ["laravel", "debugbar", "profiler", "debug", "webprofiler"],
"license": "MIT",
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"require": {
"php": ">=5.5.9",
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*",
"symfony/finder": "~2.7|~3.0",
"maximebf/debugbar": "~1.13.0"
},
"autoload": {
"psr-4": {
"Barryvdh\\Debugbar\\": "src/"
},
"files": [
"src/helpers.php"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我的猜测是,您不需要在主composer.json 中以正确的方式使用自己的包?
| 归档时间: |
|
| 查看次数: |
643 次 |
| 最近记录: |