예제 #1
0
function log_php_errors()
{
    $error = error_get_last();
    # fatal errors
    if ($error["type"] == 1) {
        $message = "PHP Fatal Error: {$error["message"]}\nFile: {$error["file"]}\nLine: {$error['line']}";
        Trax::log($message);
    }
}
예제 #2
0
 static function register_extension($extension)
 {
     if (!in_array($extension, self::$extensions)) {
         if (file_exists(TRAX_LIB_ROOT . "/action_view/handlers/{$extension}.php")) {
             include_once TRAX_LIB_ROOT . "/action_view/handlers/{$extension}.php";
             array_unshift(self::$extensions, $extension);
             Trax::$views_extension = $extension;
         }
     }
 }
예제 #3
0
파일: trax.php 프로젝트: phpontrax/trax
function trax()
{
    global $search, $replace, $quiet;
    //  Get command line argument, if any
    if (!array_key_exists('argc', $GLOBALS) || $GLOBALS['argc'] < 2) {
        usage();
        // print Usage message and exit
    }
    $first_param_is_option = substr($GLOBALS['argv'][1], 0, 1) == "-" ? true : false;
    //  Check for excess arguments
    if ($GLOBALS['argc'] > 3 && !$first_param_is_option) {
        echo "unrecognized command argument " . $GLOBALS['argv'][2] . "\n";
        usage();
    }
    if ($first_param_is_option) {
        foreach ($GLOBALS['argv'] as $arg) {
            if ($arg == '-v' || $arg == '--version') {
                include dirname(__FILE__) . "/vendor/trax/trax.php";
                echo "Trax " . Trax::version() . "\n";
                exit;
            } elseif ($arg == '-h' || $arg == '--help') {
                usage();
            }
        }
    } else {
        //  Destination directory on command line
        $dstdir = $GLOBALS['argv'][1];
        if ($GLOBALS['argv'][2] == '-q' || $GLOBALS['argv'][2] == '--quiet') {
            $quiet = true;
        }
    }
    //  Guarantee it ends with DIRECTORY_SEPARATOR
    if (substr($dstdir, -1, 1) != DIRECTORY_SEPARATOR) {
        $dstdir .= DIRECTORY_SEPARATOR;
    }
    if (!create_dir($dstdir)) {
        return;
    }
    //  Assign real values for symbol substitution
    $replace[0] = realpath($dstdir) . '/config';
    // actual value of
    // the full filesystem path to the
    // Trax config/ directory in the
    // user's work area
    //  copy source directory to destination directory
    copy_dir(SOURCE_DIR, $dstdir);
    $dstdir .= 'vendor/trax/';
    if (!create_dir($dstdir)) {
        return;
    }
    // copy trax core code to vendor folder of project
    copy_dir(TRAX_SOURCE_DIR, $dstdir);
}
예제 #4
0
 /**
 *  Dispatch a request from Apache
 *
 *  Called from file dispatch.php, which is invoked by
 *  {@link http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html Apache mod_rewrite}
 *  whenever a client makes a request.  Actions:
 *  <ol>
 *    <li>Remove forbidden tags and attributes from
 *      {@link http://www.php.net/reserved.variables#reserved.variables.get $_GET},
 *      {@link http://www.php.net/reserved.variables#reserved.variables.post $_POST} and
 *      {@link http://www.php.net/reserved.variables#reserved.variables.request $_REQUEST}.
 </li>
 *    <li>Start a session to keep track of state between requests from
 *      the client.</li>
 *    <li>Construct an ActionController to process the action.</li>
 *    <li>Process the route</li>
 *  </ol>
 *  @uses ActionController::__construct()
 *  @uses ActionController::process_route()
 *  @uses ActionController::process_with_exception()
 *  @uses InputFilter::process_all()
 *  @uses Session::start()
 */
 function dispatch()
 {
     if (TRAX_ENV != 'production') {
         $start = microtime(true);
     }
     try {
         InputFilter::process_all();
         Session::start();
         $ac = new ActionController();
         $ac->process_route();
     } catch (Exception $e) {
         ActionController::process_with_exception($e);
     }
     if (TRAX_ENV != 'production') {
         $duration = "(" . round((microtime(true) - $start) * 1000, 1) . "ms)";
         $url = parse_url($_SERVER['REQUEST_URI']);
         Trax::log("Rendered {$url['path']} {$duration}");
     }
 }
