当前位置: 首页>>代码示例>>PHP>>正文


PHP File::setContent方法代码示例

本文整理汇总了PHP中File::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP File::setContent方法的具体用法?PHP File::setContent怎么用?PHP File::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在File的用法示例。


在下文中一共展示了File::setContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetContentWritesTheContenIntoTheFilesystem

 public function testSetContentWritesTheContenIntoTheFilesystem()
 {
     $fs = $this->getFilesystemMock();
     $fs->expects($this->once())->method('write')->with($this->equalTo('myFile'), $this->equalTo('some content'));
     $file = new File('myFile', $fs);
     $file->setContent('some content');
 }
开发者ID:novatex,项目名称:Gaufrette,代码行数:7,代码来源:FileTest.php

示例2: encodeFile

 /**
  * Encode JSON data and write to the file.
  *
  * @param array $data
  * @param string $filePath
  * @throws \InvalidArgumentException
  */
 public function encodeFile($data, $filePath)
 {
     $file = new File($filePath);
     $dataEncoder = new JsonDataEncoder();
     $fileData = $dataEncoder->encodeData($data);
     $file->setContent($fileData);
 }
开发者ID:katheroine,项目名称:php-data-coder,代码行数:14,代码来源:JsonDatafileEncoder.php

示例3: create

 /**
  * Create sitemap
  */
 public static function create()
 {
     // Get pages list
     $pages_list = Pages::getPages();
     // Create sitemap content
     $map = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
     $map .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
     foreach ($pages_list as $page) {
         if ($page['parent'] != '') {
             $parent = $page['parent'] . '/';
             $priority = '0.5';
         } else {
             $parent = '';
             $priority = '1.0';
         }
         $map .= "\t" . '<url>' . "\n\t\t" . '<loc>' . Option::get('siteurl') . '/' . $parent . $page['slug'] . '</loc>' . "\n\t\t" . '<lastmod>' . date("Y-m-d", (int) $page['date']) . '</lastmod>' . "\n\t\t" . '<changefreq>weekly</changefreq>' . "\n\t\t" . '<priority>' . $priority . '</priority>' . "\n\t" . '</url>' . "\n";
     }
     // Get list of components
     $components = Sitemap::getComponents();
     // Add components to sitemap
     if (count($components) > 0) {
         foreach ($components as $component) {
             $map .= "\t" . '<url>' . "\n\t\t" . '<loc>' . Option::get('siteurl') . '/' . Text::lowercase($component) . '</loc>' . "\n\t\t" . '<lastmod>' . date("Y-m-d", time()) . '</lastmod>' . "\n\t\t" . '<changefreq>weekly</changefreq>' . "\n\t\t" . '<priority>1.0</priority>' . "\n\t" . '</url>' . "\n";
         }
     }
     // Close sitemap
     $map .= '</urlset>';
     // Save sitemap
     return File::setContent(ROOT . DS . 'sitemap.xml', $map);
 }
开发者ID:rowena-altastratus,项目名称:altastratus,代码行数:33,代码来源:sitemap.plugin.php

示例4: get

 /**
  * Read file from KDB.
  *
  * @param  string    $remoteFile
  * @return \Kdb\File
  */
 public function get($remoteFile)
 {
     $result = $this->getClient()->get($this->getUrlForFilename($remoteFile));
     $file = new File();
     $file->setContent($result->getBody())->setName(basename($remoteFile))->setMimeType($result->getHeader('Content-Type'));
     return $file;
 }
开发者ID:iborodikhin,项目名称:kdb-client,代码行数:13,代码来源:Connection.php

示例5: Poll

