Beispiel #1
0
 /**
  * Open the stream and return the associated resource.
  *
  * @param   string               $streamName    Stream name (e.g. path or URL).
  * @param   \Hoa\Stream\Context  $context       Context.
  * @return  resource
  * @throws  \Hoa\File\Exception\FileDoesNotExist
  * @throws  \Hoa\File\Exception
  */
 protected function &_open($streamName, Stream\Context $context = null)
 {
     static $createModes = [parent::MODE_READ];
     if (!in_array($this->getMode(), $createModes)) {
         throw new Exception('Open mode are not supported; given %d. Only %s are supported.', 0, [$this->getMode(), implode(', ', $createModes)]);
     }
     preg_match('#^(\\w+)://#', $streamName, $match);
     if ((isset($match[1]) && $match[1] == 'file' || !isset($match[1])) && !file_exists($streamName)) {
         throw new Exception\FileDoesNotExist('File %s does not exist.', 1, $streamName);
     }
     $out = parent::_open($streamName, $context);
     return $out;
 }
Beispiel #2
0
 public function __construct($file = "channels.json")
 {
     try {
         $this->fDB = new ReadWrite($file, File::MODE_READ_WRITE);
     } catch (\Hoa\File\Exception\FileDoesNotExist $exception) {
         File::create($file, false);
         $this->fDB = new ReadWrite($file, File::MODE_READ_WRITE);
     }
     if ($this->fDB->getSize() > 0) {
         $this->read();
     } else {
         $this->write();
     }
 }