2017-02-22 60 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; 

這實際上現在工作很好。