/** * Updates resource using modified references * @param array $updates * @throws \InvalidArgumentException */ protected function save($updates) { $out = ''; if (qtil\ArrayUtil::isIterable($updates)) { foreach ($updates as $section => $values) { if (is_numeric($section)) { throw new \InvalidArgumentException(); } $this->array[$section] = $updates[$section]; } } if (qtil\ArrayUtil::isIterable($this->array)) { foreach ($this->array as $section => $values) { $out .= '[' . $section . ']' . PHP_EOL; foreach ($values as $key => $value) { $out .= $key . '=' . $value . PHP_EOL; } $out .= PHP_EOL; } } $stream = $this->getStream(); if (!$stream->isOpen()) { $stream->open(); } $stream->truncate(0); $writer = new qio\File\Writer($stream); $writer->write($out); $stream->close(); }
/** * Updates resource using modified references * @param array $updates * @throws \InvalidArgumentException */ protected function save($updates) { if ($updates instanceof \qtil\Interfaces\Collection) { $updates = $updates->toArray(); foreach ($updates as $key => $values) { if (!array_key_exists($key, $this->array[0])) { $this->array[0][$key] = []; } if (array_key_exists($key, $this->array[0])) { if (is_null($values)) { unset($this->array[0][$key]); } else { $this->array[0][$key] = $values; } } } } $encoder = new Filter\Encoder(); $out = $encoder($this->array[0]); $resource = $this->getResource(); $stream = new qio\File\Stream($resource, qio\Stream\Mode::ReadWriteTruncate); if (!$stream->isOpen()) { $stream->open(); } $writer = new qio\File\Writer($stream); $writer->write($out); $stream->close(); }
protected function save($updates) { $dumper = new Filter\Emit(2, 0); foreach ($updates as $key => $value) { $value = $updates[$key]; if (isset($this->array[$key])) { if (is_array($value)) { foreach ($value as $k => $v) { if (is_null($v)) { unset($this->array[$key][$k]); } else { $this->array[$key][$k] = $v; } } } else { if (is_null($value)) { unset($this->array[$key]); } else { $this->array[$key] = $value; } } } } $out = $dumper($this->array); $stream = $this->getStream(); if (!$stream->isOpen()) { $stream->open(); } $stream->truncate(0); $writer = new qio\File\Writer($stream); $writer->write($out); $stream->close(); }
/** * write single byte to stream * @param mixed $byte */ public function writeByte($byte) { parent::write(chr($byte)); }