本文整理汇总了PHP中Cake\Filesystem\File::append方法的典型用法代码示例。如果您正苦于以下问题:PHP File::append方法的具体用法?PHP File::append怎么用?PHP File::append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::append方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _modifyBootstrap
/**
* Update the applications bootstrap.php file.
*
* @param string $plugin Name of plugin.
* @param bool $hasBootstrap Whether or not bootstrap should be loaded.
* @param bool $hasRoutes Whether or not routes should be loaded.
* @param bool $hasAutoloader Whether or not there is an autoloader configured for
* the plugin.
* @return bool If modify passed.
*/
protected function _modifyBootstrap($plugin, $hasBootstrap, $hasRoutes, $hasAutoloader)
{
$bootstrap = new File($this->bootstrap, false);
$contents = $bootstrap->read();
if (!preg_match("@\n\\s*Plugin::loadAll@", $contents)) {
$autoloadString = $hasAutoloader ? "'autoload' => true" : '';
$bootstrapString = $hasBootstrap ? "'bootstrap' => true" : '';
$routesString = $hasRoutes ? "'routes' => true" : '';
$append = "\nPlugin::load('%s', [%s]);\n";
$options = implode(', ', array_filter([$autoloadString, $bootstrapString, $routesString]));
$bootstrap->append(str_replace(', []', '', sprintf($append, $plugin, $options)));
$this->out('');
$this->out(sprintf('%s modified', $this->bootstrap));
return true;
}
return false;
}
示例2: _modifyBootstrap
/**
* Update the app's bootstrap.php file.
*
* @param string $plugin Name of plugin
* @param bool $hasAutoloader Whether or not there is an autoloader configured for
* the plugin
* @return void
*/
protected function _modifyBootstrap($plugin, $hasAutoloader)
{
$bootstrap = new File($this->bootstrap, false);
$contents = $bootstrap->read();
if (!preg_match("@\n\\s*Plugin::loadAll@", $contents)) {
$autoload = $hasAutoloader ? null : "'autoload' => true, ";
$bootstrap->append(sprintf("\nPlugin::load('%s', [%s'bootstrap' => false, 'routes' => true]);\n", $plugin, $autoload));
$this->out('');
$this->out(sprintf('%s modified', $this->bootstrap));
}
}
示例3: createFileFromChunks
public function createFileFromChunks($chunkFiles, $destFile)
{
$destFile = new File($destFile, true);
foreach ($chunkFiles as $chunkFile) {
$file = new File($chunkFile);
$destFile->append($file->read());
}
return $destFile->exists();
}
示例4: _addPluginToBootstrap
/**
* _addPluginToBootstrap
*
* Quick method to add a plugin to the bootstrap file.
* This is useful for the tests
*
* @param string $name
*/
protected function _addPluginToBootstrap($name)
{
$bootstrap = new File($this->bootstrap, false);
$bootstrap->append("\n\nPlugin::load('{$name}', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);\n");
}
示例5: testAppend
/**
* testAppend method
*
* @return void
*/
public function testAppend()
{
if (!($tmpFile = $this->_getTmpFile())) {
return false;
}
if (file_exists($tmpFile)) {
unlink($tmpFile);
}
$TmpFile = new File($tmpFile);
$this->assertFalse(file_exists($tmpFile));
$fragments = ['CakePHP\'s', ' test suite', ' was here ...'];
$data = null;
$size = 0;
foreach ($fragments as $fragment) {
$r = $TmpFile->append($fragment);
$this->assertTrue($r);
$this->assertTrue(file_exists($tmpFile));
$data = $data . $fragment;
$this->assertEquals($data, file_get_contents($tmpFile));
$newSize = $TmpFile->size();
$this->assertTrue($newSize > $size);
$size = $newSize;
$TmpFile->close();
}
$TmpFile->append('');
$this->assertEquals($data, file_get_contents($tmpFile));
$TmpFile->close();
}
示例6: createFileFromChunks
public function createFileFromChunks($chunkFiles, $destFile)
{
$this->log('Beginning of create files from chunks');
natsort($chunkFiles);
$destFile = new File($destFile, true);
foreach ($chunkFiles as $chunkFile) {
$file = new File($chunkFile);
$destFile->append($file->read());
$this->log('Append ', ['chunk file' => $chunkFile]);
}
$this->log('End of create files from chunks');
return $destFile->exists();
}
示例7: export
//.........这里部分代码省略.........
} elseif ($table == 5) {
$tableName = 'seats';
$seatsTable = TableRegistry::get('seats');
$query = $seatsTable->find('all');
$str = "id" . "," . "theater" . "," . "section" . "," . "row" . "," . "code" . "," . "price\r\n";
$results = $query->toArray();
foreach ($results as $item) {
$str .= $item->id . ",";
$str .= $item->theater_id . ",";
$str .= $item->section_id . ",";
$str .= $item->row_id . ",";
$str .= "\"" . $item->code . "\"" . ",";
$str .= $item->price;
$str .= "\r\n";
}
} elseif ($table == 6) {
$tableName = 'seasons';
$seasonsTable = TableRegistry::get('seasons');
$query = $seasonsTable->find('all');
$str = "id" . "," . "name" . "," . "start_time" . "," . "end_time" . "," . "ticket_price" . "," . "theater_id" . "\r\n";
$results = $query->toArray();
foreach ($results as $item) {
$str .= $item->id . ",";
$str .= "\"" . $item->name . "\"" . ",";
$str .= $item->start_time . ",";
$str .= $item->end_time . ",";
$str .= $item->ticket_price . ",";
$str .= $item->theater_id . ",";
$str .= "\"" . $item->about . "\"";
$str .= "\r\n";
}
} elseif ($table == 7) {
$tableName = 'rows';
$rowsTable = TableRegistry::get('rows');
$query = $rowsTable->find('all');
$str = "id" . "," . "theater" . "," . "section" . "," . "code\r\n";
$results = $query->toArray();
foreach ($results as $item) {
$str .= $item->id . ",";
$str .= $item->theater_id . ",";
$str .= $item->section_id . ",";
$str .= "\"" . $item->code . "\"";
$str .= "\r\n";
}
} elseif ($table == 8) {
$tableName = 'plays';
$playsTable = TableRegistry::get('plays');
$query = $playsTable->find('all');
$str = "id" . "," . "name" . "," . "artwork" . "," . "description" . "," . "author\r\n";
$results = $query->toArray();
foreach ($results as $item) {
$str .= $item->id . ",";
$str .= "\"" . $item->name . "\"" . ",";
$str .= "\"" . $item->artwork . "\"" . ",";
$str .= "\"" . $item->description . "\"" . ",";
$str .= "\"" . $item->author . "\"" . ",";
$str .= "\"" . $item->shortname . "\"";
$str .= "\r\n";
}
} elseif ($table == 9) {
$tableName = 'performances';
$ticketsTable = TableRegistry::get('performances');
$query = $ticketsTable->find('all');
$str = "id" . "," . "start_time" . "," . "open" . "," . "canceled" . "," . "play_id" . "," . "theater_id" . "," . "season_id\r\n";
$results = $query->toArray();
foreach ($results as $item) {
$str .= $item->id . ",";
$str .= $item->start_time . ",";
$str .= $item->open . ",";
$str .= $item->canceled . ",";
$str .= $item->play_id . ",";
$str .= $item->theater_id . ",";
$str .= $item->season_id;
$str .= "\r\n";
}
} elseif ($table == 10) {
$tableName = 'cart_items';
$ticketsTable = TableRegistry::get('cart_items');
$query = $ticketsTable->find('all');
$str = "id" . "," . "cart_id" . "," . "performance_id" . "," . "seat_id" . "," . "season_ticket\r\n";
$results = $query->toArray();
foreach ($results as $item) {
$str .= $item->id . ",";
$str .= "\"" . $item->cart_id . "\"" . ",";
$str .= "\"" . $item->performance_id . "\"" . ",";
$str .= $item->seat_id . ",";
$str .= $item->season_id;
$str .= "\r\n";
}
} else {
$this->Flash->error('Unexpected table value');
}
$file = new File('tmp/', true);
$file->open('w');
$file->append($str);
$this->response->file($file->path, ['download' => true, 'name' => $tableName . '.csv']);
} else {
$this->set('file_status', 'Please submit a file.');
}
}
示例8: updateCake2Configuration
/**
* Convenience function to update all required CakePHP2 configuration files.
*
* @param string $appdir Full path to the application directory (APP).
* @param string $url FQDN used to expose the application.
* @return boolean True if the file was updated successfully
*/
public function updateCake2Configuration($appdir, $url)
{
# Update salt/cipher in core.php
$this->_log("Updating core.php");
$coreFile = $appdir . DS . "app" . DS . "Config" . DS . "core.php";
$res = CakeboxUtility::updateConfigFile($coreFile, [$this->Info->frameworkMeta['cakephp2']['salt'] => CakeboxUtility::getSaltCipher($coreFile), $this->Info->frameworkMeta['cakephp2']['cipher'] => CakeboxUtility::getSaltCipher($coreFile)]);
if (!$res) {
$this->_error("Error updating core file");
return false;
}
// create database.php
$dbFileSource = $appdir . DS . "app" . DS . "Config" . DS . "database.php.default";
$dbFileTarget = $appdir . DS . "app" . DS . "Config" . DS . "database.php";
if (!file_exists($dbFileTarget)) {
copy($dbFileSource, $dbFileTarget);
$this->_log("Created database file `{$dbFileTarget}`");
}
# update database.php
$this->_log("Updating database.php");
$database = CakeboxUtility::normalizeDatabaseName($url);
$result = CakeboxUtility::updateConfigFile($dbFileTarget, ['test_database_name' => 'test_' . $database, 'database_name' => $database, 'user' => 'cakebox', "'password' => 'password'" => "'password' => 'secret'"]);
if (!$result) {
$this->_error("Error updating database file");
return false;
}
# Enable debugkit in bootstrap.php
$this->_log("Enabling DebugKit");
$bootstrapFile = $appdir . DS . "app" . DS . "Config" . DS . "bootstrap.php";
$fh = new File($bootstrapFile);
$fh->append('CakePlugin::loadAll();');
return true;
}