public function generate($buffer = false) { $access = $this->_public ? 'public' : 'private'; $argsStr = implode(', ', $this->_arguments); $writeStr = <<<METHODSTR \t/** \t * Method Generated by Bong Admin panel \t */\t\t\t \t{$access} function {$this->_name}({$argsStr}){ \t\t/*TODO Not Implemented Yet*/ \t} } METHODSTR; if (!$buffer) { $endLine = $this->_controller->endLine(); $fp = fopen($this->_controller->filePath(), 'r+'); fseekline($fp, $endLine); $classEndPos = fstrrpos($fp, '}') - 2; fseek($fp, $classEndPos); fwrite($fp, $writeStr, strlen($writeStr)); fclose($fp); } else { return $writeStr; } }
public function setCode($code) { $size = filesize($this->_controller->filePath()); $fd = @fopen($this->_controller->filePath(), 'rb'); if (!$fd) { return false; } //"php://temp/maxmemory:$size" $backup = fopen('php://temp/maxmemory:$size', 'w'); $c = 0; while ($c < $this->_startLine - 1) { fwrite($backup, fgets($fd)); ++$c; } //{ Write the Code $codeFd = fopen('data:text/plain,' . $code, 'rb'); while (($line = fgets($codeFd)) !== false) { fwrite($backup, $this->spaceToTab($line)); } //} fwrite($backup, "\n"); \fseekline($fd, $this->_endLine); while (!feof($fd)) { fwrite($backup, fgets($fd)); } fclose($fd); $fd = @fopen($this->_controller->filePath(), 'w'); if (!$fd) { return false; } fseek($fd, 0); fseek($backup, 0); while (!feof($backup)) { fwrite($fd, fread($backup, 1), 1); } fclose($fd); fclose($backup); return true; }