當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::read方法代碼示例

本文整理匯總了PHP中File::read方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::read方法的具體用法?PHP File::read怎麽用?PHP File::read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在File的用法示例。


在下文中一共展示了File::read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testCache

 function testCache()
 {
     $dir = __DIR__ . '/../cache';
     $cache = new File(['directory' => $dir]);
     $users = ['Masoud', 'Alireza'];
     $cache->write('users', $users);
     $this->assertCount(1, $cache->stats());
     $this->assertTrue($cache->contains('users'));
     $this->assertEquals($users, $cache->read('users'));
     $this->assertFalse($cache->expired('users', 1));
     $i = 0;
     $posts = ['Post 1', 'Post 2'];
     for ($j = 0; $j < 10; $j++) {
         $result = $cache->remember('posts', function () use(&$i, $posts) {
             $i++;
             return $posts;
         }, 10);
     }
     $this->assertEquals(1, $i);
     $this->assertEquals($posts, $result);
     $this->assertEquals($posts, $cache->read('posts'));
     $this->assertCount(2, $cache->stats());
     $cache->delete('users');
     $this->assertFalse($cache->contains('users'));
     $this->assertTrue($cache->contains('posts'));
     $cache->deleteAll();
     $this->assertCount(0, $cache->stats());
     @unlink($dir);
 }
開發者ID:mdzzohrabi,項目名稱:azera-cache,代碼行數:29,代碼來源:FileTest.php

示例2: read_packet

 private function read_packet()
 {
     $buffer = $this->file->read($this->offset_in_file, $this->buffer_max_size);
     $buffer_size = strlen($buffer);
     $this->offset_in_file += strlen($buffer);
     if ($buffer_size == 0) {
         $this->reached_end_of_file = true;
     }
     return $buffer;
 }
開發者ID:AroundPBT,項目名稱:PHPBoost,代碼行數:10,代碼來源:BufferedFileReader.class.php

示例3: test_basic_write

 public function test_basic_write()
 {
     $file = new File("/tmp/test.txt");
     FuzzyTest::assert_true($file->exists(), "File not found");
     $save_path = DOCUMENT_SAVE_PATH . "/test.txt";
     $file->write($save_path);
     FuzzyTest::assert_true($file->exists(), "File not written");
     $contents = $file->read();
     FuzzyTest::assert_equal($file->read(), "This is the content of the file", "Contents were not read");
     $file->delete();
     FuzzyTest::assert_false($file->exists(), "File not deleted");
 }
開發者ID:pokeb,項目名稱:fuzzy-record,代碼行數:12,代碼來源:FileTest.php

示例4: updateBower

 /**
  * Bower update
  *
  * @param Model $model Model using this behavior
  * @param string $plugin Plugin namespace
  * @param string $option It is '' or '--save'. '--save' is used install.
  * @return bool True on success
  */
 public function updateBower(Model $model, $plugin, $option = '')
 {
     if (!$plugin) {
         return false;
     }
     $pluginPath = ROOT . DS . 'app' . DS . 'Plugin' . DS . Inflector::camelize($plugin) . DS;
     if (!file_exists($pluginPath . 'bower.json')) {
         return true;
     }
     $file = new File($pluginPath . 'bower.json');
     $bower = json_decode($file->read(), true);
     $file->close();
     foreach ($bower['dependencies'] as $package => $version) {
         CakeLog::info(sprintf('[bower] Start bower install %s#%s for %s', $package, $version, $plugin));
         $messages = array();
         $ret = null;
         exec(sprintf('cd %s && `which bower` --allow-root install %s#%s %s', ROOT, $package, $version, $option), $messages, $ret);
         // Write logs
         if (Configure::read('debug')) {
             foreach ($messages as $message) {
                 CakeLog::info(sprintf('[bower]   %s', $message));
             }
         }
         CakeLog::info(sprintf('[bower] Successfully bower install %s#%s for %s', $package, $version, $plugin));
     }
     return true;
 }
開發者ID:Onasusweb,項目名稱:PluginManager,代碼行數:35,代碼來源:BowerBehavior.php

示例5: read

 public static function read($sql = false)
 {
     if (!($data = self::_data($sql)) || !($cont = File::read($data['path'] . $data['file']))) {
         return false;
     }
     return unserialize($cont);
 }
開發者ID:hectormenendez,項目名稱:h23,代碼行數:7,代碼來源:cache.php

示例6: refresh

 /**
  * 生成視圖緩存
  *
  * @param string $tplfile
  * @return number
  */
 public function refresh($tplfile)
 {
     $str = File::read($tplfile);
     $str = $this->template_parse($str);
     $strlen = File::write($this->compilefile, $str);
     return $strlen;
 }
開發者ID:hubs,項目名稱:yuncms,代碼行數:13,代碼來源:Template.php

示例7: decodeFile

 public static function decodeFile($filepath, $toArray = true)
 {
     // Attempt to retrieve the file content
     if ($serializedData = File::read($filepath)) {
         return self::decode($serializedData, $toArray);
     }
 }
開發者ID:SkysteedDevelopment,項目名稱:Deity,代碼行數:7,代碼來源:Data_JSON.php