예제 #5
0
파일: make-pkg.php 프로젝트: phpontrax/trax
 *      that they affect.  For each file and directory managed by
 *      Subversion, PackageFileManager first attempts to apply the
 *      RE pattern as coded.  Then it appends leading and trailing '/'
 *      to the pattern and tries again.  The results are hard to
 *      predict.</li>
 *  </ul>
 *
 *  @package PHPonTrax
 *  @version $Id$
 */
chdir("./trax/");
require_once 'PEAR/PackageFileManager2.php';
require_once 'PEAR/Packager.php';
require_once './vendor/trax/inflector.php';
require_once './vendor/trax/trax.php';
$trax_version = Trax::version();
$packagexml = new PEAR_PackageFileManager2();
// Set package options
$e = $packagexml->setOptions(array('baseinstalldir' => 'PHPonTrax', 'packagedirectory' => '.', 'filelistgenerator' => 'file', 'simpleoutput' => true, 'addhiddenfiles' => true, 'dir_roles' => array('doc' => 'doc', 'test' => 'test', 'data' => 'data'), 'exceptions' => array('pear-trax' => 'script', 'pear-trax.bat' => 'script', 'vendor/trax/templates/error.phtml' => 'php', 'vendor/trax/templates/view.phtml' => 'php', 'vendor/trax/templates/mailer_view.phtml' => 'php', 'vendor/trax/templates/scaffolds/add.phtml' => 'php', 'vendor/trax/templates/scaffolds/edit.phtml' => 'php', 'vendor/trax/templates/scaffolds/index.phtml' => 'php', 'vendor/trax/templates/scaffolds/layout.phtml' => 'php', 'vendor/trax/templates/scaffolds/show.phtml' => 'php', 'vendor/trax/templates/scaffolds/scaffold.css' => 'php', 'vendor/trax/templates/scaffolds/generator_templates/form_scaffolding.phtml' => 'php', 'vendor/trax/templates/scaffolds/generator_templates/layout.phtml' => 'php', 'vendor/trax/templates/scaffolds/generator_templates/view_add.phtml' => 'php', 'vendor/trax/templates/scaffolds/generator_templates/view_edit.phtml' => 'php', 'vendor/trax/templates/scaffolds/generator_templates/view_index.phtml' => 'php', 'vendor/trax/templates/scaffolds/generator_templates/view_show.phtml' => 'php', 'vendor/trax/templates/scaffolds/generator_templates/style.css' => 'php'), 'installexceptions' => array('pear-trax' => '/', 'dispatch.php' => 'public')));
$packagexml->setPackage('PHPonTrax');
$packagexml->setSummary('Rapid Application Development Made Easy');
$packagexml->setDescription('PHP port of Ruby on Rails');
$packagexml->setNotes('We\'ve implemented many new and exciting features');
$packagexml->setChannel('pear.phpontrax.com');
$packagexml->setReleaseVersion($trax_version);
$packagexml->setAPIVersion($trax_version);
$packagexml->setReleaseStability('stable');
$packagexml->setAPIStability('stable');
$packagexml->setLicense('MIT License', 'http://www.opensource.org/licenses/mit-license.php');
$packagexml->setPackageType('php');
// this is a PEAR-style php script package
예제 #6
0
 * @author Walt Haas <*****@*****.**>
 */
echo "testing AssetTagHelper\n";
// Call AssetTagHelperTest::main() if this source file is executed directly.
if (!defined("PHPUnit2_MAIN_METHOD")) {
    define("PHPUnit2_MAIN_METHOD", "AssetTagHelperTest::main");
}
require_once "PHPUnit2/Framework/TestCase.php";
require_once "PHPUnit2/Framework/TestSuite.php";
// You may remove the following line when all tests have been implemented.
require_once "PHPUnit2/Framework/IncompleteTestError.php";
//  root Trax files in the test directory
define("TRAX_ROOT", dirname(__FILE__) . "/");
require_once 'testenv.php';
Trax::$public_path = dirname(__FILE__) . "/public";
Trax::$url_prefix = "/testprefix";
require_once "action_view/helpers.php";
require_once "inflector.php";
require_once "action_view/helpers/url_helper.php";
require_once "action_view/helpers/asset_tag_helper.php";
require_once "trax_exceptions.php";
//  parameters need by UrlHelper
$_SERVER['HTTP_HOST'] = 'www.example.com';
$_SERVER['SERVER_PORT'] = '80';
//  referenced by the AssetTagHelper constructor
$GLOBALS['JAVASCRIPT_DEFAULT_SOURCES'] = array('this', 'that');
/**
 * Test class for AssetTagHelper.
 * Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:17:32.
 */
