doutan2111
2015-08-22 09:30
浏览 102

我应该如何在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/"
        }
    }
}

图片转代码服务由CSDN问答提供 功能建议

我正在开发一个需要XML文件才能工作的PHP库(作为编写器包)。 我正在使用 simplexml_load_file 来加载XML文件,但我想知道我应该把文件放在哪里以及如何获得始终有效的路径。 当前的文件结构如下所示:

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

我的 composer.json 文件:

   {
“name”:“vendor / library”,
“require”:{
“php”:“> = 5.3.0”
},
“autoload”:{
“psr-  0“:{
”供应商“:”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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题