<?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));