Replace executable code.

@return \Illuminate\Support\Collection
979680
private function replaceExecutableCode($files)
    {
        return $files->map(function ($item) {
            return collect($item)
                ->map(function ($value) {
                    return (new Resolver())->recursivelyFindAndReplaceExecutableCode(
                        $value
                    );
                })
                ->all();
        });
    }
319730
private function replaceTabs($code)
    {
        if ($this->options['tabReplace'] !== null) {
            return str_replace("\t", $this->options['tabReplace'], $code);
        }

        return $code;
    }
985803
public function getReplacements()
    {
        $replaces = [
            'extends' => $this->extends,
            'section' => $this->section,
            'content' => $this->content,
        ];

        return $this->customReplacements + $replaces;
    }
191799
protected function prepareReplacements(Exception $exception)
    {
        $statusCode = $this->getStatusCode($exception);

        if (! $message = $exception->getMessage()) {
            $message = \sprintf('%d %s', $statusCode, Response::$statusTexts[$statusCode]);
        }

        $replacements = [
            ':message' => $message,
            ':status_code' => $statusCode,
        ];

        if ($exception instanceof MessageBagErrors && $exception->hasErrors()) {
            $replacements[':errors'] = $exception->getErrors();
        }

        if ($exception instanceof ValidationException) {
            $replacements[':errors'] = $exception->errors();
            $replacements[':status_code'] = $exception->status;
        }

        if ($code = $exception->getCode()) {
            $replacements[':code'] = $code;
        }

        if ($this->runningInDebugMode()) {
            $replacements[':debug'] = [
                'line' => $exception->getLine(),
                'file' => $exception->getFile(),
                'class' => \get_class($exception),
                'trace' => \explode("\n", $exception->getTraceAsString()),
            ];

            // Attach trace of previous exception, if exists
            if (! \is_null($exception->getPrevious())) {
                $currentTrace = $replacements[':debug']['trace'];

                $replacements[':debug']['trace'] = [
                    'previous' => \explode("\n", $exception->getPrevious()->getTraceAsString()),
                    'current' => $currentTrace,
                ];
            }
        }

        return \array_merge($replacements, $this->replacements);
    }
193401
public function flushCode()
    {
        if ($this->hasValidCode()) {
            $this->addCodeBufferToHistory();
            $code = $this->code;
            $this->popCodeStack();

            return $code;
        }
    }
969895
protected function code()
    {
        $files = $out = [];

        if (isset($this->manifest->code->file)) {
            $files = array_map([$this, 'path'], (array) $this->manifest->code->file);
        } else {
            if (($cwd = getcwd()) !== false && chdir($this->dir)) {
                $files = (array) glob('*.php');
            }
        }

        $pathFrom = (string) new FindTextpattern() . '/index.php';

        foreach ($files as $path) {
            if (file_exists($path) && is_file($path) && is_readable($path)) {
                $includePath = $this->getRelativePath($pathFrom, realpath($path));

                if ($includePath !== $path) {
                    $out[] = "include txpath.'/".addslashes($includePath)."';";
                } else {
                    $out[] = "include '".addslashes($includePath)."';";
                }
            }
        }

        if (isset($cwd) && $cwd !== false) {
            chdir($cwd);
        }

        return implode("\n", $out);
    }
1360494
private function loadResourceFiles()
    {
        return $this->replaceExecutableCode(
            $this->loadResourcesFiles()
        )->mapWithKeys(function ($value, $key) {
            return [$this->removeExtension($key) => $value];
        });
    }
