/** * Notify observers with some values. * @param string $value */ function notify($value) { // only notify in development environment... if (Fari_ApplicationEnvironment::isDevelopment()) { // save the info $this->value = $value; // notify each of our observers foreach ($this->observers as $observer) { $observer->update($this); } } }
/** * Include layout file and view file included in $template var. * @param string $layout file path * @param string $view file path */ private function includeLayoutAndView($layout, $view) { // we are defining our own var $template so check if exists assert('!array_key_exists(\'template\', $this->values); // $template variable will be overwritten, do not use it'); // import key:value array into symbol table extract($this->values, EXTR_SKIP); // display paths to files in development mode $devMode = Fari_ApplicationEnvironment::isDevelopment(); ob_start(); // save view into template var if ($devMode) { echo "\n<!-- begin {$view} -->\n"; } include $view; if ($devMode) { echo "\n<!-- end {$view} -->\n"; } $template = ob_get_contents(); ob_end_clean(); // call parent layout if ($devMode) { echo "<!-- begin {$layout} -->\n"; } include $layout; if ($devMode) { echo "\n<!-- end {$layout} -->\n"; } }
/** * Generates a link to an image with alt in /public. * @example <img alt="Bg" src="/images/bg.jpg?1213337144" /> * @param string $img path */ function imageTag($img) { // preconditions assert('!empty($img); // image file not defined'); assert('is_string($img); // pass filename as a string'); // trim whitespace $img = trim($img); // prepend slash? if (substr($img, 0, 1) !== '/') { $img = "/{$img}"; } // determine file so we can generate alt tag $file = ucfirst(str_replace("-", " ", current(explode('.', end(explode('/', $img)))))); // append timestamp only in dev environment $mktime = Fari_ApplicationEnvironment::isDevelopment() ? '?' . mktime() : ''; // echo with trailing timestamp echo "<img alt=\"{$file}\" src=\"" . WWW_DIR . "/public{$img}" . $mktime . '" />'; }