public function build()
 {
     \yii\base\Event::on(\denoll\filekit\Storage::className(), \denoll\filekit\Storage::EVENT_BEFORE_SAVE, function ($event) {
         /** @var \denoll\filekit\Storage $storage */
         $storage = $event->sender;
         if (!$storage->getFilesystem()->has('.dirindex')) {
             $storage->getFilesystem()->write('.dirindex', 1);
             $dirindex = 1;
         } else {
             $dirindex = $storage->getFilesystem()->read('.dirindex');
         }
         if ($storage->maxDirFiles !== -1) {
             if ($storage->getFilesystem()->has($dirindex)) {
                 $filesCount = count($storage->getFilesystem()->listContents($dirindex));
                 if ($filesCount > $storage->maxDirFiles) {
                     $dirindex++;
                     $storage->getFilesystem()->createDir($dirindex);
                 }
             } else {
                 $storage->getFilesystem()->createDir($dirindex);
             }
         }
     });
     $client = new \Sabre\DAV\Client(['baseUri' => 'https://webdav.yandex.ru']);
     $client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
     $client->addCurlSetting(CURLOPT_HTTPHEADER, ['Authorization: OAuth TOKENTOKENTOKEN', 'Accept: */*', 'Host: webdav.yandex.ru']);
     $adapter = new WebDAVAdapter($client, '/');
     $flysystem = new Filesystem($adapter);
     if (!$flysystem->has($this->pathPrefix)) {
         $flysystem->createDir($this->pathPrefix);
     }
     $adapter->setPathPrefix($this->pathPrefix);
     return $flysystem;
 }
<?php

/**
 * The package league/flysystem-webdav is required for this example
 */
use League\Flysystem\Filesystem as Flysystem;
use League\Flysystem\WebDAV\WebDAVAdapter;
use React\EventLoop\Factory;
use React\Filesystem\Filesystem;
use Sabre\DAV\Client;
use WyriHaximus\React\Filesystem\Flysystem\FlysystemAdapter;
require dirname(__DIR__) . '/vendor/autoload.php';
$loop = Factory::create();
$loop->futureTick(function () use($loop) {
    $adapter = new WebDAVAdapter(new Client(['baseUri' => 'https://YOURSTACK.stackstorage.com/remote.php/webdav', 'userName' => 'USERNAME', 'password' => 'PASSWORD']));
    $adapter->setPathPrefix('/remote.php/webdav');
    $flysystem = new Flysystem($adapter);
    $filesystem = Filesystem::createFromAdapter(new FlysystemAdapter($loop, [], $flysystem));
    $filesystem->dir('')->ls()->then(function ($nodes) {
        foreach ($nodes as $node) {
            echo $node->getPath(), PHP_EOL;
        }
    }, function ($e) {
        var_export($e);
    });
});
$loop->run();