activecollab / etcd

PHP client for etcd, a distributed configuration system
https://labs.activecollab.com
MIT License
13 stars 6 forks source link

traversalDir() method stores in $this->dir globaly #8

Open bahamasbahamas opened 5 years ago

bahamasbahamas commented 5 years ago

Hey, if you call listSubdirs('/', true) inetcd/src/Client.php it works great but if you call listSubdirs('/', false) again you*ll getlistSubdirs('/', true). I think the problem lives in traversalDir() method in etcd/src/Client.php. It stores in $this->dir globaly.

My quick fix would be:

    public function listSubdirs($key = '/', $recursive = false)
    {
        try {
            $data = $this->dirInfo($key, $recursive);
        } catch (EtcdException $e) {
            throw $e;
        }

        $iterator = new RecursiveArrayIterator($data);

    //reset iterator array
        $this->dirs = [];

        return $this->traversalDir($iterator);
    }