本文整理汇总了PHP中Cake\Filesystem\File::write方法的典型用法代码示例。如果您正苦于以下问题:PHP File::write方法的具体用法?PHP File::write怎么用?PHP File::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Cria um plugin de teste e o carrega para conseguir rodar os testes.
*/
public function setUp()
{
parent::setUp();
$testData = ['full_path' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS, 'config_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'config' . DS, 'css_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'css' . DS, 'js_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'js' . DS, 'img_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'img' . DS, 'packages_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'packages' . DS];
$pluginFolder = new Folder($testData['full_path'], self::CREATE_FOLDER_IF_NOT_EXISTS, self::PLUGIN_FOLDER_PERMISSIONS);
$pluginFolder->create($testData['config_folder']);
$pluginFolder->create($testData['css_folder']);
$pluginFolder->create($testData['js_folder']);
$pluginFolder->create($testData['img_folder']);
$pluginFolder->create($testData['packages_folder'] . 'sample_package');
$defaultSettingsFile = new File($testData['config_folder'] . 'default_settings.php', true);
$defaultSettingsFile->write("<?php \n\t\t\treturn [\n\t\t\t\t'MyApplication.Modules.ThemeInstallerTest.Settings' => \n\t\t\t\t\t['Default' => true]\n\t\t\t\t]; \n\t\t?>");
$defaultSettingsFile->close();
$file = new File($testData['css_folder'] . 'sample.css', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['js_folder'] . 'sample.js', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.css', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.js', true);
$file->write('#id { }');
$file->close();
$bootstrapFile = new File($testData['config_folder'] . 'bootstrap.php', true);
$bootstrapFile->close();
}
示例2: writeSwaggerDocumentToFile
/**
* Write swagger document to filesystem.
*
* @param string $path Full path to the json document including filename
* @param string $content Swagger content
* @throws Cake\Network\Exception\InternalErrorException
* @return bool
*/
protected static function writeSwaggerDocumentToFile($path, $content)
{
$fh = new File($path, true);
if (!$fh->write($content)) {
throw new InternalErrorException('Error writing Swagger json document to filesystem');
}
return true;
}
示例3: tearDown
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
unset($this->shell);
Plugin::unload();
$bootstrap = new File($this->bootstrap, false);
$bootstrap->write($this->originalBootstrapContent);
}
示例4: _write
/**
* Write data in json file.
*
* @return void
*/
protected function _write()
{
$this->_bufferActivated();
$this->_bufferLoaded();
$JSON = new JSON($this->_buffer);
$file = Path::loadedFolder() . $this->_config['file'];
$File = new File($file);
$File->write($JSON->write());
}
示例5: afterSave
public function afterSave(Event $event, Entity $site, \ArrayObject $options)
{
$sitePath = WWW_ROOT . '..' . DS . self::SITES_DIR . DS . 'site' . $site->id;
$folder = new Folder();
if (!$folder->create($sitePath, 0755)) {
throw new InternalErrorException('Error create site files');
}
$indexHtml = new File($sitePath . DS . 'index.html', true, 0644);
$indexHtml->write($site->content);
}
示例6: write
/**
* write serialize data.
* @param bool $overwrite
* @return bool
*/
public function write($overwrite = false)
{
$path = $this->getPath();
if (true === $this->writable() && false === $overwrite) {
throw new ExistsFileException('exists ' . $path);
}
$file = new File($path);
if (!$file->write($this->export())) {
throw new \RuntimeException('save failed ' . $path);
}
return true;
}
示例7: _modifyBootstrap
/**
* Update the applications bootstrap.php file.
*
* @param string $plugin Name of plugin.
* @return bool If modify passed.
*/
protected function _modifyBootstrap($plugin)
{
$finder = "/\nPlugin::load\\((.|.\n|\n\\s\\s|\n\t|)+'{$plugin}'(.|.\n|)+\\);\n/";
$bootstrap = new File($this->bootstrap, false);
$contents = $bootstrap->read();
if (!preg_match("@\n\\s*Plugin::loadAll@", $contents)) {
$contents = preg_replace($finder, "", $contents);
$bootstrap->write($contents);
$this->out('');
$this->out(sprintf('%s modified', $this->bootstrap));
return true;
}
return false;
}
示例8: testInstalledPluginSettingsFileWillNotBeOverrridenOnLoad
public function testInstalledPluginSettingsFileWillNotBeOverrridenOnLoad()
{
$starter = new PluginStarter();
$starter->load('PluginInstallerTest');
$installedSettingsFile = new File(ROOT . DS . 'config' . DS . 'Plugins' . DS . 'PluginInstallerTest' . DS . 'settings.php');
$defaultSettingsFile = new File(ROOT . DS . 'plugins' . DS . 'PluginInstallerTest' . DS . 'config' . DS . 'default_settings.php');
$installedSettingsFile->write("<?php \n\t\t\treturn [\n\t\t\t\t'MyApplication.Modules.PluginInstallerTest.Settings' => \n\t\t\t\t\t['Default' => false]\n\t\t\t\t]; \n\t\t?>");
$installedSettingsFile->close();
$starter->load('PluginInstallerTest');
$installedSettingsFile = new File(ROOT . DS . 'config' . DS . 'Plugins' . DS . 'PluginInstallerTest' . DS . 'settings.php');
$this->assertEquals(strcmp($installedSettingsFile->md5(), $defaultSettingsFile->md5()) === 0, false);
$installedSettingsFile->close();
$defaultSettingsFile->close();
}
示例9: add
public function add()
{
$broch = $this->request->data;
if (!empty($this->request->data)) {
//hacking in blank default values since there is no inputs for the following
$this->request->data['location'] = '';
$this->request->data['restrict_access'] = 0;
$this->request->data['max_restricted_qty'] = 0;
if ($this->request->data['image']['tmp_name'] != '') {
$file = new File($this->request->data['image']['tmp_name']);
$filename = $this->request->data['image']['name'];
$data = $file->read();
$file->close();
$file = new File(WWW_ROOT . '/img/brochures/' . $filename, true);
$file->write($data);
$file->close();
unset($this->request->data['image']);
$image = ['filename' => $filename, 'caption' => $filename];
$image = $this->Brochures->Images->newEntity($image);
if ($image = $this->Brochures->Images->save($image)) {
$this->Flash->set(__('The brochure image could not be saved. Please, try again.'));
}
$this->request->data['image_id'] = '';
} else {
$image = '';
}
try {
$brochure = $this->Brochures->newEntity($this->request->data, ['accessibleFields' => ['sku' => true], 'contain' => 'Images']);
if ($image) {
$brochure->image = $image;
}
if ($brochure = $this->Brochures->save($brochure)) {
$this->Flash->set(__('The brochure has been saved'));
// $this->_notifyWarehouse($broch);
$this->redirect(array('action' => 'index'));
} else {
$this->Flash->set(__('The brochure could not be saved. Please, try again.'));
}
} catch (Exception $e) {
$this->Flash->set(__('The brochure could not be saved. Please, try again.'));
}
}
$images = $this->Brochures->Images->find('list', array('fields' => array('id', 'caption')));
//$images['0'] = "None";
$this->LoadModel('Suppliers');
$suppliers = $this->Suppliers->find('list', ['fields' => array('company', 'id'), 'order' => ['Suppliers.company']]);
//$suppliers['0'] = "None";
$this->set(compact('images', 'suppliers'));
}
示例10: assertSameAsFile
/**
* Compare the result to the contents of the file
*
* @param string $path partial path to test comparison file
* @param string $result test result as a string
* @return void
*/
public function assertSameAsFile($path, $result)
{
if (!file_exists($path)) {
$path = $this->_compareBasePath . $path;
}
if ($this->_updateComparisons === null) {
$this->_updateComparisons = env('UPDATE_TEST_COMPARISON_FILES');
}
if ($this->_updateComparisons) {
$file = new File($path, true);
$file->write($result);
}
$expected = file_get_contents($path);
$this->assertTextEquals($expected, $result);
}
示例11: upload
public function upload($path = null)
{
$root = WWW_ROOT;
$fullPath = $root . $path;
if ($this->request->is('post')) {
foreach ($this->request->data['file'] as $file) {
$new = new File($fullPath . DS . $file['name'], false);
if (!$new->exists()) {
$new->create();
$new->write(file_get_contents($file['tmp_name']));
}
}
if (count($this->request->data['file']) > 1) {
$this->Flash->success(__('The files have been saved.'));
} else {
$this->Flash->success(__('The file has been saved.'));
}
return $this->redirect(['action' => 'index', $path]);
}
$this->Flash->error(__('The file(s) could not be saved.'));
}
示例12: save
//.........这里部分代码省略.........
$width = $resizedWidth;
$height = $this->thumbHeight;
$src_x = intval(($resizedWidth - $this->thumbWidth) / 2);
} else {
$width = $this->thumbWidth;
$height = $resizedHeight;
$src_y = intval(($resizedHeight - $this->thumbHeight) / 2);
}
$src = imagecreatetruecolor($width, $height);
// save transparent colors
if ($this->imgFormat == 'png') {
imagecolortransparent($src, imagecolorallocate($src, 0, 0, 0));
imagealphablending($src, false);
imagesavealpha($src, true);
}
// get and reallocate transparency-color for gif
if ($this->imgFormat == 'gif') {
imagealphablending($src, false);
$transindex = imagecolortransparent($this->imgSource) <= imagecolorstotal($src) ? imagecolortransparent($this->imgSource) : imagecolorstotal($src);
if ($transindex >= 0) {
$transcol = imagecolorsforindex($this->imgSource, $transindex);
$transindex = imagecolorallocatealpha($src, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
imagefill($src, 0, 0, $transindex);
}
}
if (function_exists('imagecopyresampled')) {
@imagecopyresampled($src, $this->imgSource, 0, 0, 0, 0, $width, $height, $this->imgWidth, $this->imgHeight);
} else {
@imagecopyresized($src, $this->imgSource, 0, 0, 0, 0, $width, $height, $this->imgWidth, $this->imgHeight);
}
// restore transparency for gif
if ($this->imgFormat == 'gif') {
if ($transindex >= 0) {
imagecolortransparent($src, $transindex);
for ($y = 0; $y < imagesy($src); ++$y) {
for ($x = 0; $x < imagesx($src); ++$x) {
if ((imagecolorat($src, $x, $y) >> 24 & 0x7f) >= 100) {
imagesetpixel($src, $x, $y, $transindex);
}
}
}
}
}
}
// create thumbnail image
$thumbnail = imagecreatetruecolor($this->thumbWidth, $this->thumbHeight);
// save transparent colors for png
if ($this->imgFormat == 'png') {
imagecolortransparent($thumbnail, imagecolorallocate($src, 0, 0, 0));
imagealphablending($thumbnail, false);
imagesavealpha($thumbnail, true);
}
// get and reallocate transparency-color for gif
if ($this->imgFormat == 'gif') {
imagealphablending($thumbnail, false);
$transindex = imagecolortransparent($src);
if ($transindex >= 0) {
$transcol = imagecolorsforindex($src, $transindex);
$transindex = imagecolorallocatealpha($thumbnail, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
imagefill($thumbnail, 0, 0, $transindex);
}
}
@imagecopy($thumbnail, $src, 0, 0, $src_x, $src_y, $this->thumbWidth, $this->thumbHeight);
// restore transparency for gif
if ($this->imgFormat == 'gif') {
if ($transindex >= 0) {
imagecolortransparent($thumbnail, $transindex);
for ($y = 0; $y < imagesy($thumbnail); ++$y) {
for ($x = 0; $x < imagesx($thumbnail); ++$x) {
if ((imagecolorat($thumbnail, $x, $y) >> 24 & 0x7f) >= 100) {
imagesetpixel($thumbnail, $x, $y, $transindex);
}
}
}
}
}
// save thumbnail to file
ob_start();
switch ($this->imgFormat) {
case 'gif':
$return = imagegif($thumbnail);
break;
case 'jpeg':
$return = imagejpeg($thumbnail, null, $this->thumbQuality);
break;
case 'png':
$return = imagepng($thumbnail);
break;
}
$output = ob_get_contents();
ob_end_clean();
$File = new File($file);
$File->write($output);
$File->close();
// free memory resources
imagedestroy($thumbnail);
imagedestroy($src);
}
return $return;
}
示例13: export
public function export()
{
if ($this->request->is('post')) {
$listLang = [];
foreach (Configure::read('Core.System.language') as $key => $item) {
$listLang = array_merge($listLang, [$key => $item['key']]);
}
$lang = $this->request->data['language'];
$list = $this->Languages->find();
$content = "";
$path = APP . "Locale/{$listLang[$lang]}/default.po";
foreach ($list as $item) {
$content .= 'msgid "' . $item->key . '"' . "\n" . 'msgstr "' . $item->{$lang} . '"' . "\n";
}
if ($File = new File($path, true, 0777)) {
$File->write($content);
Cache::clearGroup('persistent');
$this->Flash->success(__('language exported', true));
} else {
$this->Flash->error(__('language can not be exported', true));
}
$this->redirect(array('action' => 'index'));
}
}
示例14: sendFile
/**
* @param $path
* @param $fileName
* @param $fileId
* @return \Cake\Network\Response|null
*/
private function sendFile($path, $fileName, $fileId, $bucketName)
{
$S3Client = new WRS3Client();
$plainUrl = $S3Client->getObjectUrl($bucketName, $path);
$tempPath = ROOT . DS . 'tmp' . DS . 'cache' . DS . $fileId . $fileName;
$file = new File($tempPath, true, 0644);
$file->write(@file_get_contents($plainUrl));
$this->response->file($tempPath);
return $this->response;
}
示例15: _clearBootstrap
/**
* clearBootstrap
*
* Helper to clear the bootstrap file.
*
* @return void
*/
protected function _clearBootstrap()
{
$bootstrap = new File($this->bootstrap, false);
$bootstrap->write($this->originalBootstrapContent);
}