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


PHP FileReader::read方法代码示例

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


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

示例1: testWriteInNotExistingFile

 public function testWriteInNotExistingFile()
 {
     $filePath = __DIR__ . '/resources/none.txt';
     $dummyFileReader = new FileReader($filePath);
     $this->assertSame('', $dummyFileReader->read());
     $this->assertSame(3, $dummyFileReader->write('abc'));
     $this->assertSame('abc', $dummyFileReader->read());
     $this->assertSame(3, $dummyFileReader->write('def'));
     $this->assertSame('def', $dummyFileReader->read());
     unlink($filePath);
 }
开发者ID:raphhh,项目名称:balloon,代码行数:11,代码来源:FileReaderTest.php

示例2: fromRoute

 /**
  * @TODO
  */
 public function fromRoute($route)
 {
     // $this->route = $route;
     // Find the files that match the route.
     $finder = new \Symfony\Component\Finder\Finder();
     $glob = '#^default\\.(?:md|markdown|textile|html|htm|txt)$#';
     if ($route !== '') {
         $glob = '#^(?:\\d\\d\\.)?' . implode('\\/(?:\\d\\d\\.)?', explode('/', $route)) . '(?:\\/default)?\\.(?:md|markdown|textile|html|htm|txt)' . '$#';
     }
     $finder->in($this->documentPath)->path($glob);
     $files = [];
     foreach ($finder as $file) {
         $files[] = $file->getRelativePathname();
     }
     // Work out if we have *any* matching documents.  If not, throw an
     // exception.
     if (empty($files)) {
         throw new Exceptions\NoCandidatesException($route);
     }
     // Sort functions.
     $indexSort = function ($a, $b) {
         // return 0;
         return $a > $b;
     };
     $extensionSort = function ($a, $b) {
         $allowedExtensions = explode('|', 'md|markdown|textile|html|htm|txt');
         $aExt = pathinfo($a, PATHINFO_EXTENSION);
         $bExt = pathinfo($b, PATHINFO_EXTENSION);
         $aExtPos = array_search($aExt, $allowedExtensions);
         $bExtPos = array_search($bExt, $allowedExtensions);
         return $aExtPos > $bExtPos;
     };
     $isDefaultSort = function ($a, $b) {
         $aHasDefault = strpos($a, 'default.');
         $bHasDefault = strpos($b, 'default.');
         return $aHasDefault < $bHasDefault;
     };
     // Sort the documents according to their priority.
     $complexSort = \pjdietz\ComplexSort\ComplexSort::makeComplexSortFunction([$indexSort, $extensionSort, $isDefaultSort]);
     usort($files, $complexSort);
     // Read the file content from the filesystem.
     $fileReader = new FileReader(new \League\Flysystem\Filesystem(new \League\Flysystem\Adapter\Local($this->documentPath)));
     $filepath = $files[0];
     $content = $fileReader->read($filepath);
     // Create a document from the file content.
     $document = new Document($content);
     $document->filepath = $filepath;
     $document->parse();
     return $document;
 }
开发者ID:bluematt,项目名称:korpus-app,代码行数:53,代码来源:DocumentLocator.php

示例3: getPhingVersion

 /**
  * Gets the current Phing version based on VERSION.TXT file.
  *
  * @throws ConfigurationException
  *
  * @return string
  */
 public static function getPhingVersion()
 {
     $path = dirname(dirname(dirname(__FILE__)));
     $gitInformation = self::getGitInformation($path);
     if ($gitInformation) {
         return "Phing " . $gitInformation;
     }
     $versionPath = self::getResourcePath("phing/etc/VERSION.TXT");
     if ($versionPath === null) {
         $versionPath = self::getResourcePath("etc/VERSION.TXT");
     }
     if ($versionPath === null) {
         throw new ConfigurationException("No VERSION.TXT file found; try setting phing.home environment variable.");
     }
     try {
         // try to read file
         $file = new PhingFile($versionPath);
         $reader = new FileReader($file);
         $phingVersion = trim($reader->read());
     } catch (IOException $iox) {
         throw new ConfigurationException("Can't read version information file");
     }
     return "Phing " . $phingVersion;
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:31,代码来源:Phing.php

示例4: read

    }
}
class INIFileReader
{
    public function read($filePath)
    {
        return fopen($filePath, 'r');
    }
}
class FileReader
{
    public function read($filePath)
    {
        $extension = substr($filePath, -3);
        switch ($extension) {
            case 'ini':
                $reader = new INIFileReader();
                break;
            case 'xml':
                $reader = new XMLFileReader();
                break;
            default:
                return false;
                break;
        }
        return $reader->read($filePath);
    }
}
$reader = new FileReader();
$reader->read("test.ini");
$reader = new INIFileReader();
开发者ID:VoidWalker,项目名称:learning-project,代码行数:31,代码来源:Factory.php

