function run($port = 10000, $opts = array()) { global $argv; $addr = "127.0.0.1"; $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $__condtmpvar4 = Null; if (isset($opts["file"])) { $__condtmpvar4 = $opts["file"]; } else { $__condtmpvar4 = NULL; } $file = $__condtmpvar4; $repl_vars = get_repl_vars($file); if ($file) { compile_file($file); } else { NULL; } \NamespaceNode::$repling = TRUE; socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1); socket_bind($sock, $addr, $port); socket_listen($sock, 5); prn("Initializing Reph server on ", $addr, ":", $port); accept_loop($sock, $repl_vars); return socket_close($sock); }
/** * 创建运行时文件 * * @author mrmsl <*****@*****.**> * @date 2013-01-22 15:45:33 * @lastmodify 2013-02-18 17:03:00 by mrmsl * * @return void 无返回值 */ private function _buildRuntimeFile() { $filesize = 0; //加载文件大小 $compile = "<?php\n!defined('YAB_PATH') && exit('Access Denied');"; //编译内容 //加载核心文件 foreach ($this->_require_files as $file) { require $file; if (defined('APP_DEBUG') && !APP_DEBUG) { $filesize += filesize($file); $compile .= compile_file($file); } } $require_files = array(CORE_PATH . 'Bootstrap.' . APP_EXT, CORE_PATH . 'Template.' . APP_EXT, CORE_PATH . 'Model.' . APP_EXT, CORE_PATH . 'Logger.' . APP_EXT, CORE_PATH . 'Filter.' . APP_EXT, CORE_PATH . 'Db.' . APP_EXT, CORE_PATH . 'drivers/db/Db' . ucfirst(DB_TYPE) . '.' . APP_EXT); if (is_file($filename = LIB_PATH . 'BaseController.' . APP_EXT)) { //底层控制器类 $require_files[] = $filename; } if (is_file($filename = APP_PATH . 'controllers/Common.' . APP_EXT)) { //项目底层通用控制器类 $require_files[] = $filename; } if (is_file($filename = LIB_PATH . 'BaseModel.' . APP_EXT)) { //底层模型类 $require_files[] = $filename; } if (is_file($filename = APP_PATH . 'models/Common.' . APP_EXT)) { //项目底层通用模型类 $require_files[] = $filename; } //加载核心文件,用空间换时间 if (APP_DEBUG) { //调试 foreach ($require_files as $file) { require $file; } } else { foreach ($require_files as $file) { require $file; $filesize += filesize($file); $compile .= compile_file($file); } file_put_contents(RUNTIME_FILE, $compile); $size = filesize(RUNTIME_FILE); //编译后大小 file_put_contents(LOG_PATH . 'compile_runtime_file.log', new_date() . '(' . format_size($filesize) . ' => ' . format_size($size) . ')' . EOL_LF, FILE_APPEND); } }
function generate() { global $APP; $app_dir = getcwd() . '/' . $APP['NAME']; if (file_exists($app_dir)) { echo "\n"; echo "Warnning: App path[{$app_dir}] already exists!\n"; echo "Overwrite?(n/y): "; $line = strtolower(trim(fgets(STDIN))); if ($line !== 'y') { die; } } echo "\n"; echo "Generate app into: {$app_dir} ...\n"; $template_files = scan_dir(TEMPLATE_DIR); foreach ($template_files as $file) { $src = TEMPLATE_DIR . '/' . $file; $dst = $app_dir . '/' . $file; if (is_dir($src)) { $dst_dir = $dst; } else { $dst_dir = dirname($dst); } if (!file_exists($dst_dir)) { mkdir($dst_dir, 0755, true); } if (is_dir($src)) { continue; } #echo "$src => $dst\n"; $ps = explode('.', $src); $ext = $ps[count($ps) - 1]; if (in_array($ext, array('sh', 'txt', 'conf', 'php'))) { $text = compile_file($src); } else { $text = file_get_contents($src); } file_put_contents($dst, $text); } copy(TEMPLATE_DIR . '/.gitignore', $app_dir . '/.gitignore'); }
/** * 创建运行时文件 * * @author mrmsl <*****@*****.**> * @date 2013-09-26 10:37:40 * * @return void 无返回值 */ private function _buildRuntimeFile() { $filesize = 0; //加载文件大小 $compile = '<?php' . PHP_EOL . "!defined('YAB_PATH') && exit('Access Denied');"; //编译内容 //加载核心文件,用空间换时间 if (APP_DEBUG) { //调试 foreach ($this->_require_files as $file) { require $file; } } else { foreach ($this->_require_files as $file) { require $file; $filesize += filesize($file); $compile .= compile_file($file); } } $require_files = array(CORE_PATH . 'Template' . PHP_EXT, CORE_PATH . 'Controller' . PHP_EXT, CORE_PATH . 'Model' . PHP_EXT, CORE_PATH . 'Logger' . PHP_EXT, CORE_PATH . 'Filter' . PHP_EXT, CORE_PATH . 'Db' . PHP_EXT, CORE_PATH . 'drivers/db/Db' . ucfirst(DB_TYPE) . PHP_EXT, LIB_PATH . 'BaseModel' . PHP_EXT, LIB_PATH . 'SVNDiff' . PHP_EXT, APP_PATH . '/controllers/CommonController' . PHP_EXT, APP_PATH . '/models/CommonModel' . PHP_EXT, LIB_PATH . 'LogModel' . PHP_EXT); //加载核心文件,用空间换时间 if (APP_DEBUG) { //调试 foreach ($require_files as $file) { require $file; } } else { foreach ($require_files as $file) { require $file; $filesize += filesize($file); $compile .= compile_file($file); } file_put_contents(RUNTIME_FILE, $compile); $size = filesize(RUNTIME_FILE); //编译后大小 file_put_contents(LOG_PATH . 'compile_runtime_file.log', new_date() . '(' . format_size($filesize) . ' => ' . format_size($size) . ')' . PHP_EOL, FILE_APPEND); } }
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 365 * 24 * 60 * 60) . " GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); if ($_GET["file"] == "favicon.ico") { header("Content-Type: image/x-icon"); echo lzw_decompress(compile_file('../adminer/static/favicon.ico', 'lzw_compress')); } elseif ($_GET["file"] == "default.css") { header("Content-Type: text/css; charset=utf-8"); echo lzw_decompress(compile_file('../adminer/static/default.css;../externals/jush/jush.css', 'minify_css')); } elseif ($_GET["file"] == "functions.js") { header("Content-Type: text/javascript; charset=utf-8"); echo lzw_decompress(compile_file('../adminer/static/functions.js;static/editing.js', 'minify_js')); } elseif ($_GET["file"] == "jush.js") { header("Content-Type: text/javascript; charset=utf-8"); echo lzw_decompress(compile_file('../externals/jush/modules/jush.js;../externals/jush/modules/jush-textarea.js;../externals/jush/modules/jush-txt.js;../externals/jush/modules/jush-sql.js;../externals/jush/modules/jush-pgsql.js;../externals/jush/modules/jush-sqlite.js;../externals/jush/modules/jush-mssql.js;../externals/jush/modules/jush-oracle.js;../externals/jush/modules/jush-simpledb.js', 'minify_js')); } else { header("Content-Type: image/gif"); switch ($_GET["file"]) { //case "plus.gif": echo compile_file('../adminer/static/plus.gif'); break; //case "cross.gif": echo compile_file('../adminer/static/cross.gif'); break; //Cambiada por boton bootstrap case "up.gif": echo compile_file('../adminer/static/up.gif'); break; case "down.gif": echo compile_file('../adminer/static/down.gif'); break; case "arrow.gif": echo compile_file('../adminer/static/arrow.gif'); break; } } exit;
function compile_file($filename, $recursivelevel = 0, CompilerNamespace $parentnamespace){ global $included_files; $haschildren = 0; $filedisplay = '/' . substr($filename, strlen(ROOT_PDIR)); echo "\n"; $lineprefix = ''; if($recursivelevel > 0){ $lineprefix .= str_repeat(' | ', $recursivelevel-1) . ' |>- '; } if(in_array($filename, $included_files)){ echo $lineprefix; echo "Skipping " . $filedisplay . ", already included!\n"; return false; } //echo "[$recursivelevel] "; $flen = strlen($lineprefix . $filedisplay) + 3; echo $lineprefix; echo "Scanning $filedisplay..." . str_repeat(' ', max(80 - $flen, 1)); //echo "Scanning " . $filedisplay . "... "; $fh = fopen($filename, 'r'); if(!$fh) die('Unable to open [' .$filename . '] for reading.'); $contents = ''; $linenumber = 0; $codenumber = 0; $incomment = false; $lastwasending = false; // Will get reset to an internal one if there is one defined. $namespace = $parentnamespace; $namespacename = null; $namespacewrote = false; while(!feof($fh)){ $line = trim(fgets($fh, 1024)); ++$linenumber; // Skip blank lines. if($line == '') continue; // If the last line was an ending block and it's continuing on... then the script actually does need it. if($lastwasending){ ++$codenumber; $contents .= '?>' . "\n"; $lastwasending = false; } // Skip the opening <?php line. if($line == '<?php' && $codenumber == 0) continue; // Single-line comment? if(preg_match('#^/[\*]+.*[\*]+/$#', $line)) continue; // Another single line comment? if(strpos($line, '//') === 0) continue; // Opening of a comment? if(!$incomment && preg_match('#^/[\*]+#', $line)){ $incomment = true; continue; } // End of a comment? if($incomment && preg_match('#[\*]+/$#', $line)){ $incomment = false; continue; } // In a multiline comment? if($incomment) continue; // Namespaces must be first in the code! // If the parent namespace was defined and is identical, // then don't worry about anything, as the parent will take care of opening and closing it. if(strpos($line, 'namespace ') === 0){ $namespacename = preg_replace('#[^a-zA-Z\\\\]#', '', substr($line, 10)); // Was this the same namespace as the parent? If so, I don't need to do anything. if($namespacename != $parentnamespace->name){ // Close the previous namespace before I open a new one! $contents .= $parentnamespace->getClosingTag(); // And start a new one. $namespace = new CompilerNamespace($namespacename); $contents .= $namespace->getOpeningTag(); ++$codenumber; } continue; } // If recursion is enabled, we will recurse into REQUIRE_ONCE statements. // And if the namespace is global.... if(strpos($line, 'require_once') === 0 && $recursivelevel <= MAX_RECURSE_LEVEL){ // Trim off everything but the filename. // Since this is code and it can be written in a variety of ways, I need to be as flexible as possible in reading it. // Easiest way, trim off the first 12 characters, ("require_once"). $subfile = substr($line, 12); // Now, the only thing left should be a semicolon, some spaces, and maybe a couple parenthesis. $subfile = trim($subfile, " \t\n\r\0\x0B();"); //$subfile = preg_replace('#require_once[ ]*\([ ]*([^\)]*)[ ]*\)[ ]*;#', '$1', $line); // The file probably has relative paths... $replaces = [ '__DIR__' => "'" . dirname($filename) . "'", 'ROOT_PDIR' => "'" . ROOT_PDIR . "'" ]; $subfile = str_replace(array_keys($replaces), array_values($replaces), $subfile); // If this looks like a variable or something, skip it! if(strpos($subfile, '$') !== false){ // Skip } elseif(strpos($subfile, '::') !== false){ // Skip } elseif(strpos($subfile, '#SKIPCOMPILER') !== false){ // Skip } else{ // I'm using eval here because the line otherwise is a valid PHP string, just split into parts. // it's the easiest way to take a string such as '/somewhere/blah' . '/' . 'foo mep.php' // and combine them. eval("\$subfile = $subfile;"); if(!file_exists($subfile)){ echo "\nWARNING, $subfile does not appear to exist! Unable to compile."; echo "\nSource: $filename:$linenumber ($line)"; $filecontents = ''; } else{ $filecontents = compile_file($subfile, ($recursivelevel+1), $namespace); } // Trim the root directory and put a location-independent one instead. $subfilerelative = substr($subfile, strlen(ROOT_PDIR)); // If this file could not be minified, false will be returned. if($filecontents !== false){ $haschildren++; $line = '### REQUIRE_ONCE FROM ' . $subfilerelative . "\n" . $filecontents . "\n"; // Do I need to re-open my namespace? // This doesn't actually have any effect if it's already open :) $line .= $namespace->getOpeningTag(); } } } // Is this line an ending block? if($line == '?>'){ $lastwasending = true; continue; } ++$codenumber; //if($codenumber % 10 == 0) $line = '## ' . basename($filename) . ':' . $linenumber . "\n" . $line; // I need to make sure that a namespace was written already. // This is because the namespace must be the first line in the document. /* if(!$namespacewrote){ // Was this the same namespace as the parent? If so, I don't need to do anything. if($namespace != $parentnamespace){ // Close the previous namespace before I open a new one! $contents .= "} // ENDING NAMESPACE " . $parentnamespace . "\n"; $contents .= "namespace {\n"; ++$codenumber; $contents .= $line . "\n"; $namespacewrote = true; } $namespacewrote = true; } */ $contents .= $line . "\n"; } // Before I return, I need to check and see if the parent had a different namespace. // If it did... I should probably close mine so the parent can reopen its namespace. if($namespace->name != $parentnamespace->name){ $contents .= $namespace->getClosingTag(); } if($haschildren){ echo "\n"; $lineprefix = ''; if($recursivelevel > 0){ $lineprefix .= str_repeat(' | ', $recursivelevel-1) . ' |>- '; } $flen = strlen($lineprefix . $filedisplay) + 3; echo $lineprefix . $filedisplay . "..." . str_repeat(' ', max(89 - $flen, 1)) . "Found $codenumber lines and $haschildren children files"; } else{ echo "Found $codenumber lines!"; } return $contents; }