doutan2111 2015-08-22 09:30
浏览 103
已采纳

我应该如何在composer包中包含XML数据文件?

I'm working on a PHP library (as a composer package) that needs a XML file to work. I'm using simplexml_load_file to load the XML file, but I'm wondering where I should put the file and how to get a path that always works. The current file structure looks like this is:

/
  src/
    Vendor/
      Library.php
  tests/
    LibraryTest.php
  composer.json
  composer.lock

My composer.json file :

{
    "name": "vendor/library",
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "psr-0": {
            "Vendor": "src/"
        }
    }
}
  • 写回答

1条回答 默认 最新

  • duannan4486 2015-08-22 09:36
    关注

    You can't do this directly, but there are some possibilities:

    1. Create a private repository which will contain only your XML file and add it to your composer. You'll then find it in your vendor folder. Here you can find a documentation about how to create custom repos: https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md

    2. Save it in your application, in some data folder and add to a GIT.

    3. Add a simple checking to your application, so if the XML file hasn't been found, display message with information how to get it.

    I'd recommend to mix points 2 and 3.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度