本文整理汇总了PHP中SplFileObject::eof方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::eof方法的具体用法?PHP SplFileObject::eof怎么用?PHP SplFileObject::eof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::eof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readBytes
private function readBytes($length)
{
$stream = null;
for ($cc = 0; $cc < $length; $cc++) {
if ($this->file->eof()) {
return null;
}
$stream .= $this->file->fgetc();
}
return $stream;
}
示例2: __construct
/**
* @param $file
* @param null $defaultPatternPattern
*/
public function __construct($file, $defaultPatternPattern = null)
{
parent::__construct($defaultPatternPattern);
$this->file = new \SplFileObject($file, 'r');
$i = 0;
while (!$this->file->eof()) {
$this->file->current();
$this->file->next();
$i++;
}
$this->lineCount = $i;
$this->parser = $this->getDefaultParser();
}
示例3: test
function test($name)
{
echo "==={$name}===\n";
$o = new SplFileObject(dirname(__FILE__) . '/' . $name);
var_dump($o->key());
while (($c = $o->fgetc()) !== false) {
var_dump($o->key(), $c, $o->eof());
}
echo "===EOF?===\n";
var_dump($o->eof());
var_dump($o->key());
var_dump($o->eof());
}
示例4: __construct
/**
* @param $file
* @param int $days
* @param string $pattern
*/
public function __construct($file, $days = 1, $pattern = 'default')
{
$this->file = new \SplFileObject($file, 'r');
$i = 0;
while (!$this->file->eof()) {
$this->file->current();
$this->file->next();
$i++;
}
$this->days = $days;
$this->pattern = $pattern;
$this->lineCount = $i;
$this->parser = $this->getDefaultParser($days, $pattern);
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if (parent::execute($input, $output)) {
$this->loadOCConfig();
$properties = array('string $id', 'string $template', 'array $children', 'array $data', 'string $output');
// TODO: get all library classes as well, maybe extract from registry somehow...
$searchLine = "abstract class Controller {";
$pathToController = "engine/controller.php";
$catalogModels = $this->getModels(\DIR_APPLICATION);
$adminModels = $this->getModels(str_ireplace("catalog/", "admin/", \DIR_APPLICATION));
$textToInsert = array_unique(array_merge($properties, $catalogModels, $adminModels));
//get line number where start Controller description
$fp = fopen(\DIR_SYSTEM . $pathToController, 'r');
$lineNumber = $this->getLineOfFile($fp, $searchLine);
fclose($fp);
//regenerate Controller text with properties
$file = new \SplFileObject(\DIR_SYSTEM . $pathToController);
$file->seek($lineNumber);
$tempFile = sprintf("<?php %s \t/**%s", PHP_EOL, PHP_EOL);
foreach ($textToInsert as $val) {
$tempFile .= sprintf("\t* @property %s%s", $val, PHP_EOL);
}
$tempFile .= sprintf("\t**/%s%s%s", PHP_EOL, $searchLine, PHP_EOL);
while (!$file->eof()) {
$tempFile .= $file->fgets();
}
//write Controller
$fp = fopen(\DIR_SYSTEM . $pathToController, 'w');
fwrite($fp, $tempFile);
fclose($fp);
}
}
示例6: upload_hathdl
function upload_hathdl()
{
$file = new SplFileObject($_FILES['ehgfile']['tmp_name']);
$gid = -1;
$page = -1;
$title = null;
$tags = null;
while (!$file->eof()) {
$line = $file->fgets();
$line = trim($line);
$token = explode(' ', $line);
if (strcmp($token[0], 'GID') == 0) {
$gid = intval($token[1]);
} else {
if (strcmp($token[0], 'FILES') == 0) {
$page = intval($token[1]);
} else {
if (strcmp($token[0], 'TITLE') == 0) {
$title = trim(preg_replace('TITLE', '', $line));
} else {
if (strcmp($token[0], 'Tags:') == 0) {
$tags = trim(preg_replace('Tags:', '', $line));
}
}
}
}
}
shell_exec('cp ' . $_FILES['ehgfile']['tmp_name'] . ' hentaiathome/hathdl/');
$info['gid'] = $gid;
$info['page'] = $page;
$info['title'] = $title;
$info['tags'] = $tags;
return $info;
}
示例7: valid
/**
* True if not EOF
*
* @return boolean
*/
public function valid()
{
if (null === $this->_file) {
$this->_openFile();
}
return $this->_file && !$this->_file->eof();
}
示例8: _getCSVLine
/**
* Returns a line form the CSV file and advances the pointer to the next one
*
* @param Model $Model
* @param SplFileObject $handle CSV file handler
* @return array list of attributes fetched from the CSV file
*/
protected function _getCSVLine(Model &$Model, SplFileObject $handle)
{
if ($handle->eof()) {
return false;
}
return $handle->fgetcsv($this->settings[$Model->alias]['delimiter'], $this->settings[$Model->alias]['enclosure']);
}
示例9: actionIndex
public function actionIndex($path = null, $fix = null)
{
if ($path === null) {
$path = YII_PATH;
}
echo "Checking {$path} for files with BOM.\n";
$checkFiles = CFileHelper::findFiles($path, array('exclude' => array('.gitignore')));
$detected = false;
foreach ($checkFiles as $file) {
$fileObj = new SplFileObject($file);
if (!$fileObj->eof() && false !== strpos($fileObj->fgets(), self::BOM)) {
if (!$detected) {
echo "Detected BOM in:\n";
$detected = true;
}
echo $file . "\n";
if ($fix) {
file_put_contents($file, substr(file_get_contents($file), 3));
}
}
}
if (!$detected) {
echo "No files with BOM were detected.\n";
} else {
if ($fix) {
echo "All files were fixed.\n";
}
}
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$values = $form_state->getValues();
$file = File::load($values['file'][0]);
// Load File entity.
$read_file = new \SplFileObject($file->url());
// Create file handler.
$lines = 1;
$in_queue = 0;
$queue = \Drupal::queue('eventninja');
// Load queue
while (!$read_file->eof()) {
$data = $read_file->fgetcsv(';');
if ($lines > 1) {
// skip headers
$user = user_load_by_mail($data[1]);
if ($user === false) {
// Verify if user with specified email does not exist.
$queue->createItem($data);
$in_queue++;
} else {
$this->logger('eventninja')->log(RfcLogLevel::NOTICE, 'User {mail} hasn\'t been created.', ['mail' => $data[1]]);
}
}
$lines++;
}
if ($lines > 1) {
drupal_set_message($this->t('@num records was scheduled for import', array('@num' => $in_queue)), 'success');
} else {
drupal_set_message($this->t('File contains only headers'), 'error');
}
}
示例11: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$filename = $input->getArgument('filename');
if (!file_exists($filename)) {
throw new \Symfony\Component\HttpKernel\Exception\BadRequestHttpException("Le fichier {$filename} n'existe pas.");
}
// Indicateurs
$i = 0;
// Nombre de mots-clés importés
$em = $this->getContainer()->get('doctrine')->getManager();
$categorieRepository = $em->getRepository('ComptesBundle:Categorie');
$file = new \SplFileObject($filename);
while (!$file->eof()) {
$line = $file->fgets();
list($word, $categorieID) = explode(':', $line);
$word = trim($word);
$categorieID = (int) $categorieID;
$categorie = $categorieRepository->find($categorieID);
if ($categorie === null) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException("La catégorie n°{$categorieID} est inconnue.");
}
$keyword = new Keyword();
$keyword->setWord($word);
$keyword->setCategorie($categorie);
// Indicateurs
$i++;
// Enregistrement
$em->persist($keyword);
}
// Persistance des données
$em->flush();
// Indicateurs
$output->writeln("<info>{$i} mots-clés importés</info>");
}
示例12: loadJson
/**
* Load file content and decode the json
*/
protected function loadJson()
{
$lines = '';
while (!$this->file->eof()) {
$lines .= $this->file->fgets();
}
$this->json = json_decode($lines);
}
示例13: __construct
public function __construct($csvFile)
{
$file = new SplFileObject($csvFile);
while (!$file->eof()) {
$csv[] = $file->fgetcsv();
}
$this->File = $csv;
}
示例14: __construct
public function __construct($filepath)
{
$file = new \SplFileObject($filepath);
$this->path = $file->getFilename();
while (!$file->eof()) {
$this->content .= $file->fgets();
}
}
示例15: prepare
/**
* Write the compiled csv to disk and return the file name
*
* @param array $sortedHeaders An array of sorted headers
*
* @return string The csv filename where the data was written
*/
public function prepare($cacheFile, $sortedHeaders)
{
$csvFile = $cacheFile . '.csv';
$handle = fopen($csvFile, 'w');
// Generate a csv version of the multi-row headers to write to disk
$headerRows = [[], []];
foreach ($sortedHeaders as $idx => $header) {
if (!is_array($header)) {
$headerRows[0][] = $header;
$headerRows[1][] = '';
} else {
foreach ($header as $headerName => $subHeaders) {
$headerRows[0][] = $headerName;
$headerRows[1] = array_merge($headerRows[1], $subHeaders);
if (count($subHeaders) > 1) {
/**
* We need to insert empty cells for the first row of headers to account for the second row
* this acts as a faux horizontal cell merge in a csv file
* | Header 1 | <---- 2 extra cells ----> |
* | Sub 1 | Subheader 2 | Subheader 3 |
*/
$headerRows[0] = array_merge($headerRows[0], array_fill(0, count($subHeaders) - 1, ''));
}
}
}
}
fputcsv($handle, $headerRows[0]);
fputcsv($handle, $headerRows[1]);
// TODO: Track memory usage
$file = new \SplFileObject($cacheFile);
while (!$file->eof()) {
$csvRow = [];
$row = json_decode($file->current(), true);
if (!is_array($row)) {
// Invalid json data -- don't process this row
continue;
}
foreach ($sortedHeaders as $idx => $header) {
if (!is_array($header)) {
$csvRow[] = isset($row[$header]) ? $row[$header] : '';
} else {
// Multi-row header, so we need to set all values
$nestedHeaderName = array_keys($header)[0];
$nestedHeaders = $header[$nestedHeaderName];
foreach ($nestedHeaders as $nestedHeader) {
$csvRow[] = isset($row[$nestedHeaderName][$nestedHeader]) ? $row[$nestedHeaderName][$nestedHeader] : '';
}
}
}
fputcsv($handle, $csvRow);
$file->next();
}
$file = null;
// Get rid of the file handle that SplFileObject has on cache file
unlink($cacheFile);
fclose($handle);
return $csvFile;
}