1077845
private function _compile() {
		
		// remove spaces
		$this->_result = str_replace('{{ ', '{{', $this->_content);
		$this->_result = str_replace(' }}', '}}', $this->_result);
		
		// check if
		if ($this->ifs) {
			foreach ($this->ifs as $key => $val) {
				$this->_setBool($key, $val);
			}
			empty($this->ifs);
		}
		
		// check loop
		if ($this->loops) {
			foreach ($this->loops as $key => $val) {
				$this->_setArray($key, $val);
			}
			empty($this->loops);
		}
		
		// check static replaces
		if ($this->vars) {
			foreach ($this->vars as $key => $val) {
				$this->_setString($key, $val);
			}
			empty($this->vars);
		}
		
		// include global vars
		if (is_array($this->injects)) {
			foreach ($this->injects as $inject) {
				global $ {
					$inject
				};
			}
			extract($this->injects);
		}
		
		// remove if and loop traces
		$this->_result = preg_replace("/<if\..*?>(.*?)<\/if\..*?>/s", '', $this->_result);
		$this->_result = preg_replace("/<loop\..*?>(.*?)<\/loop\..*?>/s", '', $this->_result);
		
		// check dynamic variables
		$pattern = "\{\{(.*?)\}\}";
		preg_match_all("/" . $pattern . "/", $this->_result, $matches, PREG_SET_ORDER);
		foreach ($matches as $block) {
			$chunk = $block[0];
			$codes = '<?php ' . $this->config['echo'] . '(' . trim($block[1]) . ')' . '; ?>';
			$this->_result = str_replace($chunk, $codes, $this->_result);
		}
		
		// attempt to create cache file for this template in storage directory
		$cache_file = md5($this->_filename) . '.compiled';
		$cache = $this->config['dir_cache'] . '/' . $cache_file;
		$fd = @fopen($cache, 'w+');
		@fwrite($fd, $this->_result);
		@fclose($fd);
		
		// when failed, try to create in /tmp
		if (!file_exists($cache)) {
			$cache = '/tmp/' . $cache_file;
			$fd = @fopen($cache, 'w+');
			@fwrite($fd, $this->_result);
			@fclose($fd);
		}
		
		// if template cache file created then include it, else use eval() to compile
		if (file_exists($cache)) {
			ob_start();
			include $cache;
			$this->_compiled = ob_get_contents();
			ob_end_clean();
			@unlink($cache);
		} else {
			ob_start();
			eval('?>' . $this->_result . '<?php ');
			$this->_compiled = ob_get_contents();
			ob_end_clean();
		}
	}
82851
public function actionRebuild() {
        $module = \jacmoe\mdpages\Module::getInstance();

        if(!is_dir(Yii::getAlias($module->pages_directory))) {
            $this->stderr("Execution terminated: the repository to update does not exist - please run init first.\n", Console::FG_RED);
            return self::EXIT_CODE_ERROR;
        }

        if (!$this->acquireMutex()) {
            $this->stderr("Execution terminated: command is already running.\n", Console::FG_RED);
            return self::EXIT_CODE_ERROR;
        }

        $files = FileHelper::findFiles(Yii::getAlias('@pages'), [
            'only' => ['*' . $module->page_extension],
        ]);

        $this->updateDB($files, false);

        $this->releaseMutex();
        return self::EXIT_CODE_NORMAL;
    }
416019
public function sniffCode() {
    $task = $this->taskExecStack()
      ->dir($this->bltRoot)
      ->exec("{$this->bin}/phpcs")
      ->exec("composer validate");
    $result = $task->run();

    return $result->getExitCode();
  }
1233624
public function run()
    {
        // Run compilation based on class dependencies.
        $this->runCompilationByArrangedPriority();

        // Run remaining components (if any).
        foreach ($this->components as $name => $classes) {
            $this->compileGroupClasses($name, $classes);
        }

        // Append application file to the bottom.
        $original = $this->config->get('compile.files', []);

        foreach ($original as $class) {
            $this->collection['added'][] = $class;
        }

        $this->config->set('compile.files', $this->collection['added']);

        return new Fluent([
            'added'   => $this->collection['added'],
            'missing' => $this->collection['missing'],
        ]);
    }
591249
public function getReplacements()
    {
        $replacements = array_merge(parent::getReplacements(), ['root_namespace' => $this->getAppNamespace()]);

        if ($this->scaffold) {
            return array_merge($replacements, $this->scaffolder->toArray());
        }

        return $replacements;
    }
1138986
public function replace() {

		if(null !== $this -> match) {

			foreach($this -> match[0] as $index => $match) {

				$code = '<?php endforeach; ?>';
				$this -> line = preg_replace('/' . preg_quote($this -> match[0][$index], '/') . '/', $code, $this -> line , 1);
			}
		}

		return $this;
	}