class AssetTagHelperTest extends PHPUnit2_Framework_TestCase
예제 #7
0
파일: boot.php 프로젝트: phpontrax/trax
    # or change the string to manually set it. (development | test | production)
    define('TRAX_ENV', $_SERVER['TRAX_ENV'] ? $_SERVER['TRAX_ENV'] : "development");
}
# Determine the path to this applications trax folder
if (!defined('TRAX_ROOT')) {
    define("TRAX_ROOT", dirname(dirname(__FILE__)));
}
# Determine where your system php libs path
if (!defined('PHP_LIB_ROOT')) {
    $php_dir = trim(exec('pear config-get php_dir'));
    if (is_dir($php_dir)) {
        define('PHP_LIB_ROOT', $php_dir);
    } else {
        define('PHP_LIB_ROOT', '/usr/local/lib/php');
    }
    unset($php_dir);
}
# Should we use local copy of the Trax libs in vendor/trax or
# the server Trax libs in the php libs dir defined in PHP_LIB_ROOT
if (is_dir(TRAX_ROOT . "/vendor/trax")) {
    define("TRAX_LIB_ROOT", TRAX_ROOT . "/vendor/trax");
} elseif (is_dir(PHP_LIB_ROOT . "/PHPonTrax/vendor/trax")) {
    define("TRAX_LIB_ROOT", PHP_LIB_ROOT . "/PHPonTrax/vendor/trax");
} else {
    echo "Can't determine where your Trax Libs are located.";
    exit;
}
# Set up Trax environment, framework, and default configuration
include_once TRAX_LIB_ROOT . "/trax.php";
Trax::initialize();
예제 #8
0
echo "creating trax skeleton files\n";
exec("trax " . dirname(__FILE__) . "/trax-standalone");
echo "fetching README\n";
exec("wget http://www.phpontrax.com/downloads/README-standalone.txt");
rename("README-standalone.txt", "README");
chdir("vendor");
echo "fetching PEAR files\n";
exec("wget http://www.phpontrax.com/downloads/PEAR.tar.gz");
echo "untarring PEAR files\n";
exec("tar zxvf PEAR.tar.gz");
echo "removing PEAR tar file.\n";
unlink("PEAR.tar.gz");
echo "creating vendor/trax folder\n";
mkdir("trax");
echo "copying Trax files to vendor folder\n";
exec("cp -Rp ../../trax/vendor/trax/* trax");
#echo "checking out edge Trax from svn\n";
#exec("svn co svn://svn.phpontrax.com/trax/trunk/trax/vendor/trax trax");
chdir("../");
echo "updating config files\n";
$htaccess = file_get_contents("./public/.htaccess");
file_put_contents("./public/.htaccess", str_replace(dirname(__FILE__) . "/trax-standalone/config", "/home/username/trax/config", $htaccess));
$environment = file_get_contents("./config/environment.php");
$environment = str_replace("# define(\"PHP_LIB_ROOT\",    \"/usr/local/lib/php\");", "define(\"PHP_LIB_ROOT\",    dirname(dirname(__FILE__)).\"/vendor/PEAR\");", $environment);
$environment = str_replace("# define(\"TRAX_ROOT\",       dirname(dirname(__FILE__)));", "define(\"TRAX_ROOT\",       dirname(dirname(__FILE__)));", $environment);
file_put_contents("./config/environment.php", $environment);
include "./vendor/trax/trax.php";
$version = Trax::version();
chdir("../");
exec("tar zcvf trax-standalone-" . $version . ".tar.gz trax-standalone");
echo "done creating standalone Trax\n";
예제 #9
0
파일: session.php 프로젝트: phpontrax/trax
 /**
  *  Setup basic session information
  *
  *  Fetch the contents from a specified element of
  *  {@link http://www.php.net/manual/en/reserved.variables.php#reserved.variables.session $_SESSION}
  *  @uses Trax::$session_name
  *  @uses Trax::$session_lifetime
  *  @uses Trax::$session_maxlifetime_minutes
  */
 function init()
 {
     Trax::$session_name = Trax::$session_name ? Trax::$session_name : self::TRAX_SESSION_NAME;
     Trax::$session_lifetime = Trax::$session_lifetime ? Trax::$session_lifetime : self::TRAX_SESSION_LIFETIME;
     Trax::$session_maxlifetime_minutes = Trax::$session_maxlifetime_minutes ? Trax::$session_maxlifetime_minutes : self::TRAX_SESSION_MAXLIFETIME_MINUTES;
     # set the session default for this app
     ini_set('session.name', Trax::$session_name);
     ini_set('session.use_cookies', 1);
     if (Trax::$session_cookie_domain) {
         ini_set('session.cookie_domain', Trax::$session_cookie_domain);
     }
     ini_set('session.cookie_lifetime', Trax::$session_lifetime);
     ini_set('session.gc_probability', 1);
     ini_set('session.gc_maxlifetime', Trax::$session_maxlifetime_minutes * 60);
     ini_set('session.use_trans_sid', 0);
     ini_set('session.auto_start', 0);
     if (Trax::$session_store == 'active_record_store') {
         ini_set('session.save_handler', 'user');
         include_once "session/active_record_store.php";
         $session_class_name = Trax::$session_class_name ? Trax::$session_class_name : 'ActiveRecordStore';
         $ar_session = new $session_class_name();
         session_set_save_handler(array(&$ar_session, 'open'), array(&$ar_session, 'close'), array(&$ar_session, 'read'), array(&$ar_session, 'write'), array(&$ar_session, 'destroy'), array(&$ar_session, 'gc'));
     } else {
         # file store
         ini_set('session.save_handler', 'files');
         if (Trax::$session_save_path) {
             ini_set('session.save_path', Trax::$session_save_path);
         }
     }
 }
