【问题标题】:Setting up a Drupal composer package in a non-Drupal site在非 Drupal 站点中设置 Drupal Composer 包
【发布时间】:2017-02-22 17:32:14
【问题描述】:

有一个特殊的地址格式化作曲家插件,它看起来对我自己的项目(不是 Drupal)非常有用,名为 commerceguys/addressing (https://www.versioneye.com/php/commerceguys:addressing/0.8.4)。

所以我习惯了作曲家,我只是在我的项目中需要它,但它似乎不像我正在使用的所有其他作曲家包那样运作。我不确定这是否与 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);

但这给了我这个错误

致命错误:未捕获的错误:在第 8 行的 /media/sf_domains/coolproject.com/public_html/coolfile.php 中找不到类“CommerceGuys\Addressing\AddressFormat\AddressFormatRepository”

安装似乎没有任何问题,所有“commerceguys”文件都位于“vendor”文件夹中的正确位置。我确实通过作曲家安装了大约 6 个其他东西,这些东西可以正常工作。我错过了什么?

【问题讨论】:

    标签: php drupal composer-php


    【解决方案1】:

    实际上,当涉及到“使用”子句时,他们的文档看起来完全不正确。在文件本身中手动搜索它们之后,我想出了

    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;
    

    现在实际上效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      • 2016-02-28
      相关资源
      最近更新 更多