本文整理匯總了PHP中Cake\Filesystem\File::replaceText方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::replaceText方法的具體用法?PHP File::replaceText怎麽用?PHP File::replaceText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::replaceText方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _reloadDebugKitPlugin
/**
* Reload DebugKit plugin.
*
* @param string $vendorDir
*/
protected static function _reloadDebugKitPlugin($vendorDir)
{
$webRoot = $vendorDir . '/cakephp/debug_kit/webroot';
$assetsDir = $vendorDir . '/cakephp/debug_kit/assets';
if (is_dir($webRoot)) {
// Transport js styles.
$debugWebroot = new Folder($webRoot);
$debugWebroot->copy($assetsDir);
$debugWebroot->delete($webRoot);
}
// Rewrite include scripts.
$debugFilterFile = $vendorDir . '/cakephp/debug_kit/src/Routing/Filter/DebugBarFilter.php';
if (file_exists($debugFilterFile)) {
$debugFilter = new File($debugFilterFile);
$debugFilter->replaceText("Router::url('/debug_kit/js/toolbar.js')", "vPath()->url('DebugKit:assets/js/toolbar.js')");
}
// Reload default DebugKit AjaxView.
$debugViewFile = $vendorDir . '/cakephp/debug_kit/src/View/AjaxView.php';
if (file_exists($debugViewFile)) {
$debugView = new File($debugViewFile);
$debugView->replaceText('use Cake\\View\\View;', '');
$debugView->replaceText('extends View', 'extends \\Union\\App\\View\\AjaxView');
}
}
示例2: testReplaceText
/**
* testReplaceText method
*
* @return void
*/
public function testReplaceText()
{
$TestFile = new File(TEST_APP . 'vendor/welcome.php');
$TmpFile = new File(TMP . 'tests' . DS . 'cakephp.file.test.tmp');
// Copy the test file to the temporary location
$TestFile->copy($TmpFile->path, true);
// Replace the contents of the temporary file
$result = $TmpFile->replaceText('welcome.php', 'welcome.tmp');
$this->assertTrue($result);
// Double check
$expected = 'This is the welcome.tmp file in vendors directory';
$contents = $TmpFile->read();
$this->assertContains($expected, $contents);
$search = ['This is the', 'welcome.php file', 'in tmp directory'];
$replace = ['This should be a', 'welcome.tmp file', 'in the Lib directory'];
// Replace the contents of the temporary file
$result = $TmpFile->replaceText($search, $replace);
$this->assertTrue($result);
// Double check
$expected = 'This should be a welcome.tmp file in vendors directory';
$contents = $TmpFile->read();
$this->assertContains($expected, $contents);
$TmpFile->delete();
}