예제 #10
0
 /**
  *  Set the environment ActiveRecord expects
  */
 protected function setUp()
 {
     //  Force constructor to get a connection
     Trax::$active_record_connections = array();
     // Set up information that normally comes from database.ini
     Trax::$database_settings[TRAX_ENV] = array('phptype' => 'mysql', 'database' => 'database_development', 'hostspec' => 'localhost', 'username' => 'root', 'password' => '', 'persistent' => true);
 }
예제 #11
0
 /**
  *  Implement the "generate scaffold" command
  *
  *  @param string $model_name
  *  @param string $controller_name
  *  @param string $views
  *  @uses generate_controller()
  *  @uses generate_model()
  *  @uses Inflector::classify()
  *  @uses Inflector::humanize()
  *  @uses Inflector::pluralize()
  *  @uses Inflector::singularize()
  *  @uses Inflector::underscore()
  *  @uses $layout_filename          Set as output from
  *                                  generate_controller().
  *                                  Not changed afterward.
  *  @uses fix_php_brackets()
  */
 function generate_scaffold($model_name, $controller_name, $views = "")
 {
     //echo 'generate_scaffold("'.$model_name.'", "'
     //          .$controller_name.'", "'.$views.'")'."\n";
     if (!($model_exists = $this->generate_model($model_name))) {
         echo "Error - Can't create Model: {$model_name}.\n";
         return;
     }
     Trax::$current_controller_object =& $this;
     $model_class_name = Inflector::classify($model_name);
     $singular_model_name = Inflector::singularize($model_name);
     $plural_model_name = Inflector::pluralize($model_name);
     $human_model_name = Inflector::humanize($model_name);
     try {
         $this->{$singular_model_name} = new $model_class_name();
     } catch (ActiveRecordError $e) {
         echo "Can't create model.\n";
         echo $e->getMessage() . "\n";
         echo "for database '" . ActiveRecord::$database_settings[TRAX_ENV]['database'] . "' on host '" . ActiveRecord::$database_settings[TRAX_ENV]['hostspec'] . "' as user '" . ActiveRecord::$database_settings[TRAX_ENV]['username'] . "'\nDid you configure file " . Trax::$config_path . "/database.ini correctly?\n";
         die;
     }
     if (empty($controller_name)) {
         $controller_name = Inflector::underscore($model_name);
     } else {
         $controller_name = Inflector::underscore($controller_name);
     }
     Trax::$current_controller_name = $controller_name;
     $controller_file = "{$this->controller_path}/" . $controller_name . "_controller.php";
     Trax::$current_controller_path = $controller_file;
     $non_scaffolded_actions = array();
     $illegal_views = array("index", "add", "edit", "show");
     if (is_array($views)) {
         foreach ($views as $view) {
             if (!in_array($view, $illegal_views)) {
                 $non_scaffolded_actions[] = $view;
             }
         }
     }
     $this->generate_controller($controller_name, $non_scaffolded_actions, true);
     if (stristr($controller_name, "/")) {
         $controller_class_name = Inflector::classify(substr($controller_name, strrpos($controller_name, "/") + 1));
         $human_controller_name = Inflector::humanize(substr($controller_name, strrpos($controller_name, "/") + 1));
     } else {
         $controller_class_name = Inflector::classify($controller_name);
         $human_controller_name = Inflector::humanize($controller_name);
     }
     # Generate the controller
     ob_start();
     include "{$this->scaffold_template_path}/controller.php";
     $controller_contents = $this->fix_php_brackets(ob_get_contents());
     ob_end_clean();
     if (!file_exists($controller_file)) {
         if (!file_put_contents($controller_file, $controller_contents)) {
             echo "error creating controller class file: {$controller_file}\n";
         } else {
             echo "create {$controller_file}\n";
         }
     } else {
         echo "exists {$controller_file}\n";
     }
     # Generate the index.phtml view
     $view_file = "{$this->view_path}/index." . Trax::$views_extension;
     ob_start();
     include "{$this->scaffold_template_path}/view_index.phtml";
     $index_contents = $this->fix_php_brackets(ob_get_contents());
     ob_end_clean();
     if (!file_exists($view_file)) {
         if (!file_put_contents($view_file, $index_contents)) {
             echo "error creating view file: {$view_file}\n";
         } else {
             echo "create {$view_file}\n";
         }
     } else {
         echo "exists {$view_file}\n";
     }
     # Generate the add.phtml view
     $view_file = "{$this->view_path}/add." . Trax::$views_extension;
     ob_start();
     include "{$this->scaffold_template_path}/view_add.phtml";
     $add_contents = $this->fix_php_brackets(ob_get_contents());
     ob_end_clean();
     if (!file_exists($view_file)) {
         if (!file_put_contents($view_file, $add_contents)) {
             echo "error creating view file: {$view_file}\n";
         } else {
             echo "create {$view_file}\n";
         }
     } else {
         echo "exists {$view_file}\n";
     }
     # Generate the edit.phtml view
     $view_file = "{$this->view_path}/edit." . Trax::$views_extension;
     ob_start();
     include "{$this->scaffold_template_path}/view_edit.phtml";
     $edit_contents = $this->fix_php_brackets(ob_get_contents());
     ob_end_clean();
     if (!file_exists($view_file)) {
         if (!file_put_contents($view_file, $edit_contents)) {
             echo "error creating view file: {$view_file}\n";
         } else {
             echo "create {$view_file}\n";
         }
     } else {
         echo "exists {$view_file}\n";
     }
     # Generate the show.phtml view
     $view_file = "{$this->view_path}/show." . Trax::$views_extension;
     ob_start();
     include "{$this->scaffold_template_path}/view_show.phtml";
     $show_contents = $this->fix_php_brackets(ob_get_contents());
     ob_end_clean();
     if (!file_exists($view_file)) {
         if (!file_put_contents($view_file, $show_contents)) {
             echo "error creating view file: {$view_file}\n";
         } else {
             echo "create {$view_file}\n";
         }
     } else {
         echo "exists {$view_file}\n";
     }
     # Generate the partial containing the form elments from the database
     $view_file = "{$this->view_path}/_form." . Trax::$views_extension;
     ob_start();
     require "{$this->scaffold_template_path}/form_scaffolding.phtml";
     $_form_contents = $this->fix_php_brackets(ob_get_contents());
     ob_end_clean();
     if (!file_exists($view_file)) {
         if (!file_put_contents($view_file, $_form_contents)) {
             echo "error creating view file: {$view_file}\n";
         } else {
             echo "create {$view_file}\n";
         }
     } else {
         echo "exists {$view_file}\n";
     }
     # Generate the layout for the scaffolding
     $layout_file = $this->layouts_path . "/" . $this->layout_filename . "." . Trax::$views_extension;
     if (!file_exists($this->layouts_path)) {
         mkdir($this->layouts_path);
     }
     ob_start();
     include "{$this->scaffold_template_path}/layout.phtml";
     $layout_contents = $this->fix_php_brackets(ob_get_contents());
     ob_end_clean();
     if (!file_exists($layout_file)) {
         if (!file_put_contents($layout_file, $layout_contents)) {
             echo "error creating layout file: {$layout_file}\n";
         } else {
             echo "create {$layout_file}\n";
         }
     } else {
         echo "exists {$layout_file}\n";
     }
 }
