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


PHP File::read方法代码示例

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


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

示例1: getSwaggerDocument

 /**
  * Returns a single swagger document from filesystem or crawl-generates
  * a fresh one.
  *
  * @param string $id Name of the document
  * @param string $host Hostname of system serving swagger documents (without protocol)
  * @throws \InvalidArgumentException
  * @return string
  */
 public static function getSwaggerDocument($id, $host)
 {
     // load document from filesystem
     $filePath = CACHE . self::$filePrefix . $id . '.json';
     if (!Configure::read('Swagger.docs.crawl')) {
         if (!file_exists($filePath)) {
             throw new NotFoundException("Swagger json document was not found on filesystem: {$filePath}");
         }
         $fh = new File($filePath);
         return $fh->read();
     }
     // otherwise crawl-generate a fresh document
     $swaggerOptions = null;
     if (Configure::read("Swagger.library.{$id}.exclude")) {
         $swaggerOptions = ['exclude' => Configure::read("Swagger.library.{$id}.exclude")];
     }
     $swagger = \Swagger\scan(Configure::read("Swagger.library.{$id}.include"), $swaggerOptions);
     // set object properties required by UI to generate the BASE URL
     $swagger->host = $host;
     if (empty($swagger->basePath)) {
         $swagger->basePath = '/' . Configure::read('App.base');
     }
     $swagger->schemes = Configure::read('Swagger.ui.schemes');
     // write document to filesystem
     self::writeSwaggerDocumentToFile($filePath, $swagger);
     return $swagger;
 }
开发者ID:alt3,项目名称:cakephp-swagger,代码行数:36,代码来源:SwaggerTools.php

示例2: main

 public function main()
 {
     $tick_names_and_values = array();
     $this->authentication();
     $http = new Client();
     $this->loadModel('Stocks');
     $this->loadModel('Devices');
     $token_file = new File("/home/demo/token/token.txt");
     $token = $token_file->read();
     $token_file->close();
     $MyAuthObject = new OAuthObject(array("token_type" => "Bearer", "access_token" => $token));
     $OptionsToast = new WNSNotificationOptions();
     $OptionsToast->SetAuthorization($MyAuthObject);
     $OptionsToast->SetX_WNS_REQUESTFORSTATUS(X_WNS_RequestForStatus::Request);
     $NotifierToast = new WindowsNotificationClass($OptionsToast);
     $OptionsTile = new WNSNotificationOptions();
     $OptionsTile->SetAuthorization($MyAuthObject);
     $OptionsTile->SetX_WNS_REQUESTFORSTATUS(X_WNS_RequestForStatus::Request);
     //NOTE: Set the Tile type
     $OptionsTile->SetX_WNS_TYPE(X_WNS_Type::Tile);
     $NotifierTile = new WindowsNotificationClass($OptionsTile);
     $allStocks = $this->Stocks->find('all')->toArray();
     //$allStocks = $this->Stocks->find('all')->group(['Stocks.device_id'])->toArray();
     //$allStocks = $this->Stocks->Devices->find()->group(['Devices.id'])->toArray();
     Debugger::dump('allStocks: ');
     Debugger::dump($allStocks);
     $allStocksByDeviceId = array();
     for ($i = 0; $i < sizeof($allStocks); $i++) {
         $actualDeviceId = $allStocks[$i]['device_id'];
         $added = false;
         for ($a = 0; $a < sizeof($allStocksByDeviceId); $a++) {
             if ($allStocksByDeviceId[$a]['device_id'] == $actualDeviceId) {
                 $allStocksByDeviceId[$a]['stocks'][] = $allStocks[$i];
                 $added = true;
             }
         }
         if (!$added) {
             $allStocksByDeviceId[] = ['device_id' => $actualDeviceId, 'stocks' => [$allStocks[$i]]];
         }
     }
     Debugger::dump('allStocksByDeviceId: ');
     Debugger::dump($allStocksByDeviceId);
     $someStocks = $this->Stocks->find()->distinct(['tick_name'])->toArray();
     for ($i = 0; $i < sizeof($someStocks); $i++) {
         $response = $http->get('http://download.finance.yahoo.com/d/quotes?f=sl1d1t1v&s=' . $someStocks[$i]['tick_name']);
         $tick_name = explode(",", $response->body())[0];
         $tick_names_and_values[] = [str_replace("\"", "", $tick_name), explode(",", $response->body())[1]];
     }
     Debugger::dump('tick_names_and_values: ');
     Debugger::dump($tick_names_and_values);
     $this->sendAllStocksNotificationsInTileNotifications($NotifierTile, $tick_names_and_values, $allStocksByDeviceId);
     $this->checkMinMaxValuesAndSendToastNotifications($NotifierToast, $tick_names_and_values);
     //$stuff = implode(",", $stuff);
     //$now = Time::now();
     //$this->createFile('/home/demo/files_created_each_minute/'.$now->i18nFormat('yyyy-MM-dd HH:mm:ss').'.txt', $stuff);
 }