示例5: loadFromStream

 function loadFromStream($filename)
 {
     $buffers = new StringBuffer();
     $file = NULL;
     if (File::validClass($filename)) {
         $file = $filename;
     } else {
         $file = new File($filename);
     }
     $filereader = new FileReader($file);
     while ($c = $filereader->read()) {
         $buffers->append($c);
     }
     $this->str = $buffers->toString();
 }
开发者ID:railfuture,项目名称:tiki-website,代码行数:15,代码来源:StringBuffer.php

示例6: _readFile

 /**
  * Reading a file.
  * 
  * @param  PhingFile $file The file to read
  * @return string
  * @access protected
  **/
 protected function _readFile(PhingFile $file)
 {
     $input = new FileReader($file);
     $buffer = $input->read();
     $input->close();
     return $buffer;
 }
开发者ID:piouPiouM,项目名称:phing-header,代码行数:14,代码来源:HeaderTask.php

示例7: file

   <td bgcolor=#ffffff>
   <br>
   <br>
   <?php 
if ($source) {
    highlight_string(implode('', file(__FILE__)));
    exit;
}
?>
   <strong>Loading properties file from :</strong> ./config.conf
   <br>
   <br>
   Display <strong>config.conf</strong> content :
   <dl><dd>
   <?php 
$reader = new FileReader('config.conf');
if ($reader->ready()) {
    while (($line = $reader->read()) != '') {
        if ($line == "\n" || $line == "\r\n") {
            print "<br>\n";
        } else {
            print htmlentities($line);
        }
    }
}
?>
   </dl>
   </td>
</tr>
</table>
开发者ID:alexpagnoni,项目名称:jphp,代码行数:30,代码来源:index.php

示例8: copyFrom

 /**
  * @param IFile $file The source file to copy from.
  * @return bool TRUE if the file has been successfully copied from $file, FALSE if an error occured
  * Note: An exception is raised if an important error is detected (the copy of a single file failed),
  *       but during a folder copy, a failure during the copy of a single "sub-file" is ignored and no
  *       exception is raised.
  *       Nevertheless, you can check if the copy was a full success by testing the returned value.
  * @throws EyeIOException
  * @throws EyeFileNotFoundException
  */
 protected function copyFrom(IFile $file, $overwrite = true)
 {
     if ($this->isDirectory() && (!$file->isDirectory() || $this->getName() != $file->getName())) {
         if ($this->getName() != '/' || $file->getName() != '/') {
             return $this->getChildFile($file->getName())->copyFrom($file, $overwrite);
         }
     }
     if ($this->exists() && !$overwrite) {
         throw new EyeIOException($this->path . '" exists and can\'t be overwritten.');
     }
     //FILE or LINK
     if ($file->isFile() || $file->isLink()) {
         $srcPath = AdvancedPathLib::getPhpLocalHackPath($file->getPath());
         $destPath = AdvancedPathLib::getPhpLocalHackPath($this->path);
         // First, let's try with the function provided by PHP, but only working with
         // a very restricted range of filesystems
         if (copy($srcPath, $destPath)) {
             return true;
         }
         if (!$this->exists() && !$this->createNewFile(true)) {
             throw new EyeIOException('Unable to create destination file ' . $this->path . '.');
         }
         try {
             $fileWriter = new FileWriter($this->getOutputStream());
             $fileReader = new FileReader($file->getInputStream());
             $buffer = null;
             while ($fileReader->read($buffer) !== 0) {
                 $fileWriter->write($buffer);
             }
             $fileReader->close();
             $fileWriter->close();
             return true;
         } catch (Exception $e) {
             if (is_object($fileReader)) {
                 $fileReader->close();
             }
             if (is_object($fileWriter)) {
                 $fileWriter->close();
             }
             throw new EyeIOException('Unable to transfer files contents ' . $file->getPath() . ' => ' . $this->path . '.', 0, $e);
         }
     } elseif ($file->isDirectory()) {
         if ($this->isDirectory() || $this->mkdirs()) {
             $success = true;
             foreach ($file->listFiles() as $subFile) {
                 try {
                     if (!$subFile->copyTo($this)) {
                         $success = false;
                     }
                 } catch (Exception $e) {
                     $success = false;
                 }
             }
             return $success;
         } else {
             throw new EyeIOException('Unable to create destination directory ' . $this->path . '.');
         }
     } else {
         throw new EyeFileNotFoundException($file->getPath() . ' does not exist.');
     }
 }
开发者ID:DavidGarciaCat,项目名称:eyeos,代码行数:71,代码来源:GenericFile.php


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