Example #1
0
 /**
  * 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);
         }
     }
 }
Example #2
0
 /**
  * Setup host, port, login and password.
  * @param string $host
  * @param integer $port
  * @param string $username
  * @param string $password
  */
 public function __construct($host = NULL, $port = NULL, $username = NULL, $password = NULL)
 {
     // include PEAR Mail:: if possible...
     // a hack of a production environment on Onebit servers
     if (Fari_ApplicationEnvironment::isProduction()) {
         set_include_path(BASEPATH . '/application/3rdparty/pear:' . get_include_path());
         include 'Mail.php';
         include 'Mail/mime.php';
         include 'SMTP.php';
     } else {
         try {
             // get include paths
             $paths = explode(':/', get_include_path());
             foreach ($paths as $path) {
                 // 'fix' directory
                 if (substr($path, 0, 1) == '.') {
                     // this directory
                     $path = '';
                 } else {
                     // directory from the root
                     $path = "/{$path}/";
                 }
                 // can we call PEAR Mail:: ?
                 if (file_exists("{$path}Mail.php") && file_exists("{$path}Mail/mime.php")) {
                     // include
                     require_once "{$path}Mail.php";
                     require_once "{$path}Mail/mime.php";
                     // switch
                     $found = TRUE;
                     // we are done here
                     break;
                 }
             }
             if ($found !== TRUE) {
                 throw new Fari_Exception("PEAR Mail:: has not been found");
             }
         } catch (Fari_Exception $exception) {
             $exception->fire();
         }
     }
     // setup the connection details
     $this->setConnection($host, $port, $username, $password);
 }
 /**
  * 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";
     }
 }
Example #4
0
}
// Step 1a: Define absolute environment values
// set so that we can check if PHP pages have been accessed directly
if (!defined('FARI')) {
    define('FARI', 'Fari Framework 2.3.15.0 (August 27, 2012)');
}
// get absolute pathname and define it as a constant (server install path)
if (!defined('BASEPATH')) {
    define('BASEPATH', dirname(__FILE__));
}
// www root dir (path for links in your views)
if (!defined('WWW_DIR')) {
    // now we can have the app running in the root
    dirname($_SERVER['SCRIPT_NAME']) == '/' ? define('WWW_DIR', '') : define('WWW_DIR', dirname($_SERVER['SCRIPT_NAME']));
}
// default file extension (.php)
if (!defined('EXT')) {
    define('EXT', '.' . pathinfo(__FILE__, PATHINFO_EXTENSION));
}
// Step 1b: Include database and application specific settings
require BASEPATH . '/config/config' . EXT;
// Step 2a: Initialize Error & Exceptions handling and check environment
require BASEPATH . '/fari/Application/ApplicationDiagnostics' . EXT;
require BASEPATH . '/fari/Application/ApplicationEnvironment' . EXT;
Fari_ApplicationEnvironment::startupCheck();
// Step 2b: Setup contracts handling
require BASEPATH . '/fari/Application/ApplicationContracts' . EXT;
// Step 3: Define global functions, autoloading and those required for framework start
require BASEPATH . '/fari/Application/ApplicationFunctions' . EXT;
// Step 4: Start the whole shebang
Fari_ApplicationRouter::loadRoute();
/**
 * 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 . '" />';
}
 /**
  * Display Error or an Exception.
  * @param string $type PHP Error or Fari Exception
  * @param string $file File where the error was thrown
  * @param string $line Line on which the error was thrown
  * @param string $message Message of the error
  */
 public static function display($type, $file, $line, $message, $trace = NULL)
 {
     // clean output
     ob_end_clean();
     // are we on a production server?
     if (Fari_ApplicationEnvironment::isProduction()) {
         self::productionMessage($message);
     }
     // an Ajax request, display a lightweight message
     if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         die("Fari Exception on line {$line} in \"{$file}\": {$message}");
     }
     // 'build' the header
     self::showHeader();
     // output the message to the user
     echo '<div id="message"><h1>' . $type . '</h1><br />' . $message . '</div>';
     // output information about the file
     echo '<div id="file">File: <b>' . $file . '</b> Line: <b>' . $line . '</b></div>';
     // show the source
     self::showErrorSource($file, $line);
     // show trace if present
     if (!empty($trace)) {
         self::showErrorTrace($trace);
     }
     // show declared classes
     self::showDeclaredClasses();
     // close the whole page properly
     echo '</body></html>';
     // end the misery...
     die;
 }