开发者ID:luisfilipe46,项目名称:Stock-Exchange-System-Server,代码行数:56,代码来源:FileShell.php

示例3: _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;
 }
开发者ID:cakephp,项目名称:cakephp,代码行数:20,代码来源:UnloadTask.php

示例4: 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'));
 }
开发者ID:subsumo,项目名称:envoy.website,代码行数:49,代码来源:BrochuresController.php

示例5: _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;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:27,代码来源:LoadTask.php

示例6: testShrinkJs

 /**
  * Test that js files are properly processed
  *
  * @return void
  */
 public function testShrinkJs()
 {
     $ret = $this->Shrink->build(['base.js', 'base.coffee'], 'js');
     // verify the result has the proper keys
     $this->assertArrayHasKey('path', $ret);
     $this->assertArrayHasKey('webPath', $ret);
     // verify we were returned a file
     $this->assertFileExists($ret['path']);
     // verify the contents
     $cacheFile = new File($ret['path']);
     $result = $cacheFile->read();
     $cacheFile->delete();
     $cacheFile->close();
     $expectedfile = new File(WWW_ROOT . 'js/base.shrink.js');
     $expect = $expectedfile->read();
     $expectedfile->close();
     $this->assertEquals($expect, $result);
 }
开发者ID:edukondaluetg,项目名称:cakephp-shrink,代码行数:23,代码来源:ShrinkTest.php

示例7: load

 /**
  * Load a YAML configuration file
  * located in ROOT/config/yaml/FILENAME
  *
  * We can use it like this:
  *      LoaderComponent::load('FILENAME.yml')
  *
  * @uses Cake\Filesystem\File
  * @param string The file name, extend with .yml
  * @param string The callback filename, if the first name parameter file doesn't exist, looking for the callback file
  * @throws \Exception
  * @return array The yaml data in array format
  */
 public static function load($file, $callback = null)
 {
     $path = ROOT . DS . 'config' . DS . 'yaml' . DS . $file;
     $oFile = new File($path);
     if (!$oFile->exists()) {
         if (is_null($callback)) {
             throw new Exception($path . " doesn't exists!!");
         } else {
             return static::load($callback);
         }
     }
     if (in_array($file, array_keys(static::$_loadedConfig))) {
         $config = static::$_loadedConfig[$file];
     } else {
         $config = Yaml::parse($oFile->read());
         static::$_loadedConfig[$file] = $config;
     }
     return $config;
 }
开发者ID:EdouardTack,项目名称:loaderyaml,代码行数:32,代码来源:LoaderComponent.php

示例8: get

 /**
  * @param $path
  * @return mixed
  */
 protected function get($path)
 {
     $file = new File($path);
     if (!$file->readable()) {
         if (true === $this->throws) {
             throw new \RuntimeException('not readable ' . $path);
         }
         return false;
     }
     $serialize = $file->read();
     $ret = unserialize($serialize);
     if (empty($ret)) {
         if (true === $this->throws) {
             throw new \UnexpectedValueException('empty data');
         }
         return false;
     }
     return $ret;
 }
开发者ID:Rmtram,项目名称:TextDatabase,代码行数:23,代码来源:Reader.php

示例9: testShrinkJs

 /**
  * test that js files are properly queued and processed
  *
  * @return void
  */
 public function testShrinkJs()
 {
     $this->Shrink->js(['base.js', 'base.coffee']);
     $tag = $this->Shrink->fetch('js');
     // did it create a link tag?
     $this->assertRegExp('/^\\<script\\s/', $tag);
     // grab the url if it has one (it always should)
     preg_match('/src="(?P<url>.+?)"/', $tag, $matches);
     $this->assertArrayHasKey('url', $matches);
     // verify the file exists
     $url = $matches['url'];
     $file = new File(WWW_ROOT . $url);
     $this->assertTrue($file->exists());
     // verify the contents
     $result = $file->read();
     $file->delete();
     $file->close();
     $expectedfile = new File(WWW_ROOT . 'js/base.shrink.js');
     $expect = $expectedfile->read();
     $expectedfile->close();
     $this->assertEquals($expect, $result);
 }
开发者ID:edukondaluetg,项目名称:cakephp-shrink,代码行数:27,代码来源:ShrinkHelperTest.php

