文件结构如下:
index.php
composer.json
composer.lock
-lib
--books
---SearchClient.php (contains class books\SearchClient
以下docker-compose.yml + PHP可在Windows上运行:
{
"name" : "keithdavis/books",
"description" : "",
"version" : "0.1",
"minimum-stability": "beta",
"require" : {
"ext-curl" : "*",
"ext-json" : "*",
"guzzlehttp/guzzle": "^6.3"
},
"autoload" : {
"psr-4": {
"books\\": "lib"
}
}
}
<?php
use books\SearchClient;
require_once __DIR__."/vendor/autoload.php";
$oSearchClient = new SearchClient();
但是,在macOS(Mojave)上:
( ! ) Fatal error: Uncaught Error: Class 'books\SearchClient' not found in /var/www/html/search.php on line 6
( ! ) Error: Class 'books\SearchClient' not found in /var/www/html/search.php on line 6
Call Stack
# Time Memory Function Location
1 0.0032 416944 {main}( ) .../search.php:0
在调试中,似乎出现了路径“ lib”是问题,但是我尝试了“ / lib”,但这也不起作用。我认为也许我没有正确安装Composer。我是Windows上经验丰富的PHP开发人员,但对Mac来说还相对较新,因此我并不是100%知道在Mac上安装Composer的最佳方法。我在全球范围内遵循以下说明:
答案 0 :(得分:1)
查看您的文件结构,您搜索客户端类的名称空间需要为
func exp(_ s : String, _ term: String) -> String{ //term_inator: Any Char not in the Sequence.
guard let first = s.first else {return ""}
return """
\(s.dropFirst().appending(term).reduce(("\(first)",1)){ r, c in
let t = c == r.0.last!
let tc = t ? r.1 : 0
let tb = t ? "" : "\(c)"
let ta = t ? "" : r.1 > 2 ? "\(r.1)" : r.1 == 2 ? "\(r.0.last!)" : ""
return (r.0 + ta + tb, tc + 1)
}.0.dropLast())
"""}
print(exp(initialString, " "))
let initialString = "abbbaaa" // ab3a3
let initialString = "aahhhgggg" // aah3g4
let initialString = "aabbaa" // aabbaa
这是因为要在lib文件夹上设置名称空间书。您可以通过添加
将自动装带器直接指向书本文件夹,而不是在命名空间中使用书本两次namespace books\books;
请确保在更改自动加载时运行{
"name" : "keithdavis/books",
"description" : "",
"version" : "0.1",
"minimum-stability": "beta",
"require" : {
"ext-curl" : "*",
"ext-json" : "*",
"guzzlehttp/guzzle": "^6.3"
},
"autoload" : {
"psr-4": {
"books\\": "lib/books"
}
}
}
,以便重建名称空间。
希望这会有所帮助。