0

I develop git repository, that contains only one useful file data.json. Another repo which I develop in parallel is php implementation of idea.

And now I need to load list from data.json, parse it and then use. First and most obvious idea was write some Loader class, which will try to access this file by 2 ways:

  • __DIR__ . '/../vendor/ely/anti-tempmail-list/data.json. That case will be worked if we have library itself with its dependencies.

  • __DIR__ . '/../../anti-tempmail-list/data.json. That case will be worked if library is included as another composer dependency.

But it's a bit horrible, 'cause crawl on file system is "dirty". And in case of package replacement (hello forks) it will stop working.

Another solution is create in reference repository some language-dependent Loader classes, which will be implement loading for data file. But I'm not sure that this is also a good solution...

So I ask you, how should I organize communication with the reference repository (data.json) to implementation by some programming language?

P.S. reference repo contains russian README, but on release it will be translated as it should be ;)

1 Answers1

1

If you develop a PHP package, you should provide a simple PHP class that can be used to get the list from that JSON file:

require `vendor/autoload.php`;

$list = \Elyby\Json::getList();

Implementation:

<?php
namespace Elyby;

class Json
{
    /**
     * @return array
     */
    public static function getList()
    {
        return json_decode(__DIR__.'/data.json', true);
    }
}

Autoloading has to be configured as well.

Sven
  • 69,403
  • 10
  • 107
  • 109
  • Yes, this is one of solutions. But it's means, that every language (I suppose that the community develop another implementations, if they found this list helpful) will create his own loaders into reference repository... Is it normal? – ErickSkrauch Apr 27 '16 at 21:14