示例10: cmdInfo

 public function cmdInfo()
 {
     $cmdline_fh = new File('/proc/cmdline');
     $cmdline_raw = $cmdline_fh->read();
     $cmdline_fh->close();
     $lines = explode(" ", $cmdline_raw);
     $cmdline = [];
     for ($i = 0; $i < sizeof($lines); $i++) {
         if (trim($lines[$i]) != "") {
             $info = explode("=", $lines[$i]);
             if (sizeof($info) < 2) {
                 continue;
             }
             if (!strpos($info[0], '.')) {
                 $key = trim($info[0]);
             } else {
                 $key = substr(strstr(trim($info[0]), '.'), 1);
             }
             $val = trim($info[1]);
             $cmdline[$key] = $val;
         }
     }
     return $cmdline;
 }
开发者ID:tgeimer,项目名称:raspicake,代码行数:24,代码来源:Raspi.php

示例11: 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();
 }
开发者ID:xenolOnline,项目名称:resumable.php,代码行数:9,代码来源:Resumable.php

示例12: getRichCakeboxYaml

 /**
  * Returns rich information for the Cakebox.yaml file.
  *
  * @return array Hash with raw file data and timestamp.
  * @throws Exception
  */
 public function getRichCakeboxYaml()
 {
     try {
         $fileHandle = new File($this->cakeboxMeta['host']['yaml']);
         return ['timestamp' => $fileHandle->lastChange(), 'raw' => $fileHandle->read()];
     } catch (\Exception $e) {
         throw new \Exception("Error reading " . $this->cakeboxMeta['yamlFile'] . ": " . $e->getMessage());
     }
 }
开发者ID:alt3,项目名称:cakebox-console,代码行数:15,代码来源:CakeboxInfo.php

示例13: view

 /**
  * Renders a JPEG of the given attachment. Will fall back to a file icon,
  * if a image can not be generated.
  *
  * @param string $attachmentId Attachment ID
  * @return void
  */
 public function view($attachmentId = null)
 {
     // FIXME cache previews
     $attachment = $this->Attachments->get($attachmentId);
     $this->_checkAuthorization($attachment);
     switch ($attachment->filetype) {
         case 'image/png':
         case 'image/jpg':
         case 'image/jpeg':
         case 'image/gif':
             $image = new \Imagick($attachment->getAbsolutePath());
             if (Configure::read('Attachments.autorotate')) {
                 $this->_autorotate($image);
             }
             break;
         case 'application/pdf':
             header('Content-Type: ' . $attachment->filetype);
             $file = new File($attachment->getAbsolutePath());
             echo $file->read();
             exit;
             break;
         default:
             $image = new \Imagick(Plugin::path('Attachments') . '/webroot/img/file.png');
             break;
     }
     $image->setImageFormat('png');
     $image->setImageCompression(\Imagick::COMPRESSION_JPEG);
     $image->setImageCompressionQuality(75);
     $image->stripImage();
     header('Content-Type: image/' . $image->getImageFormat());
     echo $image;
     $image->destroy();
     exit;
 }
开发者ID:cleptric,项目名称:cake-attachments,代码行数:41,代码来源:AttachmentsController.php

