public function files_for_stylesheet_link_tag() { $css_urls = array(); if ($css_files = $this->get_files_from_manifest(Trax::$assets_path . "/stylesheets/application.css")) { self::reset_assets_dir("stylesheets"); $compiled_css = array(); foreach ($css_files as $file) { if ($this->compress()) { # write files to disk compressed $compiler = new Compiler($file); $compiled_css[$file] = $compiler->process_file(); } else { # copy to assets folder $css_parts = explode("/assets/stylesheets/", $file); $css_urls[] = $this->public_url($css_parts[1]); $this->copy_file($file); } } if ($this->compress()) { $fingerprint = self::fingerprint($css_files); $filename = "application-{$fingerprint}.css"; if ($this->write_file($filename, implode("\n", $compiled_css))) { $css_urls = array($this->public_url($filename)); } } } #print_r($css_urls); return $css_urls; }
/** * utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag attributes * * this is to be used in preProcessing or postProcessing functions, example : * $p = $compiler->getCompiledParams($params); * // get only the rest array as attributes * $attributes = Plugin::paramsToAttributes($p['*']); * // get all the parameters as attributes (if there is a rest array, it will be included) * $attributes = Plugin::paramsToAttributes($p); * * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string * @param string $delim the string delimiter you want to use (defaults to ') * @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior) * * @return string */ public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null) { if (isset($params['*'])) { $params = array_merge($params, $params['*']); unset($params['*']); } $out = ''; foreach ($params as $attr => $val) { $out .= ' ' . $attr . '='; if (trim($val, '"\'') == '' || $val == 'null') { $out .= str_replace($delim, '\\' . $delim, '""'); } elseif (substr($val, 0, 1) === $delim && substr($val, -1) === $delim) { $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, -1) . '"'); } else { if (!$compiler) { // disable double encoding since it can not be determined if it was encoded $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { // escape if auto escaping is disabled, or there was no variable in the string $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; } else { // print as is $escapedVal = '.' . $val . '.'; } $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); } } return ltrim($out); }
public function compile() { $compiler = new Compiler(); $compiler->setReader(new File($this->getTemplatePath())); $compiler->setWriter(new File($this->getScriptPath())); $compiler->compile(); }
public static function validateCode($sourceCode, $language, $testCases) { $inputTestCases = self::bindTestCases($testCases, true); $outputTestCases = self::bindTestCases($testCases, false); $compilerInstance = new Compiler($sourceCode, $language, $inputTestCases, $outputTestCases); $compilerInstance->compile(); return $compilerInstance; }
/** * Create new Template instance and inject its dependency * * @return TemplateEngine */ public static function create() { $te = new TemplateEngine(); $compiler = new Compiler(); $compiler->setTemplateEngine($te); $te->setCompiler($compiler); return $te; }
public function translate($query) { $lexer = new Lexer(); $parser = new Parser(); $compiler = new Compiler($this->schema); $tokens = $lexer->tokenize($query); $request = $parser->parse($tokens); return $compiler->compile($request); }
public function render($input, $scope = null, $includes = array()) { if ($scope !== null && is_array($scope)) { extract($scope); } $parser = new Parser($input, array('includes' => $includes)); $compiler = new Compiler($this->prettyprint); return $compiler->compile($parser->parse($input)); }
public function compile(Compiler $compiler, TemplateFunction $function, array $arguments) { $callback = $function->getCallback(); //simple functions are compiled directly if (is_string($callback)) { $compiler->add($callback); } else { $compiler->add('$environment->getFunction(')->compileString($function->getFunctionName())->add(')->call'); } $compiler->compileArgumentList($arguments); }
public function test_it_compiles_finished_statement() { $str = <<<EOL @finished echo 'shutdown'; @endfinished EOL; $compiler = new Compiler(); $result = $compiler->compile($str); $this->assertEquals(1, preg_match('/\\$__container->finished\\(.*?\\}\\);/s', $result, $matches)); }
public function testLaunchException() { $this->objectManagerMock->expects($this->once())->method('configure')->with($this->getPreferences()); $code = key($this->getOptions()); $arguments = current($this->getOptions()); $exception = new Task\OperationException('Unrecognized operation', Task\OperationException::UNAVAILABLE_OPERATION); $this->taskManagerMock->expects($this->once())->method('addOperation')->with($code, $arguments)->willThrowException($exception); $this->taskManagerMock->expects($this->never())->method('process'); $this->responseMock->expects($this->once())->method('setCode')->with(\Magento\Framework\App\Console\Response::ERROR); $this->assertInstanceOf('\\Magento\\Framework\\App\\Console\\Response', $this->model->launch()); }
function __compile($context, $source, $name) { $sourceStr = __toString($source); /* Compiler initialisieren */ static $compiler; if ($compiler == null) { include_once "compiler.php"; $compiler = new Compiler(); } /* Modul Kompilieren */ $code = $compiler->compile($sourceStr); if (isset($code['Module'])) { /* Libarymodule bearbeiten */ $dir = BIN_DIR . preg_replace("/\\W/", "_", $code['Module']); $name = $dir . ".php"; if (is_dir($dir)) { foreach (__ls_r($dir . "/") as $file) { if (is_dir($file)) { rmdir($file); } else { unlink($file); } } } /* Ordner neu anlegen */ mkdir($dir); chmod($dir, 0777); /* Funktionen niederschreiben */ foreach ($code['Functions'] as $fnName => $body) { $fp = fopen($dir . "/" . $fnName . ".php", 'w'); fwrite($fp, $body); fclose($fp); chmod($dir . "/" . $fnName . ".php", 0777); } /* Name von Mainmodulen anpassen */ } else { $name = BIN_DIR . preg_replace("/\\W/", "_", substr($name, strrpos($name, "/") + 1)) . ".php"; } /* Hauptteil niederschreiben */ if (($fp = @fopen($name, 'w')) == false) { PEAR::raiseError("Die Datei '" . $name . "' kann nicht geöffnet werden!"); } fwrite($fp, $code['Main']); fclose($fp); chmod($name, 0777); /* Leere Sequenz zurückgeben */ return array(); }
public function getFiles() { $src_content = $this->src_content_markup = Compiler::markUp_CHK($this->src_content, array("ignore" => true)); $src_content = $src_content; $src_content = StringUtil::removeAllHtmlComments($src_content); //--------------------------------------------------------- if (!is_null($this->str_replace_silent)) { foreach ($this->str_replace_silent as $key => $value) { $this->src_content_silent = $src_content = str_replace($key, $value, $this->src_content); } } //--------------------------------------------------------- preg_match_all('/(?:[\'\\"]|url\\()([\\-A-Za-z\\/_\\d\\.]+\\.(woff|ttf|mp4|jpg|jpeg|png|gif))/s', $src_content, $files, PREG_SET_ORDER); //--------------------------------------------------------- $this->matches = $files; //--------------------------------------------------------- foreach ($files as $file_key => $filePath) { $arr = array("compilerGlobal" => $this->compilerGlobal, "filePath" => $filePath[1], "forceDownload" => $this->forceDownload, "src_dir" => $this->src_dir, "save_dir" => $this->save_dir, "src_content" => is_null($this->src_content_updated) ? $this->src_content : $this->src_content_updated, "src_content_type" => $this->src_content_type, "relativeToSrc" => $this->relativeToSrc, "src_save_dir" => $this->src_save_dir, "base64" => $this->base64, "compilePath" => $this->compilePath); //--------------------------------------------------------- $arr = SetPublicProp::go($arr, $this->fileProp, false); //--------------------------------------------------------- $newFile = new Compile_File($arr); $this->src_content_updated = $newFile->src_content_updated; $this->images_info[] = $newFile; } //--------------------------------------------------------- if (is_null($this->src_content_updated)) { $this->src_content_updated = $this->src_content; } }
/** * @return Compiler */ public static function instance() { if (Compiler::$instance == null) { Compiler::$instance = new Compiler(); } return Compiler::$instance; }
/** * Returns a callback that binds the data with the template * * @param string $source The template string * @return callable The template binding handler */ public function compile(string $source) : callable { $name = $this->namePrefix . md5(self::VERSION . $source); if (isset($this->compiledTemplates[$name])) { goto returner; } elseif (class_exists($name) === true) { goto instantiator; } if ($this->loadCache($name . '.php') === false) { $code = $this->compiler->compile($source); $formattedCode = sprintf(self::$layout, $name, $code); $this->saveCache($name . '.php', $formattedCode); eval('?>' . $formattedCode); } instantiator: $this->compiledTemplates[$name] = new $name($this->runtime, $this->dataFactory); returner: return $this->compiledTemplates[$name]; }
public static function GetPage($a_id) { $id = Database::Escape($a_id); $result = Database::Query("SELECT * FROM `" . DB_TBL_PAGES . "` WHERE `id` = '" . $id . "'"); if (!$result->HasData()) { die('Unknown page id'); } self::$m_pagename = unserialize($result->GetValue('name')); $doc = unserialize($result->GetValue('compiled')); if (!$doc) { $compiler = new Compiler(); $doc = $compiler->CompilePage($id); } // Plugin Hook $data_object = new stdClass(); $data_object->doc = $doc; ObjMgr::GetPluginMgr()->ExecuteHook("On_PrepareTemplate", $data_object); // Title Content::AddTitle($doc, Locales::GetConstString("PAGE_TITLE", NULL, self::$m_pagename[Locales::$m_locale])); return $doc->getHtml(); }
public static function init() { Compiler::init(array("css" => "min_single", "js" => "min_single", "getServices" => array("except" => Import::getImportPath() . "service.php"), "global" => array("copy" => array(Import::$uber_src_path . "service.php", Import::getImportPath() . "index.php"), "getImages" => true, "code" => array("tmpl" => array("replace" => array("replaceSrc" => false, "\${images}" => Import::$uber_src_path . "/global/images/")))), "compile" => array(array("id" => "min_single", "minify" => true, "copy" => array(), "code" => array("css" => array("singleFile" => true, "path" => "global/css/"), "js" => array("singleFile" => true, "path" => "global/js/"))), array("id" => "min_multi", "minify" => true, "code" => array("css" => array("singleFile" => false, "path" => "global/css/"), "js" => array("singleFile" => false, "path" => "global/js/"))), array("id" => "unmin", "code" => array("css" => array("singleFile" => false, "path" => "global/css/"), "js" => array("singleFile" => false, "path" => "global/js/"))), array("id" => "unmin_raw", "raw" => true)))); //------------------------------------------------ GlobalMas::$host = self::$host; GlobalMas::$pass = self::$pass; GlobalMas::$user = self::$user; GlobalMas::$database = self::$database; UploadHandler::$projectFilesPath = ProjectGlobal::$projectFilesPath; //UploadHandler::$rootFilesPath = "/upload/generated_files/"; self::$filesLocalPath = $_SERVER['DOCUMENT_ROOT'] . "/" . UploadHandler::$rootFilesPath . self::$projectFilesPath; self::$filesPath = GenFun::get_full_url(self::$filesLocalPath); }
/** * Escapes expression in tokens. * @return MacroTokens */ public function escapeFilter(MacroTokens $tokens) { $tokens = clone $tokens; switch ($this->compiler->getContentType()) { case Compiler::CONTENT_XHTML: case Compiler::CONTENT_HTML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_SINGLE_QUOTED_ATTR: case Compiler::CONTEXT_DOUBLE_QUOTED_ATTR: case Compiler::CONTEXT_UNQUOTED_ATTR: if ($context[1] === Compiler::CONTENT_JS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeJs(')->append(')'); } elseif ($context[1] === Compiler::CONTENT_CSS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeCss(')->append(')'); } $tokens->prepend('Latte\\Runtime\\Filters::escapeHtml(')->append($context[0] === Compiler::CONTEXT_SINGLE_QUOTED_ATTR ? ', ENT_QUOTES)' : ', ENT_COMPAT)'); if ($context[0] === Compiler::CONTEXT_UNQUOTED_ATTR) { $tokens->prepend("'\"', ")->append(", '\"'"); } return $tokens; case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($context[0]) . '(')->append(')'); default: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtml(')->append(', ENT_NOQUOTES)'); } case Compiler::CONTENT_XML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); default: $tokens->prepend('Latte\\Runtime\\Filters::escapeXml(')->append(')'); if ($context[0] === Compiler::CONTEXT_UNQUOTED_ATTR) { $tokens->prepend("'\"', ")->append(", '\"'"); } return $tokens; } case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: case Compiler::CONTENT_ICAL: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($this->compiler->getContentType()) . '(')->append(')'); case Compiler::CONTENT_TEXT: return $tokens; default: return $tokens->prepend('$template->escape(')->append(')'); } }
/** * Escapes expression in tokens. * @return MacroTokens */ public function escapeFilter(MacroTokens $tokens) { $tokens = clone $tokens; switch ($this->compiler->getContentType()) { case Compiler::CONTENT_XHTML: case Compiler::CONTENT_HTML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_QUOTED_ATTRIBUTE: case Compiler::CONTEXT_TAG: if ($context[1] === Compiler::CONTENT_JS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeJs(')->append(')'); } elseif ($context[1] === Compiler::CONTENT_CSS) { $tokens->prepend('Latte\\Runtime\\Filters::escapeCss(')->append(')'); } if ($context[0] === Compiler::CONTEXT_TAG) { $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlAttrUnquoted(')->append(')'); } else { $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlAttr(')->append(')'); } return $tokens; case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($context[0]) . '(')->append(')'); default: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlText(')->append(')'); } case Compiler::CONTENT_XML: $context = $this->compiler->getContext(); switch ($context[0]) { case Compiler::CONTEXT_COMMENT: return $tokens->prepend('Latte\\Runtime\\Filters::escapeHtmlComment(')->append(')'); case Compiler::CONTEXT_TAG: return $tokens->prepend('Latte\\Runtime\\Filters::escapeXmlAttrUnquoted(')->append(')'); default: return $tokens->prepend('Latte\\Runtime\\Filters::escapeXml(')->append(')'); } case Compiler::CONTENT_JS: case Compiler::CONTENT_CSS: case Compiler::CONTENT_ICAL: return $tokens->prepend('Latte\\Runtime\\Filters::escape' . ucfirst($this->compiler->getContentType()) . '(')->append(')'); case Compiler::CONTENT_TEXT: return $tokens; default: return $tokens->prepend('$template->escape(')->append(')'); } }
/** * Parses a haml file and returns the compile result. * * @param string $fileName */ public function parseFile($fileName) { if ($this->_cacheEnabled) { if ($this->_storage === null) { throw new Exception('Storage not set'); } $fileId = $this->_storage->generateContentId($fileName); if ($this->isCacheEnabled() && $this->_storage->isFresh($fileId, $fileName)) { return $this->_storage->fetch($fileId); } // file is not fresh, so compile and cache it $this->_storage->cache($fileId, $this->_compiler->parseFile($fileName)); return $this->_storage->fetch($fileId); } // not using cache return $this->_compiler->parseFile($fileName); }
/** * Zkompiluje blok * * @param Block|string|array * @return void */ protected function compileBlock($block) { if ($block instanceof Block) { if (count($block->properties) == 0) { //zahoď prázdné bloky return; } if ($block instanceof Rule) { echo implode(',' . Compiler::NL, $block->selectors); } elseif ($block instanceof FontFace) { echo '@font-face'; } elseif ($block instanceof Media) { echo '@media ' . $block->media[1]; } else { throw new \Exception("Neimplementováno"); } echo ' {' . Compiler::NL; foreach ($block->properties as $property) { if ($block instanceof Media) { $this->compileBlock($property); continue; } $value = $this->compileValue($property[2], TRUE); if ($property[0] == Compiler::$prefixes['important']) { $value .= ' !important'; } elseif ($property[0] == Compiler::$prefixes['raw']) { if ($property[2][0] == 'string') { $value = Compiler::stringDecode($value); } } echo $property[1] . ': ' . $value . ';' . Compiler::NL; } echo '}' . Compiler::NL; } elseif (is_string($block)) { //surové CSS echo $block; } elseif (is_array($block) && $block[0] == 'charset' && $block[1][0] == 'string') { //@charset echo '@charset ' . $block[1][1] . ';' . Compiler::NL; } elseif (is_array($block) && $block[0] == 'import' && $block[1][0] == 'string' && $block[2][0] == 'raw') { //@import echo '@import ' . $block[1][1] . ' ' . $block[2][1] . ';' . Compiler::NL; } else { throw new \Exception("Neimplementováno"); } }
public function CompilePage($a_id, $a_mode = COMPILER_MODE_FRONTEND) { self::$Mode = $a_mode; $result = Database::Query("SELECT * FROM `" . DB_TBL_PAGES . "` WHERE `id` = '" . $a_id . "'"); if (!$result->HasData()) { die("Page with id #" . $a_id . " not found!"); } $this->m_pageid = $result->GetValue('id'); $this->m_pagename = $result->GetValue('name'); $compiled = $this->BuildTemplate($result->GetValue('template') . ".tmpl"); if ($a_mode == COMPILER_MODE_FRONTEND) { Database::Query("UPDATE `" . DB_TBL_PAGES . "` SET `compiled` = '" . Database::Escape(serialize($compiled)) . "' WHERE `id` = '" . $a_id . "'"); return $compiled; } else { return $compiled; } // Do not insert editor pages into db }
/** * Returns a callback that binds the data with the template * * @param *string $template the template string * * @return function The template binding handler */ public function compile($template) { $name = md5($template); if (isset(self::$callbacks[$name])) { return self::$callbacks[$name]; } $file = $this->cache . '/' . $this->prefix . $name . '.php'; if (is_dir($this->cache) && file_exists($file)) { $callback = (include $file); } else { $code = Compiler::i($this, $template)->compile(); if (is_dir($this->cache)) { file_put_contents($file, $code); } //called like: function($data) {}; $callback = @eval('?>' . $code); //$this->checkEval($code); } self::$callbacks[$name] = $callback; return $callback; }
/** * @param array $files * @param string $type */ protected function getTypeTags(array $files, $type) { $tags = ''; $compile = array(); foreach ($files as $file) { if (\Nette\Utils\Strings::startsWith($file, '/') || \Nette\Utils\Strings::startsWith($file, 'http://') || \Nette\Utils\Strings::startsWith($file, 'https://')) { $tags .= $this->createTag($file, $type); } else { $compile[] = $file; } } if (!empty($compile)) { if ($this->concatenate) { $tags .= $this->createTag($this->compiler->getCompiledFile($compile, $type), $type); } else { foreach ($compile as $file) { $tags .= $this->createTag($this->compiler->getCompiledFile(array($file), $type), $type); } } } return $tags; }
protected function parseInserts() { preg_match_all('#<\\?php\\s+(echo|print)\\s+\\$this->insert\\((.*?)\\)\\s*;\\s*\\?>#ims', $this->buffer, $m); foreach ($m[0] as $k => $i) { $sub = new Compiler($this->stripQuotes($m[2][$k]), $this->tplDir, $this->suffix, true); $this->buffer = str_replace($i, $sub->getCompiled(), $this->buffer); } }
public function compile($output = NULL) { if (!is_null($output)) { $this->output_updated = $output; } $value = NULL; foreach ($this->tags as $key => $value) { $link = NULL; //------------------------------------------------- $value->compile(); //------------------------------------------------- if ($this->compileType == "seperate") { if (!is_null($value->save_path)) { $link = Html::getExtLink($value->save_path_relative); } } else { if ($this->compileType == "single") { /*if (is_null($this->mergedCode)) $this->mergedCode = ""; //krumo($value->save_path_relative); $this->mergedCode .= $value->content_updated.PHP_EOL; krumo($this->mergedCode);*/ } } //------------------------------------------------- if (!is_null($value->link_compile_file) && is_null($value->link_compile_file->content)) { $link = Html::getExtLink($value->link_compile_file->filePath); } //------------------------------------------------- if (!is_null($link)) { $this->extLinks .= $link . PHP_EOL; //$this->output_updated = str_replace("</head>",$link.PHP_EOL.'</head>', $this->output_updated); } //krumo($this->output_updated); } //------------------------------------------------- if ($this->compileType == "single" && !is_null($value)) { //krumo($value); $this->import_save_path_relative = "import." . $value->saveas_ext; $this->import_save_path = $this->compilePath . $this->import_save_path_relative; FileFolder::file_put_contents($this->import_save_path, $this->mergedCode); $link = Compiler::insertExtLink($this->import_save_path_relative); //krumo($this->output_updated); $this->extLinks .= $link . PHP_EOL; //$this->output_updated = str_replace("</head>",$link.PHP_EOL.'</head>', $this->output_updated); } else { if ($this->compileType == "inject") { $this->output_updated = str_replace("<head>", "<head>" . PHP_EOL . $this->mergedCode . PHP_EOL, $this->output_updated); } } }
/** * Compiles the file * * @param Compiler $compiler * @param StringsManager $stringsManager */ public function compile(Compiler $compiler, StringsManager $stringsManager) { if (!$this->_ir) { throw new CompilerException('IR related to compiled file is missing'); } /** * External classes should not be compiled as part of the extension */ if ($this->_external) { return; } /** * Compilation context stores common objects required by compilation entities */ $compilationContext = new CompilationContext(); /** * Set global compiler in the compilation context */ $compilationContext->compiler = $compiler; /** * Set global config in the compilation context */ $compilationContext->config = $this->_config; /** * Set global logger in the compilation context */ $compilationContext->logger = $this->_logger; /** * Set global strings manager */ $compilationContext->stringsManager = $stringsManager; /** * Headers manager */ $headersManager = new HeadersManager(); $compilationContext->headersManager = $headersManager; /** * Main code-printer for the file */ $codePrinter = new CodePrinter(); $compilationContext->codePrinter = $codePrinter; /** * Alias manager */ $compilationContext->aliasManager = $this->_aliasManager; $codePrinter->outputBlankLine(); $class = false; $interface = false; foreach ($this->_ir as $topStatement) { switch ($topStatement['type']) { case 'class': if ($interface || $class) { throw new CompilerException("More than one class defined in the same file", $topStatement); } $class = true; $this->compileClass($compilationContext, $this->_namespace, $topStatement); break; case 'interface': if ($interface || $class) { throw new CompilerException("More than one class defined in the same file", $topStatement); } $class = true; $this->compileClass($compilationContext, $this->_namespace, $topStatement); break; case 'comment': $this->compileComment($compilationContext, $topStatement); break; } } /* ensure functions are handled last */ foreach ($this->_functionDefinitions as $funcDef) { $this->compileFunction($compilationContext, $funcDef); } /* apply headers */ $this->applyClassHeaders($compilationContext); $classDefinition = $this->_classDefinition; if (!$classDefinition) { $this->_ir = null; return; } $classDefinition->setOriginalNode($this->_originalNode); $completeName = $classDefinition->getCompleteName(); $path = str_replace('\\', DIRECTORY_SEPARATOR, strtolower($completeName)); $filePath = 'ext/' . $path . '.zep.c'; $filePathHeader = 'ext/' . $path . '.zep.h'; if (strpos($path, DIRECTORY_SEPARATOR)) { $dirname = dirname($filePath); if (!is_dir($dirname)) { mkdir($dirname, 0755, true); } } if ($codePrinter) { /** * If the file does not exists we create it for the first time */ if (!file_exists($filePath)) { file_put_contents($filePath, $codePrinter->getOutput()); if ($compilationContext->headerPrinter) { file_put_contents($filePathHeader, $compilationContext->headerPrinter->getOutput()); } } else { $fileSystem = $compiler->getFileSystem(); /** * Use md5 hash to avoid rewrite the file again and again when it hasn't changed * thus avoiding unnecessary recompilations */ $output = $codePrinter->getOutput(); $hash = $fileSystem->getHashFile('md5', $filePath, true); if (md5($output) != $hash) { file_put_contents($filePath, $output); } if ($compilationContext->headerPrinter) { $output = $compilationContext->headerPrinter->getOutput(); $hash = $fileSystem->getHashFile('md5', $filePathHeader, true); if (md5($output) != $hash) { file_put_contents($filePathHeader, $output); } } } } /** * Add to file compiled */ $this->_compiledFile = $path . '.c'; $this->_ir = null; }
/** * Transform jane code to the target language * * @param string $code * @return string */ public static function write($code) { $compiler = new Compiler(static::parse($code)); return $compiler->transform(); }
function compile_template($template) { if (!class_exists('compiler')) { require_once dirname(__FILE__) . '/' . $this->compiler_file; } $compiled_code = ''; $compiler = new Compiler(); if ($compiler->compile_file($this->template_dir . "/{$template}", $compiled_code)) { $this->write_template($this->compile_dir . "/{$template}", $compiled_code); } else { trigger_error($compiler->get_error_string(), E_USER_ERROR); } }
} $output = ''; foreach (token_get_all($source) as $token) { if (is_string($token)) { $output .= $token; } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) { $output .= str_repeat("\n", substr_count($token[1], "\n")); } elseif (T_WHITESPACE === $token[0]) { // reduce wide spaces $whitespace = preg_replace('{[ \\t]+}', ' ', $token[1]); // normalize newlines to \n $whitespace = preg_replace('{(?:\\r\\n|\\r|\\n)}', "\n", $whitespace); // trim leading spaces $whitespace = preg_replace('{\\n +}', "\n", $whitespace); $output .= $whitespace; } else { $output .= $token[1]; } } return $output; } private function getStub() { $entryPath = $this->getPath($this->entryPoint); return "#!/usr/bin/env php\n<?php\n\nPhar::mapPhar('{$this->pharName}');\n\nrequire 'phar://{$this->pharName}/{$entryPath}';\n\n__HALT_COMPILER();"; } } $root = __DIR__ . '/../'; $compile = new Compiler($root . 'bin/sync', array($root . 'bin', $root . 'src', $root . 'vendor')); $compile->compile('db-sync.phar'); chmod(__DIR__ . '/db-sync.phar', 0777);
public function parse_match_post() { //----------------------------------------------------- if (!empty($this->match[1]) || $this->match[1] != "") { $this->src_path_markup = $this->match[1]; $this->src_path = $this->match[2]; /*if (is_null($this->link_compile_file)) { krumo($this->save_path); $this->save_path_relative = Compiler::cleanURL($this->src_path, ""); $this->save_path = $this->compilePath.$this->save_path_relative; krumo($this->save_path); }*/ } //----------------------------------------------------- if (is_null($this->save_path)) { if (!is_null($this->content)) { if (!file_exists($this->src_path) && !CurlUtil::is_url_exist($this->src_path)) { $this->markup_CFG(); $this->inline = true; $this->save_path_relative = $this->savePath_CFG() . "inline_" . $this->index . "." . $this->saveas_ext; $this->save_path = $this->compilePath . $this->save_path_relative; } else { $path = is_null($this->save_dir) ? Compiler::cleanURL(FileFolder::getFileName($this->src_path, true, true)) : $this->save_dir . FileFolder::getFileName($this->src_path, true); $path = $this->removeModified($path); $this->save_path_relative = $path . "." . $this->saveas_ext; $this->save_path = $this->compilePath . $this->save_path_relative; //krumo(basename($this->save_path)); } } } //----------------------------------------------------- /*if (!is_null($this->replacePath) && !is_null($this->save_path)) { foreach ($this->replacePath as $key => $value) { $this->save_path_relative = str_replace($key, $value, $this->save_path_relative); $this->save_path = str_replace($key, $value, $this->save_path); } }*/ //----------------------------------------------------- /*if (!is_null($this->str_replace_silent)) { foreach ($this->str_replace_silent as $key => $value) { $txt = str_replace($key, $value, $txt); } }*/ //----------------------------------------------------- //if ($this->compileType == "seperate") { //} //----------------------------------------------------- if (!is_null($this->content)) { $prop = array("src_content" => $this->content, "compilerGlobal" => $this->compilerGlobal, "forceDownload" => $this->forceDownload, "src_content_type" => $this->codeType, "src_dir" => !is_null($this->src_path) ? dirname($this->src_path) . "/" : $this->src_path, "src_save_dir" => !is_null($this->save_path_relative) ? dirname($this->save_path_relative) . "/" : $this->save_path_relative, "compilePath" => $this->compilePath); //krumo($this->content); //--------------------------------------------- $this->images = new Compile_Images($prop); //--------------------------------------------- SetPublicProp::go($this->images, $this->imagesProp); //--------------------------------------------- SetPublicProp::go($this->images, $this->filesObj, false); //--------------------------------------------- $this->images->init(); $this->content_updated = $this->images->src_content_updated; if ($this->removeInline && !is_null($this->output_updated)) { $replaceWith = $this->onRemoveMatch_CHK("code"); $this->output_updated = str_replace($this->match[0], $replaceWith, $this->output_updated); } } //----------------------------------------------------- }