/** * Starts a controller of application. * * @param String $ControllerModule the module path of the controller, e.g control.main * @return true on successful controller call, false otherwise */ function StartController($ControllerModule) { #FIXME: where empty string is found in parts, it should be replaced with main //Loading controller file try { jf::import($ControllerModule); $Classname = $this->ControllerClass($ControllerModule); } catch (ImportException $e) { $Classname = ""; //looking for a catch controller on a parent folder $CatchControllerModule = $this->GetIterativeCatchController($ControllerModule); try { $LoadStatus = jf::import($CatchControllerModule); $Classname = $this->ControllerClass($CatchControllerModule); } catch (ImportException $e) { if (Controller::$AutoPresent) { $Parts = explode("/", $ControllerModule); // $x=array_shift($Parts); // if ($x=="jf") // array_unshift($Parts,"jf"); $ViewModule = implode("/", $Parts); $control = new AutoController(); if ($control->Start($ViewModule)) { return true; } } } } if (class_exists($Classname)) { $control = new $Classname(); return $control->Start(); } return false; }
/** * Adds a new connection to database manager. * If index is set, the connection is added with the index (which could be a string) * @param DatabaseSetting $dbConfig * @param integer|string $Index * @throws ImportException * @return unknown */ static function AddConnection(DatabaseSetting $dbConfig, $Index = null) { $configIndex = self::FindIndex($dbConfig); if ($configIndex != -1) { return self::$Connections[$configIndex]; } $Classname = "\\jf\\DB_{$dbConfig->Adapter}"; try { jf::import("jf/model/lib/db/adapter/{$dbConfig->Adapter}"); } catch (ImportException $e) { echo "Database adapter '{$dbConfig->Adapter}' not found."; throw $e; } if ($Index === null) { return self::$Connections[] = new $Classname($dbConfig); } else { return self::$Connections[$Index] = new $Classname($dbConfig); } }
<?php jf::import("jf/test/lib/db/adapter/base"); class LibDbMysqliTest extends LibDbBaseTest { private static $Default; public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$Default = \jf\DatabaseManager::$DefaultIndex; $setting = \jf\DatabaseManager::Configuration(); $config = new \jf\DatabaseSetting("mysqli", $setting->DatabaseName, $setting->Username, $setting->Password, $setting->Host, $setting->TablePrefix); \jf\DatabaseManager::AddConnection($config, 2); \jf\DatabaseManager::$DefaultIndex = \jf\DatabaseManager::FindIndex($config); } public static function tearDownAfterClass() { parent::tearDownAfterClass(); \jf\DatabaseManager::$DefaultIndex = self::$Default; } function testQuote() { $insDb = jf::db(); $this->assertEquals("\\'quote-test\\'", $insDb->quote("'quote-test'")); } } class LibDbStatementMysqliTest extends LibDbStatementBaseTest { private static $Default; public static function setUpBeforeClass() {
class RBACException extends \Exception { } class RBACRoleNotFoundException extends RBACException { } class RBACPermissionNotFoundException extends RBACException { } class RBACUserNotFoundException extends RBACException { } jf::import("jf/model/lib/rbac/base"); jf::import("jf/model/lib/rbac/roles"); jf::import("jf/model/lib/rbac/permissions"); jf::import("jf/model/lib/rbac/users"); /** * RBACManager class, provides NIST Level 2 Standard Hierarchical Role Based Access Control * Has three members, Roles, Users and Permissions for specific operations * @author abiusx * @version 1.0 */ class RBACManager extends Model { function __construct() { $this->Users = new RBACUserManager(); $this->Roles = new RoleManager(); $this->Permissions = new PermissionManager(); } /**
$Request = substr($Request, 0, -1); } } if ($Request !== null) { require_once dirname(__FILE__) . "/model/j.php"; // jf static // module, shortcut // to all // jframework // functionality class jf extends \jf\jf { } // make jf static class known both in jf namespace // and in public jf::import("jf/model/frontcontroller"); // front controller module global $jframework; $jframework = \jf\FrontController::GetSingleton(); try { $jframework->Init($Request); } catch (Exception $e) { try { if (class_exists("\\jf\\ErrorHandler", false) && \jf\ErrorHandler::$Enabled) { jf::$ErrorHandler->HandleException($e); } else { echo $e->getTraceAsString(); trigger_error($e->getMessage()); } } catch (Exception $e) { trigger_error($e->getTraceAsString());
/** * Loads PHPUnit framework */ private function LoadFramework() { \jf\Autoload::AddHandler(function ($Classname) { return PhpunitLoaderPlugin::Autoload($Classname); }); jf::import("jf/model/namespace/public/test"); jf::import("jf/model/test/listener"); }
<?php jf::import("jf/test/lib/rbac/base"); class LibRbacRolesTest extends LibRbacBaseTest { /** * * @return \jf\RoleManager */ protected function Instance() { return jf::$RBAC->Roles; } protected function Type() { return "role"; } function testAssignPermission() { $ID1 = jf::$RBAC->Roles->Add("role1", "description of role1"); $ID2 = jf::$RBAC->Roles->Add("role2", "description of role2"); $ID11 = jf::$RBAC->Roles->Add("role1-1", "description of role", $ID1); $ID12 = jf::$RBAC->Roles->Add("role1-2", "description of role", $ID1); $ID121 = jf::$RBAC->Roles->Add("role1-2-1", "description of role", $ID12); $PID1 = jf::$RBAC->Permissions->Add("permission1", "description"); $PID2 = jf::$RBAC->Permissions->Add("permission2", "description"); $PID21 = jf::$RBAC->Permissions->Add("permission2-1", "description", $PID2); jf::$RBAC->Roles->Assign($ID121, $PID2); $this->assertTrue(jf::$RBAC->Roles->HasPermission($ID121, $PID2)); $this->assertTrue(jf::$RBAC->Roles->HasPermission($ID1, $PID21)); $this->assertTrue(jf::$RBAC->Roles->HasPermission($ID12, $PID2));
//disable it if embedded or CLI because another system is handling it. } else { jf\ErrorHandler::$Enabled = true; //Enables jframework's built-in error handler } jf::$ErrorHandler->SetErrorHandler(); if (jf::$RunMode->IsDevelop()) { jf\ErrorHandler::$PresentErrors = true; } else { jf\ErrorHandler::$PresentErrors = false; } /** * Bandwidth Management * * jframework handles all file feeds and downloads manually. * Its FileManager has the ability to limit download speed of files larger than a specific size. * Set both the initial size and the limit here. */ jf\DownloadManager::$BandwidthLimitInitialSize = -1; # negative number disables it jf\DownloadManager::$BandwidthLimitSpeed = 1024 * 1024; /** * Iterative Templates * * If this is set, jframework viewer would look into the view folder and all its ancestor folders * to find a template folder, and would display the first template it finds. * Otherwise only the same folder is checked for templates. */ jf\View::$IterativeTemplates = true; jf::import("config/more");
function __construct() { jf::import("jf/plugin/phpxml"); }
<?php jf::import("jf/test/lib/db/adapter/pdo_mysql"); class LibDbMariadbTest extends LibDbPdoMysqlTest { private static $Default; public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$Default = \jf\DatabaseManager::$DefaultIndex; $setting = \jf\DatabaseManager::Configuration(); $config = new \jf\DatabaseSetting("mariaDB", $setting->DatabaseName, $setting->Username, $setting->Password, $setting->Host, $setting->TablePrefix); \jf\DatabaseManager::AddConnection($config, 2); \jf\DatabaseManager::$DefaultIndex = \jf\DatabaseManager::FindIndex($config); } } class LibDbStatementMariadbTest extends LibDbStatementPdoMysqlTest { private static $Default; public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$Default = \jf\DatabaseManager::$DefaultIndex; $setting = \jf\DatabaseManager::Configuration(); $config = new \jf\DatabaseSetting("mariaDB", $setting->DatabaseName, $setting->Username, $setting->Password, $setting->Host, $setting->TablePrefix); \jf\DatabaseManager::AddConnection($config, 2); \jf\DatabaseManager::$DefaultIndex = \jf\DatabaseManager::FindIndex($config); } }
/** * load application specific configurations */ protected function LoadApplicationConfiguration() { //Application specific config jf::import("config/application"); }