示例8: read

 /**
  * Reads a MagicDb from various formats
  *
  * @var $magicDb mixed Can be an array containing the db, a magic db as a string, or a filename pointing to a magic db in .db or magic.db.php format
  * @return boolean Returns false if reading / validation failed or true on success.
  * @access private
  */
 public function read($magicDb = null)
 {
     if (!is_string($magicDb) && !is_array($magicDb)) {
         return false;
     }
     if (is_array($magicDb) || strpos($magicDb, '# FILE_ID DB') === 0) {
         $data = $magicDb;
     } else {
         $File = new File($magicDb);
         if (!$File->exists()) {
             return false;
         }
         if ($File->ext() == 'php') {
             include $File->pwd();
             $data = $magicDb;
         } else {
             // @TODO: Needs test coverage
             $data = $File->read();
         }
     }
     $magicDb = $this->toArray($data);
     if (!$this->validates($magicDb)) {
         return false;
     }
     return !!($this->db = $magicDb);
 }
開發者ID:evrard,項目名稱:cakephp2x,代碼行數:33,代碼來源:magic_db.php

示例9: action_create

 public function action_create()
 {
     if (Input::method() == 'POST') {
         $config = array('path' => DOCROOT . DS . 'files', 'randomize' => true, 'ext_whitelist' => array('txt'));
         Upload::process($config);
         if (Upload::is_valid()) {
             $file = Upload::get_files(0);
             $contents = File::read($file['file'], true);
             foreach (explode("\n", $contents) as $line) {
                 if (preg_match('/record [0-9]+ BAD- PHONE: ([0-9]+) ROW: \\|[0-9]+\\| DUP: [0-9] [0-9]+/i', $line, $matches)) {
                     $all_dupes[] = $matches[1];
                 }
             }
             $dupe_check = \Goautodial\Insert::duplicate_check($all_dupes);
             foreach ($dupe_check as $dupe_number => $dupe_details) {
                 $new_duplicate = new Model_Data_Supplier_Campaign_Lists_Duplicate();
                 $new_duplicate->list_id = Input::post('list_id');
                 $new_duplicate->database_server_id = Input::post('database_server_id');
                 $new_duplicate->duplicate_number = $dupe_number;
                 $new_duplicate->dialler = $dupe_details['dialler'];
                 $new_duplicate->lead_id = $dupe_details['data']['lead_id'];
                 $new_duplicate->save();
             }
         } else {
             print "No Uploads";
         }
     }
     $this->template->title = "Data_Supplier_Campaign_Lists_Duplicates";
     $this->template->content = View::forge('data/supplier/campaign/lists/duplicates/create');
 }
開發者ID:ClixLtd,項目名稱:pccupload,代碼行數:30,代碼來源:duplicates.php

示例10: load

 /**
  * Loads a language from cache or locales files
  *
  * @param string $languages	Language code (e.g. en_US or fr_FR)
  */
 public static function load($language)
 {
     if (!preg_match('#^([a-z]{2})(?:_[A-Z]{2})?$#', $language, $match)) {
         throw new Exception('Wrong language format');
     }
     $language_base = $match[0];
     // Locale of PHP
     setlocale(LC_ALL, $language . '.UTF-8', $language_base . '.UTF-8', 'en_EN.UTF-8');
     // Retrieving the translations
     $last_modif = max(filemtime(CF_DIR . 'locales/' . $language), filemtime(APP_DIR . 'locales/' . $language));
     self::$translations = Cache::read('translations_' . $last_modif);
     if (self::$translations != false) {
         return;
     }
     // If the translations cache doesn't exist, we create it
     $vars = '';
     try {
         $vars .= File::read(CF_DIR . 'locales/' . $language);
     } catch (Exception $e) {
         throw new Exception('The L10N file "' . $language . '" for Confeature was not found');
     }
     $vars .= "\n\n";
     try {
         $vars .= File::read(APP_DIR . 'locales/' . $language);
     } catch (Exception $e) {
         throw new Exception('The L10N file "' . $language . '" for the App was not found');
     }
     // Extraction of the variables and storage in the class
     self::$translations = self::parse($vars);
     Cache::write('translations_' . $last_modif, self::$translations, 3600 * 24);
 }
開發者ID:Godefroy,項目名稱:confeature,代碼行數:36,代碼來源:class.L10N.php

示例11: updateColorConfig

 /**
  * テーマカラー設定を保存する
  * 
  * @param array $data
  * @return boolean
  */
 public function updateColorConfig($data)
 {
     $configPath = getViewPath() . 'css' . DS . 'config.css';
     if (!file_exists($configPath)) {
         return false;
     }
     $File = new File($configPath);
     $config = $File->read();
     $settings = array('MAIN' => 'color_main', 'SUB' => 'color_sub', 'LINK' => 'color_link', 'HOVER' => 'color_hover');
     $settingExists = false;
     foreach ($settings as $key => $setting) {
         if (empty($data['ThemeConfig'][$setting])) {
             $config = preg_replace("/\n.+?" . $key . ".+?\n/", "\n", $config);
         } else {
             $config = str_replace($key, '#' . $data['ThemeConfig'][$setting], $config);
             $settingExists = true;
         }
     }
     $File = new File(WWW_ROOT . 'files' . DS . 'theme_configs' . DS . 'config.css', true, 0666);
     $File->write($config);
     $File->close();
     if (!$settingExists) {
         unlink($configPath);
     }
     return true;
 }
