This repository has been archived on 2020-02-18. You can view files and clone it, but cannot push or open issues or pull requests.
ical-drupal-calendar/includes/FileReader.php

56 lines
1.1 KiB
PHP

<?php
namespace Pandy06269\iCalDrupal\includes;
class FileReader
{
protected $handle;
protected $path;
public function __construct($filePath)
{
$this->path = substr($filePath, 0, 1) == DIRECTORY_SEPARATOR
? $filePath
: sprintf('%s/%s', getcwd(), $filePath);
}
public function __destruct()
{
if (!is_null($this->handle))
{
@fclose($this->handle);
}
}
public function getPath()
{
return $this->path;
}
public function read()
{
$this->open();
$line = fgets($this->handle);
if ($line !== false)
{
$line = rtrim($line);
}
return $line;
}
private function open()
{
global $php_errormsg;
if (is_null($this->handle))
{
$this->handle = @fopen($this->path, 'r');
if (!is_resource($this->handle))
{
throw new \Exception(sprintf('Error reading file "%s": %s', basename($this->path), $php_errormsg));
}
}
}
}