本文整理汇总了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);
}
示例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;
}
示例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");
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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');
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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();
}