/** * Inject static code/markup * * @return string */ public function export() { // the code that will be returned $code = null; // handle callbacks if ($this->has_callbacks()) { // loop em foreach ($this->callbacks as $callback) { // execute callback with myself as only argument call_user_func($callback, $this); } } // have any files? if ($this->files_export->count()) { // loop through all files foreach ($this->files_export as $file) { // resolve file path if (path_is_absolute($file)) { // its absolute already, which is good $filename = $file; } else { // relative path, need to locate it $filename = $this->component()->locate_file($file); } // only import each file once! if (self::$files_imported->contains($filename)) { // already imported that one continue; } else { // push it on to imported stack self::$files_imported->push($filename); } // inject helpful comment ;) //$code .= '/*+++ import source: ' . $filename . ' */' . PHP_EOL; // make sure file actually exists if (ICE_Files::cache($filename)->is_readable()) { // get entire contents of file $code .= $this->get_file_contents($filename) . PHP_EOL; // success //$code .= '/*--- import complete! */' . PHP_EOL . PHP_EOL; } else { //$code .= '/*!!! import failed! */' . PHP_EOL . PHP_EOL; } } } // handle strings if ($this->has_strings()) { //$code .= '/*--- importing strings */' . PHP_EOL; $code .= implode(PHP_EOL, $this->strings->to_array()) . str_repeat(PHP_EOL, 2); //$code .= '/*!!! importing strings complete */' . PHP_EOL; } // all done return $code; }
/** * Generate javascript markup for this script's dynamic code * * @return string */ public function export() { // the markup that will be returned $code = parent::export(); // render rules if ($this->logic->count()) { // begin script generation $code .= sprintf('/*+++ begin script: %s */', $this->token) . PHP_EOL; // loop all logic objects foreach ($this->logic->to_array() as $logic) { // append output of logic export $code .= $logic->export(); } // end script generation $code .= sprintf('/*+++ end script: %s */', $this->token) . PHP_EOL . PHP_EOL; } // all done return $code; }
/** * Return theme stack as an array * * @param boolean $top_down * @return array */ public function theme_stack($top_down = true) { // is there anything in the stack yet? if ($this->themes->count() === 0) { // not good. throw an exception here so we don't have to // act paranoid and check the result of every call to this. throw new Exception('You are trying to get the theme stack before it has been loaded'); } // top down? if (true === $top_down) { // empty cache? if (null === $this->theme_stack_topdown) { // populate cache $this->theme_stack_topdown = $this->themes->to_array(true); } // return reversed array return $this->theme_stack_topdown; } else { // return array as is return $this->themes->to_array(); } }
/** * Find first matching extension file in the path stack * * @param string|array $ext * @param string $file * @return string|boolean */ public final function locate_file($ext, $file) { // handle strings if (is_string($ext)) { // if ext has path delim, use as is if (strpos($ext, self::PATH_DELIM)) { $ext_path = $ext; } elseif (class_exists($ext)) { // get class parts array $ext = $this->loaded->item_at($ext); } } // handle arrays if (is_array($ext)) { $ext_path = implode(self::PATH_DELIM, $ext); } // loop path stack top down foreach ($this->paths->to_array(true) as $basepath) { // build up path $path = $basepath . '/' . $ext_path . '/' . $file; // does file exist at path? if (ICE_Files::cache($path)->is_readable()) { // found one! return $path; } } return false; }