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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

你如何使用 YoSymfony 的 ResourceWatcher 包?

你如何使用 YoSymfony 的 ResourceWatcher 包?

PHP
阿晨1998 2021-06-29 16:59:23
我正在嘗試制作一個(gè)文件觀察器,當(dāng)您添加、更新或刪除文件時(shí),您可以在數(shù)據(jù)庫中看到文件更新。我正在使用框架 Symfony4 和來自 YoSymfony 的一個(gè)名為 ResourceWatcher 的包。該包使用來自 Symfony 的 Finder 包來查找指定目錄中的文件,然后觀察器比較緩存和新文件以查看是否有任何更改。當(dāng)我使用返回路徑數(shù)組的觀察者的方法時(shí),當(dāng)我嘗試查看該數(shù)組時(shí),它返回 null。我應(yīng)該如何使用這些方法及其回報(bào)?我把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)儲(chǔ) $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 回答

?
動(dòng)漫人物

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超10個(gè)贊

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

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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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