Exemplo n.º 1
0
/**
 * Automatically initializes a Raxan Web Page
 * This function will initialize either the last declared subclass of RaxanWebPage
 * or the first subclass with an $autostart property.
 *
 * Example:
 *<code>
 * class Page1 extends RaxanWebPage {    // this will be executed first because of $autostart.
 *     protected $autostart;
 *     protected function _load(){
 *          $this->content('Page1');
 *     }
 * }
 * class Page2 extends RaxanWebPage {    // this will be executed if $autostart was removed from Page1
 *     protected function _load(){
 *          $this->content('Page2');
 *     }
 * }
 * </code>
 */
function raxan_auto_startup($pth)
{
    // fix php CWD path bug when running under apache
    if ($pth != getcwd()) {
        chdir($pth);
    }
    $i = 0;
    $ok = false;
    $page = 'RaxanWebPage';
    $autostart = Raxan::config('autostart');
    if ($autostart === false) {
        return;
    }
    // stop here if autostart is set to false
    $src = trim(ob_get_clean());
    $class = 'RaxanWebPage';
    if ($autostart && is_subclass_of($autostart, $class)) {
        $page = $autostart;
    } else {
        // find page classes
        $cls = get_declared_classes();
        foreach ($cls as $cn) {
            if ($cn == $class) {
                $ok = true;
                continue;
            }
            if (!$ok) {
                continue;
            }
            if (is_subclass_of($cn, $class)) {
                // only init classes that extends RaxanWebPage
                $page = $cn;
                $r = new ReflectionClass($cn);
                if ($r->hasProperty('autostart')) {
                    break;
                }
            }
        }
    }
    // create page
    raxan_auto_create($page, $src);
}
Exemplo n.º 2
0
 /**
  * Transfer page control to the specified php file
  * @param string $file Physical path and file name of the page to be loaded
  * @param string $autoStartClass Name of page class to be initialized
  */
 public function transferTo($file, $autoStartClass = null)
 {
     if ($autoStartClass) {
         self::$mPageId = null;
         ob_start();
     }
     include_once $file;
     if ($autoStartClass) {
         $src = trim(ob_get_clean());
         raxan_auto_create($autoStartClass, $src);
     }
     exit;
 }