開發者ID:kenz,項目名稱:basercms,代碼行數:32,代碼來源:ThemeConfig.php

示例12: clear

 /**
  * Delete all values from the cache
  *
  * @param boolean $check Optional - only delete expired cache items
  * @return boolean True if the cache was succesfully cleared, false otherwise
  * @access public
  */
 function clear($check)
 {
     if (!$this->__init) {
         return false;
     }
     $dir = dir($this->settings['path']);
     if ($check) {
         $now = time();
         $threshold = $now - $this->settings['duration'];
     }
     while (($entry = $dir->read()) !== false) {
         if ($this->__setKey($entry) === false) {
             continue;
         }
         if ($check) {
             $mtime = $this->__File->lastChange();
             if ($mtime === false || $mtime > $threshold) {
                 continue;
             }
             $expires = $this->__File->read(11);
             $this->__File->close();
             if ($expires > $now) {
                 continue;
             }
         }
         $this->__File->delete();
     }
     $dir->close();
     return true;
 }
開發者ID:masayukiando,項目名稱:googlemap-search_ActionScript3.0,代碼行數:37,代碼來源:file.php

示例13: read

 function read($dir = null, $recursive = false)
 {
     $notes = array();
     $path = CORE_PATH . APP_PATH . $dir;
     $folder = new Folder(APP_PATH . $dir);
     $fold = $recursive ? $folder->findRecursive('.*\\.php') : $folder->find('.*\\.php');
     foreach ($fold as $file) {
         $file = $recursive ? $file : $path . $file;
         $file_path = r(CORE_PATH . APP_PATH, '', $file);
         $handle = new File($file_path);
         $content = $handle->read();
         $lines = explode(PHP_EOL, $content);
         //$lines = file($file);
         $ln = 1;
         if (!empty($lines)) {
             foreach ($lines as $line) {
                 if ((is_null($this->type) || $this->type == 'TODO') && preg_match("/[#\\*\\/\\/]\\s*TODO\\s*(.*)/", $line, $match)) {
                     $this->notes[$file_path]['TODO'][$ln] = $match[1];
                 }
                 if ((is_null($this->type) || $this->type == 'OPTIMIZE') && preg_match("/[#\\*\\/\\/]\\s*OPTIMIZE|OPTIMISE\\s*(.*)/", $line, $match)) {
                     $this->notes[$file_path]['OPTIMIZE'][$ln] = $match[1];
                 }
                 if ((is_null($this->type) || $this->type == 'FIXME') && preg_match("/[#\\*\\/\\/]\\s*FIXME|BUG\\s*(.*)/", $line, $match)) {
                     $this->notes[$file_path]['FIXME'][$ln] = $match[1];
                 }
                 $ln++;
             }
         }
     }
     return $this->notes;
 }
開發者ID:robksawyer,項目名稱:tools,代碼行數:31,代碼來源:notes.php

示例14: database

 /**
  * Step 1: database
  *
  * @return void
  */
 public function database()
 {
     $this->pageTitle = __('Step 1: Database', true);
     if (!empty($this->data)) {
         // test database connection
         if (mysql_connect($this->data['Install']['host'], $this->data['Install']['login'], $this->data['Install']['password']) && mysql_select_db($this->data['Install']['database'])) {
             // rename database.php.install
             rename(APP . 'config' . DS . 'database.php.install', APP . 'config' . DS . 'database.php');
             // open database.php file
             App::import('Core', 'File');
             $file = new File(APP . 'config' . DS . 'database.php', true);
             $content = $file->read();
             // write database.php file
             if (!class_exists('String')) {
                 App::import('Core', 'String');
             }
             $this->data['Install']['prefix'] = '';
             //disabled
             $content = String::insert($content, $this->data['Install'], array('before' => '{default_', 'after' => '}'));
             if ($file->write($content)) {
                 $this->redirect(array('action' => 'data'));
             } else {
                 $this->Session->setFlash(__('Could not write database.php file.', true));
             }
         } else {
             $this->Session->setFlash(__('Could not connect to database.', true));
         }
     }
 }
開發者ID:hiromi2424,項目名稱:candycane_clone,代碼行數:34,代碼來源:install_controller.php

示例15: _setupDatabase

 /**
  * Execute Config/cakegallery.sql to create the tables
  * Create the config File
  * @param $db
  */
 private function _setupDatabase($db)
 {
     # Execute the SQL to create the tables
     $sqlFile = new File(App::pluginPath('Gallery') . 'Config' . DS . 'cakegallery.sql', false);
     $db->rawQuery($sqlFile->read());
     $sqlFile->close();
 }
開發者ID:brnagn7,項目名稱:spydercake,代碼行數:12,代碼來源:InstallController.php


注:本文中的File::read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。