2017-02-22 58 views
0

有一个特定的地址格式化作曲家插件,看起来像它对我自己的项目(不是Drupal)很有用,称为commerceguys/addressinghttps://www.versioneye.com/php/commerceguys:addressing/0.8.4)。在非Drupal站点设置Drupal作曲家包

所以我习惯了作曲家,我只是在我的项目中需要它,但似乎没有像我使用的所有其他作曲家软件包一样运作。我不确定这是否与Drupal有特别的关系,我只提到它是因为他们的自述文件提到这是一个Drupal模块(但是因为它通过作曲家可用,所以我认为它可能工作)。按照他们的文档,我使用下面的代码

use CommerceGuys\Addressing\Address; 
use CommerceGuys\Addressing\Formatter\PostalLabelFormatter; 
use CommerceGuys\Addressing\AddressFormat\AddressFormatRepository; 
use CommerceGuys\Addressing\Repository\CountryRepository; 
use CommerceGuys\Addressing\Subdivision\SubdivisionRepository; 

$addressFormatRepository = new AddressFormatRepository(); 
$countryRepository = new CountryRepository(); 
$subdivisionRepository = new SubdivisionRepository(); 
// Defaults to text rendering. Requires setting the origin country code 
// (e.g. 'FR') through the constructor or the setter, before calling format(). 
$formatter = new PostalLabelFormatter($addressFormatRepository, $countryRepository, $subdivisionRepository, 'FR', 'fr'); 

$address = new Address(); 
$address = $address 
    ->withCountryCode('US') 
    ->withAdministrativeArea('CA') 
    ->withLocality('Mountain View') 
    ->withAddressLine1('1098 Alta Ave'); 

echo $formatter->format($address); 

但是,这是给我这个错误

Fatal error: Uncaught Error: Class 'CommerceGuys\Addressing\AddressFormat\AddressFormatRepository' not found in /media/sf_domains/coolproject.com/public_html/coolfile.php on line 8

似乎没有要与安装,所有的“commerceguys”文件中的任何问题位于“供应商”文件夹中的正确位置。我通过作曲家安装了大约6件左右的工作,没有任何问题。我错过了什么?

回答

0

实际上,它看起来像它们的文档在“use”子句中显然不正确。在文件本身手动搜索后,我想出了

use CommerceGuys\Addressing\Model\Address; 
use CommerceGuys\Addressing\Formatter\DefaultFormatter; 
use CommerceGuys\Addressing\Repository\AddressFormatRepository; 
use CommerceGuys\Addressing\Repository\CountryRepository; 
use CommerceGuys\Addressing\Repository\SubdivisionRepository; 

这实际上现在工作很好。