我正在尝试使用composer vimeo包"vimeo/vimeo-api":"dev-master"。
在composers自己的ClassLoader.php中,情况变得很糟糕,在下面的函数中,它达到了:if (0 === strpos($class, $prefix))
,并脱离了循环,因为在这一点上$class = 'Vimeo'
和$prefix = 'Vimeo/'
,所以结果是false。
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
...
vimeo包中的composer.json文件声明了"vimeo\"的psr-4自动加载,如下所示:
{
"name": "vimeo/vimeo-api",
"description": "Official PHP library for the Vimeo API.",
"homepage": "https://github.com/vimeo/vimeo.php",
"keywords": ["vimeo", "video"],
"license": "Apache-2.0",
"authors": [
{
"name": "Vimeo",
"homepage": "http://vimeo.com"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"Vimeo\": "src/Vimeo"
}
}
}
composer创建的autoload_psr4.php如下:
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Vimeo\' => array($vendorDir . '/vimeo/vimeo-api/src/Vimeo')
);
因此,当我实例化类"new Vimeo('arg','arg');"我得到一个类未找到错误。
这可能是因为我在Zendframework(1.12.8)内部运行,或者作曲家搞砸了什么?
右侧。一位同事找到了解决方案:我们需要在实例化composer托管类时为composer使用的命名空间加前缀。因此new VimeoVimeo($foo, $bar)
起作用,或者将use VimeoVideo
放在创建实例new Vimeo($foo, $bar)
之前。