1359151
public function replaceMocksWithConditions()
    {
        foreach ($this->parameters as $parameter => $condition) {
            $this->regrex = preg_replace("/{{$parameter}}/", $condition, $this->regrex);
        }

        return $this;
    }
814325
public function compile()
    {
        $sql = array();

        if (isset($this->select)) {
            $sql[] = 'SELECT ' . implode(',', $this->select);
        }

        if (isset($this->update)) {
            $sql[] = 'UPDATE';
            $sql[] = $this->update['table'];
            $sql[] = 'SET';

            $blocks = array();
            foreach ($this->update['values'] as $key => $value) {
                $blocks[] = $key . ' = ' . $value;
            }

            $sql[] = implode(',', $blocks);
        }

        if (isset($this->delete)) {
            $sql[] = "DELETE ";
        }

        if (isset($this->insert)) {
            $sql[] = 'INSERT INTO';
            $sql[] = $this->insert['table'];

            $fields = array();
            $replaces = array();

            foreach ($this->insert['values'] as $key => $value) {
                $fields[] = '`' . $key . '`';
                $replaces[] = $value;
            }

            $sql[] = '(' . implode(',', $fields) . ')';
            $sql[] = (count($this->insert['values']) > 1) ? 'VALUES' : 'VALUE';
            $sql[] = '(' . implode(',', $replaces) . ')';
        }

        if (isset($this->replace)) {
            $sql[] = 'REPLACE INTO';
            $sql[] = $this->replace['table'];

            $fields = array();
            $replaces = array();

            foreach ($this->replace['values'] as $key => $value) {
                $fields[] = '`' . $key . '`';
                $replaces[] = $value;
            }

            $sql[] = '(' . implode(',', $fields) . ')';
            $sql[] = (count($this->replace['values']) > 1) ? 'VALUES' : 'VALUE';
            $sql[] = '(' . implode(',', $replaces) . ')';
        }

        if (isset($this->from)) {
            $sql[] = 'FROM ' . implode(',', $this->from);
        }

        foreach ($this->where as $index => $where) {

            if (!is_string($where['column'])) {
                throw new \OtherCode\Database\Exceptions\QueryException("The column field is not a string in where clause.");
            }

            if (!is_string($where['operator']) || !in_array($where['operator'], $this->operators)) {
                throw new \OtherCode\Database\Exceptions\QueryException("Invalid operator in where clause.");
            }

            if (gettype($where['value']) == 'string' && $where['quoted'] === true) {
                $where['value'] = '"' . $where['value'] . '"';
            }

            unset($where['quoted']);

            $sentence = ($index == 0) ? "WHERE " : "AND ";
            $sql[] = $sentence . implode(" ", $where);

        }

        if (isset($this->group)) {
            $sql[] = 'GROUP BY ' . $this->group;
        }

        foreach ($this->order as $index => $order) {

            if (!in_array($order[1], array('ASC', 'DESC'))) {
                throw new \OtherCode\Database\Exceptions\QueryException('Invalid order by value, must be ASC or DESC.');
            }

            $sql[] = 'ORDER BY ' . implode(" ", $order);
        }

        if (isset($this->limit)) {
            $sql[] = 'LIMIT ' . implode(" ", $this->limit);
        }

        return trim(implode(" ", $sql));
    }
312044
protected function compileControllerStub()
    {
        $stub = $this->files->get(__DIR__ . '/../stubs/controller.stub');

        $this->replaceClassName($stub, "controller")
            ->replaceModelPath($stub)
            ->replaceModelName($stub)
            ->replaceSchema($stub, 'controller');


        return $stub;
    }
723119
protected function replaceDefaultSymfonyLineDumpers()
    {
        HtmlDumper::$defaultOutput =
        CliDumper::$defaultOutput =
            function ($line, $depth, $indentPad) {
                if (-1 !== $depth) {
                    echo str_repeat($indentPad, $depth).$line.PHP_EOL;
                }
            };
    }