本文整理汇总了PHP中SplFileObject::fgets方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::fgets方法的具体用法?PHP SplFileObject::fgets怎么用?PHP SplFileObject::fgets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::fgets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: current
public function current()
{
$type = 'unkown';
$isCovered = false;
if (isset($this->lines[$this->position])) {
$type = $this->lines[$this->position]['type'];
$isCovered = $this->lines[$this->position]['isCovered'];
}
return array('type' => $type, 'isCovered' => $isCovered, 'content' => $this->file->fgets());
}
示例2: 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);
}
}
示例3: 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>");
}
示例4: fgets
function fgets()
{
if (!$this->valid()) {
return false;
}
return parent::fgets();
}
示例5: 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";
}
}
}
示例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: __construct
public function __construct($filepath)
{
$file = new \SplFileObject($filepath);
$this->path = $file->getFilename();
while (!$file->eof()) {
$this->content .= $file->fgets();
}
}
示例8: getLine
/**
* Gets a line from the given resource.
*
* @link http://php.net/manual/en/function.fgets.php
*
* @param int $length If set the reading will end when the given length reached.
*
* @throws \YapepBase\Exception\File\Exception In case the object does not have an opened file.
*
* @return string|bool The line. Or FALSE if the pointer is at the end of the resource, or on error.
*/
public function getLine($length = null)
{
$this->checkIfFileOpened();
if ($this->checkIfPointerIsAtTheEnd()) {
return false;
}
return $this->splFile->fgets();
}
示例9: 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);
}
示例10: loadJsonFromFile
/**
* Loads the config from a json file
*
* @param $configFile
*
* @throws ConfigException
*/
private function loadJsonFromFile($configFile)
{
$file = new \SplFileObject($configFile, 'r+');
$json = $file->fgets();
$this->config = json_decode($json);
if (json_last_error() != JSON_ERROR_NONE) {
throw new ConfigException("Problem reading json");
}
}
示例11: freeUsedRequestCount
/**
* Free the used slots
*
* @param $sliced_report_definitions_count
*/
private function freeUsedRequestCount($sliced_report_definitions_count)
{
$this->file_counter->flock(LOCK_EX);
$this->file_counter->rewind();
$used_request_count = (int) $this->file_counter->fgets();
$new_used_request_count = $used_request_count - $sliced_report_definitions_count;
$this->file_counter->ftruncate(0);
$this->file_counter->fwrite($new_used_request_count);
$this->file_counter->flock(LOCK_UN);
}
示例12: SendNewOrderMessage
public static function SendNewOrderMessage($account, $orderId, $PriceSum)
{
$file = new SplFileObject(__ROOT__ . '/application/EmailService/EmailTemplates/order.txt');
$message = '';
while (!$file->eof()) {
$message = $message . $file->fgets();
}
$message = str_replace('@AccountName', $account->account_name, $message);
$message = str_replace('@OrderId', $orderId, $message);
$message = str_replace('@Price', $PriceSum, $message);
mail($account->email, 'Регистрация', $message, 'Content-type:text/html;');
}
示例13: _clearDirectory
/**
* Clears a directory of cached files with the correct header.
*
* @return void
*/
protected function _clearDirectory($path)
{
$dir = new DirectoryIterator($path);
foreach ($dir as $file) {
$fileInfo = new SplFileObject($file->getPathname());
$line = $fileInfo->fgets();
if (preg_match('#^/\\* asset_compress \\d+ \\*/$#', $line)) {
$this->out('Deleting ' . $fileInfo->getPathname());
unlink($fileInfo->getPathname());
}
}
}
示例14: importFile
/**
* Imports given JSON file
* @param string $filePath Path to a JSON file with data to import
* @return array Array with import output - metadata, status, warnings and errors
*/
public function importFile($filePath)
{
$this->tmpFile = new SplFileObject($filePath, "r");
$curState = new JSONImportStateStart(array('meta' => array(), 'result' => array(), 'user_id' => $this->params['user_id']));
$result = array('success' => false);
$stepResult = false;
while (!$this->tmpFile->eof()) {
$curLine = trim($this->tmpFile->fgets());
$stepResult = $curState->processLine($curLine);
// Returns next state for processing
if (!is_array($stepResult)) {
$curState = $stepResult;
// Returned array with results
} else {
$result = $stepResult;
$result['success'] = true;
break;
}
}
return $result;
}
示例15: getContent
/**
*
* because \SplFileObject::fread() is not available before 5.5.11 anyway
*
* returns the full content of a file, rewinds pointer in the beginning and leaves it at the end
* but dont rely on this pointer behaviour
*
* @param \SplFileObject $fileObject
*
* @return \SplString|string
*/
public static function getContent(\SplFileObject $fileObject)
{
if (class_exists('SplString')) {
$result = new \SplString();
} else {
$result = '';
}
$fileObject->rewind();
while (!$fileObject->eof()) {
$result .= $fileObject->fgets();
}
return $result;
}