/** * Gets the value of a configuration setting. * * @param string $name The name of the setting. If it includes dots, it * can traverse arrays. * @param mixed $default The value to return if the setting has not been * set (defaults to NULL). * @return The value of the setting, or $default. */ public static function setting($name, $default = NULL) { if (strpos($name, '.') === FALSE) { return maybe(self::$settings, $name, $default); } else { $parts = explode('.', $name); $cursor = self::$settings; foreach ($parts as $part) { if (is_array($cursor) && array_key_exists($part, $cursor)) { $cursor = $cursor[$part]; } else { return $default; } } return $cursor; } }
/** * Creates the shared template environment. This will register Tuffy's * default set of template helpers, and if you have defined the setting * `template.initializers`, it will call each of those functions in turn, * which should register more template helpers. * * This method will be called automatically if you define the * `modules.Tuffy_Template` setting to be TRUE. * * @param object $loader The loader to use. If this is NULL, * it will use the loader from Tuffy_Template::getDefaultLoader(). * @param array $options Any additional options to pass to the Twig * environment. If not provided, it will load options from the * `template.twigOptions` setting. */ public static function configure($loader = NULL, $extraOptions = NULL) { if ($loader === NULL) { $loader = self::getDefaultLoader(); } $options = array('debug' => Tuffy::setting('debug')); $settings = Tuffy::setting('template', array()); if (array_key_exists('cachePath', $settings)) { $options['cache'] = $settings['cachePath']; } if ($extraOptions === NULL) { $extraOptions = maybe($settings, 'twigOptions', array()); } $options = $extraOptions + $options; self::$env = new Twig_Environment($loader, $options); self::registerDefaults(); foreach (maybe($settings, 'initializers', array()) as $init) { call_user_func($init); } }
/** * Takes a backtrace as returned by debug_backtrace or * Exception->getTrace() and rewrites it into an array of * Tuffy_Debug_StackFrames. * * @param array $tb The backtrace to rewrite. * @param string|null $fFile The file that the backtrace was generated at. * @param int|null $fLine The line that the backtrace was generated at. */ public static function rewriteBacktrace($tb, $fFile = NULL, $fLine = NULL) { if ($fFile || $fLine) { array_unshift($tb, array('file' => $fFile, 'line' => $fLine)); } $level = 1; $calls = array(); $count = count($tb); while ($level < $count) { $name = $tb[$level]; $loc = $tb[$level - 1]; $calls[] = new self(maybe($name, 'class'), maybe($name, 'type'), maybe($name, 'function'), maybe($loc, 'file'), maybe($loc, 'line')); $level++; } $loc = $tb[$level - 1]; $calls[] = new self(NULL, NULL, '[main]', maybe($loc, 'file'), maybe($loc, 'line')); return $calls; }