function Poll($id, $question, $answer1 = 'Yes', $answer2 = 'No')
{
    // values
    $id = isset($id) ? $id : '';
    $question = isset($question) ? $question : '';
    $answer1 = isset($answer1) ? $answer1 : '';
    $answer2 = isset($answer2) ? $answer2 : '';
    // json dir
    $dir = PLUGINS_PATH . '/poll/db/db.json';
    // clear vars init
    $db = '';
    $data = '';
    // check if exists file if not make one
    if (File::exists($dir)) {
        $db = File::getContent($dir);
        $data = json_decode($db, true);
        if (!$data[$id]) {
            // array of data
            $data[$id] = array('question' => '', 'yes' => '', 'no' => '');
            File::setContent($dir, json_encode($data));
            // redirect
            Request::redirect(Url::getCurrent());
        }
    } else {
        File::setContent($dir, '[]');
    }
    // check session if exists show answer only
    if (Session::get('user_poll' . $id)) {
        $template = Template::factory(PLUGINS_PATH . '/poll/template/');
        return $template->fetch('answer.tpl', ['id' => trim($id), 'question' => trim($question), 'answer1' => trim($answer1), 'answer2' => trim($answer2), 'yes' => $data[$id]['yes'], 'no' => $data[$id]['no']]);
    } else {
        // form post
        if (Request::post('sendData_' . $id)) {
            // check token
            if (Request::post('token')) {
                if (Request::post('answer') == 1) {
                    $good = $data[$id]['yes'] + 1;
                    $bad = $data[$id]['no'];
                } elseif (Request::post('answer') == 0) {
                    $bad = $data[$id]['no'] + 1;
                    $good = $data[$id]['yes'];
                }
                // array of data
                $data[$id] = array('question' => $question, 'yes' => $good, 'no' => $bad);
                // set content
                File::setContent($dir, json_encode($data));
                // set session cookie
                Session::set('user_poll' . $id, uniqid($id));
                // redirect
                Request::redirect(Url::getCurrent());
            } else {
                die('crsf detect !');
            }
        }
        // show template form
        $template = Template::factory(PLUGINS_PATH . '/poll/template/');
        return $template->fetch('poll.tpl', ['id' => trim($id), 'question' => trim($question), 'answer1' => trim($answer1), 'answer2' => trim($answer2), 'yes' => $data[$id]['yes'], 'no' => $data[$id]['no']]);
    }
}
开发者ID:nakome,项目名称:Fansoro-poll-plugin,代码行数:59,代码来源:poll.php

示例6: export_data_to_file

 public function export_data_to_file($table, $filename_or_file)
 {
     if ($filename_or_file instanceof File) {
         $f = $filename_or_file;
     } else {
         $f = new File($filename_or_file);
     }
     $f->setContent($this->export_data($table));
 }
开发者ID:mbcraft,项目名称:frozen,代码行数:9,代码来源:__MysqlTableDataImportExport.class.php

示例7: testBlackHole

 function testBlackHole()
 {
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/black_hole_test.php");
     $this->assertTrue($f->exists(), "Il file del test non esiste!!");
     $content = $f->getContent();
     $f->delete();
     $this->assertFalse($f->exists(), "Il file del test black hole non e' stato eliminato!!");
     $f->touch();
     $f->setContent($content);
     $this->assertTrue($f->exists(), "Il file del test black hole non e' stato rigenerato!!");
 }
开发者ID:mbcraft,项目名称:frozen,代码行数:11,代码来源:black_hole_test.php

示例8: update

 /**
  * @description Update folder
  */
 private function update()
 {
     if (!empty($this->configChmod)) {
         chmod($this->path, $this->configChmod);
     }
     if ($this->configAccessDeny) {
         $indexFile = new File($this->path . "/index.html");
         $indexFile->setContent("Access denied")->save();
     }
     if (!empty($this->configRename)) {
         // TODO: ash-1: implement rename if folder already exist
         rename($this->path, $this->configRename);
     }
 }
开发者ID:ufo-cms,项目名称:file-system,代码行数:17,代码来源:Folder.php

示例9: main

 /**
  * Main Emails admin function
  */
 public static function main()
 {
     // Init vars
     $email_templates_path = STORAGE . DS . 'emails' . DS;
     $email_templates_list = array();
     // Check for get actions
     // -------------------------------------
     if (Request::get('action')) {
         // Switch actions
         // -------------------------------------
         switch (Request::get('action')) {
             // Plugin action
             // -------------------------------------
             case "edit_email_template":
                 if (Request::post('edit_email_template') || Request::post('edit_email_template_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         // Save Email Template
                         File::setContent(STORAGE . DS . 'emails' . DS . Request::post('email_template_name') . '.email.php', Request::post('content'));
                         Notification::set('success', __('Your changes to the email template <i>:name</i> have been saved.', 'emails', array(':name' => Request::post('email_template_name'))));
                         if (Request::post('edit_email_template_and_exit')) {
                             Request::redirect('index.php?id=emails');
                         } else {
                             Request::redirect('index.php?id=emails&action=edit_email_template&filename=' . Request::post('email_template_name'));
                         }
                     }
                 }
                 $content = File::getContent($email_templates_path . Request::get('filename') . '.email.php');
                 // Display view
                 View::factory('box/emails/views/backend/edit')->assign('content', $content)->display();
                 break;
         }
     } else {
         // Get email templates
         $email_templates_list = File::scan($email_templates_path, '.email.php');
         // Display view
         View::factory('box/emails/views/backend/index')->assign('email_templates_list', $email_templates_list)->display();
     }
 }