예제 #12
0
// Call UrlHelperTest::main() if this source file is executed directly.
if (!defined("PHPUnit2_MAIN_METHOD")) {
    define("PHPUnit2_MAIN_METHOD", "UrlHelperTest::main");
}
require_once "PHPUnit2/Framework/TestCase.php";
require_once "PHPUnit2/Framework/TestSuite.php";
// You may remove the following line when all tests have been implemented.
require_once "PHPUnit2/Framework/IncompleteTestError.php";
Trax::$url_prefix = "/testprefix";
require_once "action_view/helpers.php";
require_once "action_view/helpers/form_helper.php";
require_once "action_view/helpers/url_helper.php";
//  parameters need by UrlHelper
$_SERVER['HTTP_HOST'] = 'www.example.com';
$_SERVER['SERVER_PORT'] = '80';
Trax::$current_controller_path = 'testcontrol';
/**
 * Test class for UrlHelper.
 * Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:17:32.
 */
class UrlHelperTest extends PHPUnit2_Framework_TestCase
{
    /**
     * Runs the test methods of this class.
     *
     * @access public
     * @static
     */
    public static function main()
    {
        require_once "PHPUnit2/TextUI/TestRunner.php";
예제 #13
0
# Uncomment below to force Trax into production mode when
# you don't control web/app server and can't set it the proper way
# Sets environment from the Apache Vhost (SetEnv TRAX_ENV production)
# or change the string to manually set it. (development | test | production)
# define('TRAX_ENV', $_SERVER['TRAX_ENV'] ? $_SERVER['TRAX_ENV'] : "production");
# Bootstrap the Trax environment, framework, and default configuration
include_once dirname(__FILE__) . "/boot.php";
# Override the Trax framework default values
# Settings in config/environments/* take precedence those specified here
# Trax::$path_seperator = ":";
# Trax::$url_prefix = "~username";
# Use database or cookie-based (default) sessions. (active_record_store,file_store)
# Trax::$session_store = "active_record_store";
# Where should Trax write session files to? (only if using file_store)
# Trax::$session_save_path = Trax::$tmp_path."/sessions";
# SEO naming of urls such as ecommerce-shopping-cart which will be changed on
# incoming requests to underscores. default is null.
# Trax::$url_word_seperator = "-";
# View file type. (html(default),haml)
# ViewHandlers::register_extension('haml');
# Include the application environment specific config file
Trax::include_env_config();
# uncomment to load plugins located in vendor/plugins
# Trax::load_plugins(array('myplugin','myotherplugin'));
# Add new inflection rules using the following format
# (all these examples are active by default):
# Inflections::plural('/^(ox)$/i', '\1en');
# Inflections::singular('/^(ox)en/i', '\1');
# Inflections::irregular('person', 'people');
# Inflections::uncountable('fish', 'sheep', ['more words'] ...);
# Include your application configuration below
예제 #14
0
파일: trax.php 프로젝트: phpontrax/trax
 function load_plugins($plugins = array())
 {
     $plugins = count($plugins) ? $plugins : Trax::$plugins;
     foreach ((array) $plugins as $plugin) {
         if (file_exists(self::$plugins_path . "/{$plugin}/init.php")) {
             include_once self::$plugins_path . "/{$plugin}/init.php";
             $loaded_plugins[] = $plugin;
         }
     }
     Trax::$plugins = (array) $loaded_plugins;
 }
예제 #15
0
 /**
  *  Parse URL, extract controller and action and execute them
  *
  *  @uses $action
  *  @uses $application_controller_file
  *  @uses $application_helper_file
  *  @uses $controller
  *  @uses $controller_class
  *  @uses $controller_file
  *  @uses $controller_object
  *  @uses determine_layout()
  *  @uses execute_after_filters()
  *  @uses $helpers
  *  @uses $helper_file
  *  @uses $helpers_base_path
  *  @uses $keep_flash
  *  @uses $loaded
  *  @uses recognize_route()
  *  @uses raise()
  *  @uses ScaffoldController
  *  @uses Session::unset_var()
  *  @uses $view_file
  *  @uses $views_path
  *  @return boolean true
  */
 function process_route()
 {
     # First try to load the routes and setup the paths to everything
     if (!$this->loaded) {
         if (!$this->recognize_route()) {
             $this->raise("Failed to load any defined routes", "Controller " . $this->controller . " not found", "404");
         }
     }
     //error_log('process_route(): controller="'.$this->controller
     //          .'"  action="'.$this->action.'"');
     # Include main application controller file
     if (file_exists($this->application_controller_file)) {
         include_once $this->application_controller_file;
     }
     # If controller is loaded then start processing
     if ($this->loaded) {
         include_once $this->controller_file;
         if (class_exists($this->controller_class, false)) {
             $class = $this->controller_class;
             $this->controller_object = new $class();
         }
         if (is_object($this->controller_object)) {
             $this->controller_object->controller = $this->controller;
             $this->controller_object->action = $this->action;
             $this->controller_object->controller_path = "{$this->added_path}/{$this->controller}";
             $this->controller_object->views_path = $this->views_path;
             $this->controller_object->layouts_path = $this->layouts_path;
             $this->controller_object->plugin = $this->plugin;
             Trax::$current_controller_path = "{$this->added_path}/{$this->controller}";
             Trax::$current_controller_name = $this->controller;
             Trax::$current_action_name = $this->action;
             Trax::$current_controller_object =& $this->controller_object;
             # Which layout should we use?
             $this->controller_object->determine_layout();
             # Check if there is any defined scaffolding to load
             if (isset($this->controller_object->scaffold)) {
                 $scaffold = $this->controller_object->scaffold;
                 if (file_exists(TRAX_LIB_ROOT . "/scaffold_controller.php")) {
                     include_once TRAX_LIB_ROOT . "/scaffold_controller.php";
                     $this->controller_object = new ScaffoldController($scaffold);
                     Trax::$current_controller_object =& $this->controller_object;
                     $render_options['scaffold'] = true;
                     if (!file_exists($this->controller_object->layout_file)) {
                         # the generic scaffold layout
                         $this->controller_object->layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml";
                     }
                 }
             }
             # Include main application helper file
             if (file_exists($this->application_helper_file)) {
                 include_once $this->application_helper_file;
             }
             # Include helper file for this controller
             if (file_exists($this->helper_file)) {
                 include_once $this->helper_file;
             }
             # Include any extra helper files defined in this controller
             if (count($this->controller_object->helpers) > 0) {
                 foreach ($this->controller_object->helpers as $helper) {
                     if (strstr($helper, "/")) {
                         $file = substr(strrchr($helper, "/"), 1);
                         $path = substr($helper, 0, strripos($helper, "/"));
                         $helper_path_with_file = $this->helpers_base_path . "/" . $path . "/" . $file . "_helper.php";
                     } else {
                         $helper_path_with_file = $this->helpers_base_path . "/" . $helper . "_helper.php";
                     }
                     if (file_exists($helper_path_with_file)) {
                         # Include the helper file
                         include $helper_path_with_file;
                     }
                 }
             }
             # Suppress output
             ob_start();
             #error_log('started capturing HTML');
             # Call the controller method based on the URL
             if ($this->controller_object->execute_before_filters()) {
                 $controller_layout = null;
                 if (isset($this->controller_object->layout)) {
                     $controller_layout = $this->controller_object->layout;
                 }
                 #Get PUBLIC methods from controller object
                 $all_methods = get_class_methods($this->controller_object);
                 # Get Inherited methods from active_controller
                 $inherited_methods = array_merge(get_class_methods(__CLASS__), $this->controller_object->before_filters, $this->controller_object->after_filters);
                 # Get non-inherited methods
                 $action_methods = array_diff($all_methods, $inherited_methods);
                 #error_log("available methods:".print_r($action_methods, true));
                 if (in_array($this->action, $action_methods)) {
                     #error_log('method '.$this->action.' exists, calling it');
                     $action = $this->controller_object->called_action = $this->action;
                     #error_log('calling action routine '
                     #          . get_class($this->controller_object)
                     #          .'::'.$action.'()');
                     $this->controller_object->{$action}();
                 } elseif (file_exists($this->views_path . "/" . $this->action . "." . Trax::$views_extension)) {
                     #error_log('views file "'.$this->action.'"');
                     $action = $this->controller_object->called_action = $this->action;
                 } elseif (method_exists($this->controller_object, "index")) {
                     #error_log('calling action routine '
                     #          . get_class($this->controller_object)
                     #          .'::index()');
                     $action = $this->controller_object->called_action = "index";
                     $this->controller_object->index();
                 } else {
                     //error_log('no action');
                     $methods_size = count($action_methods);
                     if ($methods_size > 1) {
                         $last_method = ($methods_size > 2 ? "," : '') . " and " . array_pop($action_methods);
                     }
                     $this->raise("No action responded to " . $this->action . ". Actions:" . implode(", ", $action_methods) . $last_method, "Unknown action", "404");
                 }
                 if (isset($this->controller_object->layout)) {
                     if ($controller_layout != $this->controller_object->layout) {
                         # layout was set in the action need to redetermine the layout file to use.
                         $this->controller_object->determine_layout();
                     }
                 }
                 #$this->controller_object->execute_after_filters();
                 $this->controller_object->action_called = true;
                 # Find out if there was a redirect to some other page
                 if (isset($this->controller_object->redirect_to) && $this->controller_object->redirect_to != '') {
                     $this->redirect_to($this->controller_object->redirect_to);
                     # execution will end here redirecting to new page
                 }
                 # If render_text was defined as a string render it
                 if (isset($this->controller_object->render_text) && $this->controller_object->render_text != "") {
                     $this->render_text($this->controller_object->render_text);
                     # execution will end here rendering only the text no layout
                 }
                 # If defined string render_action use that instead
                 if (isset($this->controller_object->render_action) && $this->controller_object->render_action != '') {
                     $action = $this->controller_object->render_action;
                 }
                 # Render the action / view
                 if (!$this->controller_object->render_action($action, isset($render_options) ? $render_options : null)) {
                     $this->raise("No view file found {$action} ({$this->view_file}).", "Unknown view", "404");
                 }
                 $this->controller_object->execute_after_filters();
                 # Grab all the html from the view to put into the layout
                 $content_for_layout = ob_get_contents();
                 ob_end_clean();
                 //error_log("captured ".strlen($content_for_layout)." bytes\n");
                 if (isset($this->controller_object->render_layout) && $this->controller_object->render_layout !== false && $this->controller_object->layout_file) {
                     $locals['content_for_layout'] = $content_for_layout;
                     # render the layout
                     #error_log("rendering layout: ".$this->controller_object->layout_file);
                     if (!$this->controller_object->render_file($this->controller_object->layout_file, false, $locals)) {
                         # No layout template so just echo out whatever is in $content_for_layout
                         //echo "HERE";
                         echo $content_for_layout;
                     }
                 } else {
                     # Can't find any layout so throw an exception
                     # $this->raise("No layout file found.", "Unknown layout", "404");
                     # No layout template so just echo out whatever is in $content_for_layout
                     //error_log("no layout found: ".$this->controller_object->layout_file);
                     echo $content_for_layout;
                 }
             }
         } else {
             $this->raise("Failed to instantiate controller object \"" . $this->controller . "\".", "ActionController Error", "500");
         }
     } else {
         $this->raise("No controller found.", "Unknown controller", "404");
     }
     // error_log('keep flash='.var_export($this->keep_flash,true));
     if (!$this->keep_flash) {
         # Nuke the flash
         unset($_SESSION['flash']);
         Session::unset_var('flash');
     }
     return true;
 }
예제 #16
0
 /**
  * Test object()
  */
 public function testObject()
 {
     //  Constructing with no object name and then
     //  calling object with no argument should return null
     $e = new ExtHelpers();
     $this->assertNull($e->object());
     //  Create a dummy controller object
     $d = new DummyController();
     Trax::$current_controller_object = $d;
     //  This should inherit value of current_controller_object
     $e = new ExtHelpers();
     $this->assertEquals('attr value', $e->object('some_attr'));
     //  This should inherit object name from constructor
     $e = new ExtHelpers('some_attr');
     $this->assertEquals('attr value', $e->object());
 }