示例14: fetch

 /**
  * Processes/minify/combines queued files of the requested type.
  * @param string type - 'js' or 'css'. This should be the end result type
  * @param string how - 'link' for <script src="">, 'async' for <script src="" async>, 'embed' for <script>...js code...</script>
  * @param array files - string name of a file or array containing multiple string of files
  * @return string - the <script> or <link>
  */
 function fetch($type, $how = 'link', $files = array())
 {
     if ($type == 'script') {
         $type = 'js';
     }
     if (!$files) {
         $files =& $this->files;
     }
     if (!$files) {
         return '';
     }
     // ensure the layout files are before the view files
     $files[$type] = array_merge($files[$type]['layout'], $files[$type]['view']);
     // determine the cache file path
     $cacheFile = $this->settings['prefix'] . md5(implode('_', $files[$type])) . '.' . $type;
     $cacheFilePath = preg_replace('/(\\/+|\\+)/', DS, WWW_ROOT . DS . $this->settings[$type]['cachePath'] . DS . $cacheFile);
     $cacheFileObj = new File($cacheFilePath);
     $webCacheFilePath = $this->settings['url'] . preg_replace('/\\/+/', '/', '/' . $this->extraPath . '/' . $this->settings[$type]['cachePath'] . $cacheFile);
     // create Cake file objects and get the max date
     $maxAge = 0;
     foreach ($files[$type] as $k => $v) {
         //$caminho = preg_replace('/(\/+|\\+)/', DS, WWW_ROOT .DS. ($v[0]=='/'? '':$this->settings[$type]['path']) .DS. $v);
         $tmpf = new File(preg_replace('/(\\/+|\\+)/', DS, WWW_ROOT . DS . ($v[0] == '/' ? '' : $this->settings[$type]['path']) . DS . $v));
         //var_dump($tmpf); //path
         //echo '<br><br><br>';
         $files[$type][$k] = array('file' => $tmpf, 'rel_path' => $v);
         $srcMod = $tmpf->lastChange();
         if ($srcMod > $maxAge) {
             $maxAge = $srcMod;
         }
     }
     // has the cache expired (we're debugging, the cache doesn't exist, or too old)?
     $expired = false;
     if ($this->debugging || !$cacheFileObj->exists() || $maxAge > $cacheFileObj->lastChange()) {
         $expired = true;
     }
     // rebuild if it has expired
     if ($expired) {
         $output = '';
         foreach ($files[$type] as $k => $v) {
             $lang = $v['file']->ext();
             // load compiler if it is not already
             if (!isset($this->compilers[$lang])) {
                 $this->compilers[$lang] = ShrinkType::getCompiler($lang, $this->settings);
             }
             $resultType = $this->compilers[$lang]->resultType;
             // load the compressor if it is not already
             $compressorName = $this->settings[$type]['minifier'];
             if (!isset($this->compressors[$compressorName])) {
                 $this->compressors[$compressorName] = ShrinkType::getCompressor($compressorName, $this->settings);
             }
             // compile, compress, combine
             if ($resultType == $type && $v['file']->exists()) {
                 $output .= "/* " . $v['rel_path'] . " */\n";
                 $code = $this->compilers[$lang]->compile($v['file']);
                 // INICIA MODIFICAÇÃO FEITA PELO AUTOR DO "PROJETO STORES"
                 //$code = $this->compressors[$compressorName]->compress($code);
                 $isMinified = strpos($v['file']->path, '.min');
                 if ($type == 'css' && $isMinified === false) {
                     $code = $this->compressors[$compressorName]->compress($code);
                 }
                 if ($type == 'js' && $isMinified === false) {
                     $jshrinkCompressor = new ShrinkCompressorJshrink();
                     $code = $jshrinkCompressor->compress($code);
                 }
                 if ($isMinified !== false) {
                     $patter = '/\\/\\*(.|[\\r\\n])*?\\*\\//';
                     $replacement = ' ';
                     $code = preg_replace($patter, $replacement, $code);
                 }
                 // TERMINA MODIFICAÇÃO FEITA PELO AUTOR DO "PROJETO STORES"
                 $output .= $code . "\n";
             }
         }
         // be sure no duplicate charsets
         if ($type == 'css') {
             $output = preg_replace('/@charset\\s+[\'"].+?[\'"];?/i', '', $output);
             $output = '@charset "' . $this->settings['css']['charset'] . "\";\n" . $output;
         }
         // write the file
         $cacheFileObj->write($output);
     }
     // files will be @$this->files, so this clears them
     $files[$type] = array('layout' => array(), 'view' => array());
     // print them how the user wants
     if ($how == 'embed') {
         $output = $cacheFileObj->read();
         if ($type == 'css') {
             return '<style type="text/css">' . $output . '</style>';
         } else {
             return '<script type="text/javascript">' . $output . '</script>';
         }
     } else {
//.........这里部分代码省略.........
开发者ID:ricardohenriq,项目名称:shooping,代码行数:101,代码来源:ShrinkHelper.php

示例15: _getTypes

 /**
  * get Types with file cache?
  * //TODO: use normal cache
  *
  * @return array
  */
 protected function _getTypes()
 {
     $handle = new File(FILE_CACHE . 'mime_types.txt', true, 0770);
     if (!$handle->exists()) {
         # create and fill: ext||type||name||img (array serialized? separated by ||?)
         $MimeTypes = TableRegistry::get('Data.MimeTypes');
         $mimeTypes = $MimeTypes->find('all', ['fields' => ['name', 'ext', 'type', 'MimeTypeImages.name', 'MimeTypeImages.ext'], 'conditions' => ['MimeTypes.active' => 1], 'contain' => ['MimeTypeImages']]);
         $content = [];
         foreach ($mimeTypes as $m) {
             $img = !empty($m->mime_type_image['ext']) ? $m->mime_type_image['name'] . '.' . $m->mime_type_image['ext'] : '';
             $content[] = ['ext' => $m['ext'], 'name' => $m['name'], 'type' => $m['type'], 'img' => $img];
         }
         # add special types? (file not found icon, default fallback icon, generic file ext icon...)
         if (!$handle->write(serialize($content), 'w', true)) {
             throw new \Exception('Write error');
         }
     } else {
         //$handle->open('r', true);
         $content = $handle->read();
         if ($content === false) {
             return [];
         }
         $content = @unserialize($content);
         if ($content === false || !is_array($content)) {
             return [];
         }
     }
     return $content;
 }
开发者ID:dereuromark,项目名称:cakephp-data,代码行数:35,代码来源:MimeTypeHelper.php


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