开发者ID:rowena-altastratus,项目名称:altastratus,代码行数:41,代码来源:emails.admin.php

示例10: die

         $filename = Request::post('newFile');
         $dir = Request::post('directory');
         $content = Request::post('newContent');
         if ($filename && $content) {
             // empty dir save on pages dir
             if ($dir == '') {
                 if (File::exists(STORAGE_PATH . '/pages/' . sanitize($filename) . '.md')) {
                     die('<span class="alert alert-danger">The file ' . sanitize($filename) . ' already exists</span>');
                 }
                 File::setContent(STORAGE_PATH . '/pages/' . $filename . '.md', $content);
                 Request::redirect(Url::getBase() . '/' . $filename);
             } else {
                 if (File::exists(STORAGE_PATH . '/pages/' . $dir . '/' . sanitize($filename) . '.md')) {
                     die('<span class="alert alert-danger">The file ' . sanitize($filename) . ' already exists</span>');
                 }
                 File::setContent(STORAGE_PATH . '/pages/' . $dir . '/' . sanitize($filename) . '.md', $content);
                 Request::redirect(Url::getBase() . '/' . $dir . '/' . sanitize($filename));
             }
             //
         } else {
             die('You Cant write empty file');
         }
     } else {
         // crsf
         die('crsf detect');
     }
 }
 // remove file
 if (Request::get('del')) {
     if (Request::get('token')) {
         File::delete(STORAGE_PATH . '/pages' . Request::get('del') . '.md');
开发者ID:nakome,项目名称:Fansoro-edit-plugin,代码行数:31,代码来源:edit.php

示例11: testSetContent

 /**
  * Test setContent function
  * returns proper content.
  *
  * @dataProvider fileForWritePathAndContentProvider
  * @param string $filePath
  * @param string $fileContent
  */
 public function testSetContent($filePath, $fileContent)
 {
     $file = new File($filePath);
     $file->setContent($fileContent);
     $this->assertEquals($fileContent, file_get_contents($filePath));
 }
开发者ID:katheroine,项目名称:php-data-coder,代码行数:14,代码来源:FileTest.php

示例12: main

 /**
  * Snippets admin function
  */
 public static function main()
 {
     // Init vars
     $snippets_path = STORAGE . DS . 'snippets' . DS;
     $snippets_list = array();
     $errors = array();
     // Check for get actions
     // -------------------------------------
     if (Request::get('action')) {
         // Switch actions
         // -------------------------------------
         switch (Request::get('action')) {
             // Add snippet
             // -------------------------------------
             case "add_snippet":
                 if (Request::post('add_snippets') || Request::post('add_snippets_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         if (trim(Request::post('name')) == '') {
                             $errors['snippets_empty_name'] = __('Required field', 'snippets');
                         }
                         if (file_exists($snippets_path . Security::safeName(Request::post('name')) . '.snippet.php')) {
                             $errors['snippets_exists'] = __('This snippet already exists', 'snippets');
                         }
                         if (count($errors) == 0) {
                             // Save snippet
                             File::setContent($snippets_path . Security::safeName(Request::post('name')) . '.snippet.php', Request::post('content'));
                             Notification::set('success', __('Your changes to the snippet <i>:name</i> have been saved.', 'snippets', array(':name' => Security::safeName(Request::post('name')))));
                             if (Request::post('add_snippets_and_exit')) {
                                 Request::redirect('index.php?id=snippets');
                             } else {
                                 Request::redirect('index.php?id=snippets&action=edit_snippet&filename=' . Security::safeName(Request::post('name')));
                             }
                         }
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 // Save fields
                 if (Request::post('name')) {
                     $name = Request::post('name');
                 } else {
                     $name = '';
                 }
                 if (Request::post('content')) {
                     $content = Request::post('content');
                 } else {
                     $content = '';
                 }
                 // Display view
                 View::factory('box/snippets/views/backend/add')->assign('content', $content)->assign('name', $name)->assign('errors', $errors)->display();
                 break;
                 // Edit snippet
                 // -------------------------------------
             // Edit snippet
             // -------------------------------------
             case "edit_snippet":
                 // Save current snippet action
                 if (Request::post('edit_snippets') || Request::post('edit_snippets_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         if (trim(Request::post('name')) == '') {
                             $errors['snippets_empty_name'] = __('Required field', 'snippets');
                         }
                         if (file_exists($snippets_path . Security::safeName(Request::post('name')) . '.snippet.php') and Security::safeName(Request::post('snippets_old_name')) !== Security::safeName(Request::post('name'))) {
                             $errors['snippets_exists'] = __('This snippet already exists', 'snippets');
                         }
                         // Save fields
                         if (Request::post('content')) {
                             $content = Request::post('content');
                         } else {
                             $content = '';
                         }
                         if (count($errors) == 0) {
                             $snippet_old_filename = $snippets_path . Request::post('snippets_old_name') . '.snippet.php';
                             $snippet_new_filename = $snippets_path . Security::safeName(Request::post('name')) . '.snippet.php';
                             if (!empty($snippet_old_filename)) {
                                 if ($snippet_old_filename !== $snippet_new_filename) {
                                     rename($snippet_old_filename, $snippet_new_filename);
                                     $save_filename = $snippet_new_filename;
                                 } else {
                                     $save_filename = $snippet_new_filename;
                                 }
                             } else {
                                 $save_filename = $snippet_new_filename;
                             }
                             // Save snippet
                             File::setContent($save_filename, Request::post('content'));
                             Notification::set('success', __('Your changes to the snippet <i>:name</i> have been saved.', 'snippets', array(':name' => basename($save_filename, '.snippet.php'))));
                             if (Request::post('edit_snippets_and_exit')) {
                                 Request::redirect('index.php?id=snippets');
                             } else {
                                 Request::redirect('index.php?id=snippets&action=edit_snippet&filename=' . Security::safeName(Request::post('name')));
                             }
                         }
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
//.........这里部分代码省略.........
开发者ID:rowena-altastratus,项目名称:altastratus,代码行数:101,代码来源:snippets.admin.php

示例13: testSetContentThrowsAnExceptionIfNoFilesystemIsConfigured

 public function testSetContentThrowsAnExceptionIfNoFilesystemIsConfigured()
 {
     $file = new File('myFile');
     $this->setExpectedException('LogicException');
     $file->setContent('some content');
 }
开发者ID:ruudk,项目名称:Gaufrette,代码行数:6,代码来源:FileTest.php

示例14: array

 if (Session::exists('user')) {
     // items per page
     $per_page = $p::$site['backend_pagination_media_all'];
     // array json
     $json = array();
     $total = '';
     // next prev
     $prev = '';
     $next = '';
     // template
     $templateAll = '';
     // json file
     $jsonFile = ROOTBASE . '/public/media/mdb.json';
     // if not exists create
     if (!File::exists($jsonFile)) {
         File::setContent($jsonFile, '[]');
         // create folders album and album_thumbs
         Dir::create(ROOTBASE . '/public/media');
         Dir::create(ROOTBASE . '/public/media/albums');
         Dir::create(ROOTBASE . '/public/media/album_thumbs');
     } else {
         // get json file
         $json = json_decode(File::getContent($jsonFile), true);
         $total = count($json);
         if ($total > 0) {
             rsort($json);
             $showPag = array_chunk($json, $per_page);
             if ($offset > 1) {
                 $prev = '<a class="btn blue" href="' . $p->Url() . '/media/' . ($offset - 1) . '"><i class="ti-arrow-left"></i></a>';
             } else {
                 $prev = '<span class="btn black"><i class="ti-arrow-left"></i></span>';
开发者ID:xxwebplus,项目名称:morfy-admin-panel,代码行数:31,代码来源:pages.php

示例15: str_replace

     }
 }
 // get directory without base url
 $directory = str_replace(THEMES . '/', '', $path);
 $directory = str_replace(THEMES . '/' . File::name($path) . '.' . File::ext($path), '', $path);
 $error = '';
 // save file
 if (Request::post('saveFile')) {
     if (Request::post('token')) {
         $filename = $p->SeoLink(Request::post('filename'));
         $content = Request::post('newfile');
         if (File::exists(THEMES . '/' . $path . '/' . $filename . $ext)) {
             $error = '<span class="well red">' . Panel::$lang['File_Name_Exists'] . '</span>';
         } else {
             // save content
             File::setContent(THEMES . '/' . $path . '/' . $filename . $ext, $content);
             // set notification
             $p->setMsg($p::$lang['Success_save']);
             // redirect
             Request::redirect($p->Url() . '/' . $url);
         }
     } else {
         die('crsf Detect!');
     }
 }
 $p->view('actions', array('url' => $url, 'title' => Panel::$lang['New_File'], 'html' => '<form method="post">
     <seciton class="subheader">
       <div class="row">
         <div class="box-1 col">
           ' . $error . '
           <input type="hidden" name="token" value="' . Token::generate() . '">
开发者ID:xxwebplus,项目名称:morfy-admin-panel,代码行数:31,代码来源:newfile.php


注:本文中的File::setContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。