Since I couldn’t find a proper documentation and examples for flysystem, I am asking you for help. Currently I am developing a plugin (for Shopware 6), and I am using some sources that are stored inside my plugin (such as pictures, and csv files).
The structure looks like this

|-- custom
   |-- plugins
       |-- ImporterPlugin
          |-- src
            |-- Adapter
              |-- CsvImportAdapter.php
              |-- ImportAdapterInterface.php
            |-- Command
              |-- ImportCommand.php
            |-- Factory
              |-- AdapterFactory.php
            |-- Resources
            |-- Service
            |-- ImporterPlugin.php
          |-- upload
            |-- product.csv
            |-- media
              |-- Image1.jpg

在.env中,我编写了所需的文件路径

IMPORT_CSV_PATH=/var/www/html/custom/plugins/ImporterPlugin/upload/products.csv
IMPORT_MAP_PATH=/var/www/html/custom/plugins/ImporterPlugin/src/Resources/maps/product.map.json

PRODUCTIMPORTER_MEDIA_SOURCE_PATH=/var/www/html/custom/plugins/ImporterPlugin/upload/media/

我的问题是,如何实现本地适配器(FlySystem)?在哪里调用函数/方法呢?插件的功能主要是在命令行中调用.请举几个例子.谢谢

推荐答案

在您的services.xml个插件中,您可以使用FileSystemFactory和一组参数来定义文件系统抽象.

<service class="League\Flysystem\FilesystemInterface" id="importer_plugin.filesystem.private" public="true">
    <factory service="Shopware\Core\Framework\Adapter\Filesystem\FilesystemFactory" method="factory"/>
    <argument type="collection">
        <argument key="type">local</argument>
        <argument key="config" type="collection">
            <argument key="root">%kernel.plugin_dir%/ImporterPlugin/upload</argument>
        </argument>
    </argument>
</service>

然后,您可以将importer_plugin.filesystem.private注入到其他服务中,并使用以upload目录为根的文件系统抽象.

public function __construct(FilesystemInterface $filesystem)
{
    $this->filesystem = $filesystem;
}

// ...

$products = $this->filesystem->read('products.csv');

Php相关问答推荐

谷歌云SQL / mysql谁是对的?

FatFreeFramework上的不同路由

在保留唯一键值对的情况下高效合并嵌套数组

从WooCommerce订单状态更改更新用户自定义元数据

添加登录:需要app.yaml仍然允许所有拥有Google帐户的人访问

按与WooCommerce管理顺序列表中的特定字符串不匹配的特定元值筛选订单

WordPress插件和JSON不是有效的响应错误

在PHP中使用curl命令执行SCRAPYD操作.json不返回任何内容

在Laravel中从动态嵌套数组中获取值

在WooCommerce中添加特定产品类型的百分比费用和固定费用

是否使用联系人表单7 wpcf7_Feedback_Response输出答复中的html?

如何在WordPress REST API中判断应用程序密码

为什么PHP PDO忽略NOT NULL约束?

在WooCommerce购物车页面应用优惠券不会';t刷新总计

调用模型[App\Models\Employee]上未定义的关系[title]

从 WooCommerce 购物车中删除总计部分,同时保留小计行

如何在 PHP 中以 hh:mm:ss 格式获取两个 strtotime datetime/s 之间的时间差

根据WooCommerce中的产品重量更改简单产品的输入数量步值

在帖子内容中使用短代码触发 Woocommerce 挂钩

Laravel - 关联与设置观察者事件的 ID