/** * This is the function that does most of the legwork for creating the PHP code for * this node. Note teh replacement of [?php tags to allow the eval() function * in {@link BedrockTemplate} to work properly * * @return array A list of the differences in the file */ public function updateFile() { $path = $this->getFilePath(); $content = file_get_contents($path); $original_content = $content; $content = str_replace("<?php", "[?php", $content); $content = SilverSmithUtil::replace_tags(BedrockDataRecord::$model_open, BedrockDataRecord::$model_close, "\n\n<@= GeneratedCode @>\n\n\t", $content); $template = new BedrockTemplate($content); $template->bind($this); $new_content = str_replace("[?php", "<?php", $template->render()); // Ensure getCMSFields if ($this->getIsFinal()) { $func = $this->getDecorator() ? "updateCMSFields" : "getCMSFields"; if (!preg_match('/function[\\s]+' . $func . '\\(/', $new_content)) { $new_content = str_replace(self::$model_close, self::$model_close . "\n\n" . $this->getGetCMSFieldsCode(), $new_content); } } // Ensure parent $pattern = "/([A-Za-z0-9_]+)[\\s]+extends[\\s]+([A-Za-z0-9_]+)/"; preg_match_all($pattern, $new_content, $matches, PREG_SET_ORDER); if ($matches) { foreach ($matches as $set) { if (isset($set[2])) { if (substr($set[1], -11) == "_Controller" && $set[2] != $this->getParent() . "_Controller") { //say("Replacing ".$set[1] . " extends " . $set[2] . " with " . $set[1] . " extends {$this->getParent()}_Controller"); $new_content = preg_replace('/' . $set[1] . '[\\s]+extends[\\s]+([A-Za-z0-9_]+)/', $set[1] . " extends {$this->getParent()}_Controller", $new_content); } elseif (substr($set[1], -11) != "_Controller" && $set[2] != $this->getParent()) { // say("Replacing ".$set[1] . " extends " . $set[2] . " with " . $set[1] . " extends {$this->getParent()}"); $new_content = preg_replace('/' . $set[1] . '[\\s]+extends[\\s]+([A-Za-z0-9_]+)/', $set[1] . " extends {$this->getParent()}", $new_content); } } } } $fh = fopen($path, "w"); fwrite($fh, $new_content); fclose($fh); return SilverSmithUtil::get_text_diff($original_content, $new_content); }