第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

你如何使用 YoSymfony 的 ResourceWatcher 包?

你如何使用 YoSymfony 的 ResourceWatcher 包?

PHP
阿晨1998 2021-06-29 16:59:23
我正在嘗試制作一個文件觀察器,當您添加、更新或刪除文件時,您可以在數(shù)據(jù)庫中看到文件更新。我正在使用框架 Symfony4 和來自 YoSymfony 的一個名為 ResourceWatcher 的包。該包使用來自 Symfony 的 Finder 包來查找指定目錄中的文件,然后觀察器比較緩存和新文件以查看是否有任何更改。當我使用返回路徑數(shù)組的觀察者的方法時,當我嘗試查看該數(shù)組時,它返回 null。我應(yīng)該如何使用這些方法及其回報?我把var_dump到處都放了,看問題出在findChanges()->getUpdatedFiles()和getNewFiles();//舊代碼    $finder = new Finder();    $finder->files()        ->name('*.csv')        ->in('%kernel.root_dir%/../src/data/');    //watcher    $hashContent = new Crc32ContentHash();    $resourceCache = new ResourceCachePhpFile('cache-key.php');    $watcher = new ResourceWatcher($resourceCache, $finder, $hashContent);    $watcher->initialize();    if($watcher->findChanges()->hasChanges()){        if($watcher->findChanges()->getNewFiles() === null){            $paths = $watcher->findChanges()->getUpdatedFiles();        }        else{            $paths = $watcher->findChanges()->getNewFiles();        }        $propertyAccessor = PropertyAccess::createPropertyAccessor();        var_dump($propertyAccessor->getValue($paths, '[first_name]'));        die();     }我希望能夠看到路徑,將它們轉(zhuǎn)換為字符串并將其用于我的其他方法以使數(shù)據(jù)出現(xiàn)在我的數(shù)據(jù)庫中。在我的 var_dump 中,我在終端中得到 NULL。編輯:[first_name] 在我的 csv 文件中,您可以直接轉(zhuǎn)儲 $paths。//新代碼    $finder = new Finder();    $finder->files()        ->name('*.csv')        ->in('%kernel.root_dir%/../src/data/');    //watcher    $hashContent = new Crc32ContentHash();    $resourceCache = new ResourceCachePhpFile('cache-key.php');    $watcher = new ResourceWatcher($resourceCache, $finder, $hashContent);    $watcher->initialize();    $changes = $watcher->findChanges();        if(!empty($changes->getUpdatedFiles())){        $updatedFilesPath = $changes->getUpdatedFiles();        $pathString = implode($updatedFilesPath);        $reader = Reader::createFromPath($pathString);    }    elseif(!empty($changes->getNewFiles())){        $newFilesPath = $changes->getNewFiles();        $pathString = implode($newFilesPath);        $reader = Reader::createFromPath($pathString);    }
查看完整描述

1 回答

?
動漫人物

TA貢獻1815條經(jīng)驗 獲得超10個贊

因此,一旦您使用 findChanges()->hasChanges() 方法,它就會告訴觀察者有一些更改,但隨后它會重置并且觀察者中不再有任何更改,因此使用 $paths = 毫無意義$watcher->findChanges()->getUpdatedFiles(); 因為它總是因為重置而不會返回任何內(nèi)容。我必須創(chuàng)建一個包含內(nèi)部更改的變量,以便我可以進一步重復(fù)使用這些更改。

查看完整回答
反對 回復(fù) 2021-07-02
  • 1 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號