本文整理汇总了PHP中Router::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getInstance方法的具体用法?PHP Router::getInstance怎么用?PHP Router::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
private function init()
{
$this->session = Session::getInstance();
$this->request = Request::getInstance();
$this->router = Router::getInstance();
$this->view = View::getInstance();
}
示例2: __construct
/**
* Construct
*/
public function __construct()
{
parent::__construct();
$this->JSRMS = new JSRMS();
$this->JSRMS->requireResource('system');
$this->muteExpectedErrors();
$this->setCacheDir(SYSTEM_ROOT . '/classes/smarty/cache/');
$this->setCompileDir(SYSTEM_ROOT . '/classes/smarty/templates_c/');
$this->setTemplateDir(SYSTEM_ROOT . '/view/');
$this->registerObject('Router', Router::getInstance(), array('build'), false);
$this->registerObject('L10N', System::getLanguage(), array('_'), false);
$this->assign('LoggedIn', System::getUser() != NULL);
$this->assign('User', System::getUser());
$this->assign('Navigation', Navigation::$elements);
$this->assign('LangStrings', System::getLanguage()->getAllStrings());
// Configuration
$this->assign('HTTP_BASEDIR', System::getBaseURL());
$this->assign('MOD_REWRITE', MOD_REWRITE);
$this->assign('MAX_UPLOAD_SIZE', Utils::maxUploadSize());
if (System::getSession()->getData('successMsg', '') != '') {
$this->assign('successMsg', System::getSession()->getData('successMsg', ''));
System::getSession()->setData('successMsg', '');
}
if (System::getSession()->getData('errorMsg', '') != '') {
$this->assign('errorMsg', System::getSession()->getData('errorMsg', ''));
System::getSession()->setData('errorMsg', '');
}
if (System::getSession()->getData('infoMsg', '') != '') {
$this->assign('infoMsg', System::getSession()->getData('infoMsg', ''));
System::getSession()->setData('infoMsg', '');
}
}
示例3: start
/**
* Start the application
*/
public function start()
{
//match the current route
$route = Router::getInstance()->matchRoute();
if ($route) {
//rewrite the GET
$_GET = array('Module' => $route['route']['Module'], 'Controller' => $route['route']['Controller'], 'Action' => $route['route']['Action']);
if (!empty($route['params'])) {
$_GET = array_merge($_GET, $route['params']);
}
switch ($this->renderAction($route)) {
default:
case View::HTML:
//check if layout is not disabled
if (!Layout::getInstance()->isDisabled($route['route']['Module'], $route['route']['Controller'], $route['route']['Action'])) {
Layout::getInstance()->loadLayout($route);
} else {
//if disabled just show html
echo self::$action;
}
break;
case View::JSON:
//serve the json value
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 08 Jul 1985 19:15:00 GMT');
header('Content-type: application/json');
exit(self::$action);
break;
}
}
}
示例4: parse
function parse($url)
{
// Get an instance of the Router
$router =& Router::getInstance();
// Get an array of all defined prefixes
$prefixes = $router->prefixes();
// Only proceed if prefixes have been defined...
if (is_array($prefixes) && count($prefixes, COUNT_RECURSIVE) > 0) {
// Get the sub-domain from the current URL, and convert to lower-case
$url_parts = explode('.', env('HTTP_HOST'));
$subdomain = strtolower(trim($url_parts[0]));
// Assuming all routing prefixes are lower-case, check for a match between a prefix and the current URL sub-domain
if (in_array($subdomain, $prefixes)) {
// Iterate each defined route...
foreach ($router->routes as $route) {
// Check to make sure we are not trying to modify our own route definition...
if (!$route instanceof SubDomainPrefixRoute) {
// Check, just in case...
if (isset($route->defaults)) {
// If a prefix has not been defined for this particular route, then we can add a prefix using the current URL sub-domain...
if (!isset($route->defaults['prefix'])) {
$route->defaults['prefix'] = $subdomain;
$route->defaults[$subdomain] = true;
}
}
}
}
}
}
return false;
// We do not want this route to be matched, so we return false in order that Cake can continue checking routes for a match
}
示例5: createRequest
/**
* Create new request and sends email to user
* @static
* @param string Mail adress
* @throws MailFailureException, UserNotFoundException
*/
public static function createRequest($mail)
{
LostPW::cleanUp();
$user = User::find('email', $mail);
if ($user == NULL) {
throw new UserNotFoundException();
}
// Delete old requests
$sql = System::getDatabase()->prepare('DELETE FROM lostpw WHERE user_ID = :uid');
$sql->execute(array(':uid' => $user->uid));
// Create new request
$hash = LostPW::createHash();
$sql = System::getDatabase()->prepare('INSERT INTO lostpw (user_ID, hash, time) VALUES (:uid, :hash, :time)');
$sql->execute(array(':uid' => $user->uid, ':hash' => $hash, ':time' => time()));
// Send Mail
$content = new Template();
$content->assign('link', Router::getInstance()->build('AuthController', 'lostpw_check', array('hash' => $hash)));
$content->assign('user', $user);
$content->assign('title', System::getLanguage()->_('LostPW'));
// Determine template file
$tpl = 'mails/lostpw.' . LANGUAGE . '.tpl';
foreach ($content->getTemplateDir() as $dir) {
$file = 'mails/lostpw.' . $user->lang . '.tpl';
if (file_exists($dir . $file)) {
$tpl = $file;
break;
}
}
$mail = new Mail(System::getLanguage()->_('LostPW'), $content->fetch($tpl), $user);
$mail->send();
}
示例6: loadFile
private function loadFile()
{
if ($this->file != NULL) {
return;
}
$this->file = File::find('alias', $this->getParam('alias', ''));
if ($this->file == NULL) {
System::displayError(System::getLanguage()->_('ErrorFileNotFound'), '404 Not Found');
}
if (System::getUser() != NULL) {
$user_id = System::getUser()->uid;
} else {
$user_id = -1;
}
if ($user_id != $this->file->uid) {
if ($this->file->permission == FilePermissions::PRIVATE_ACCESS) {
System::displayError(System::getLanguage()->_('PermissionDenied'), '403 Forbidden');
exit;
} elseif ($this->file->permission == FilePermissions::RESTRICTED_ACCESS) {
if (is_array(System::getSession()->getData("authenticatedFiles"))) {
if (!in_array($this->file->alias, System::getSession()->getData("authenticatedFiles"))) {
System::forwardToRoute(Router::getInstance()->build('AuthController', 'authenticateFile', $this->file));
exit;
}
} else {
System::forwardToRoute(Router::getInstance()->build('AuthController', 'authenticateFile', $this->file));
exit;
}
}
}
}
示例7: __construct
public function __construct()
{
$fc = Router::getInstance();
$this->params = $fc->getParams();
$this->format = $fc->getFormat();
$this->makeObj();
}
示例8: testNegotiatesPlaceholders
public function testNegotiatesPlaceholders()
{
$router = Router::getInstance(true);
$router->register('abc/:id', 'test');
$result = $router->negotiate('abc/1');
$this->assertEquals($result, array('actions' => array('test'), 'args' => array('id' => 1)));
}
示例9: setup
/**
* Setups basic components
* @return boolean
*/
function setup()
{
$this->ini = ParserINI::getConfig('site');
$this->router = Router::getInstance();
$this->sAction = $this->router->getData();
$this->user = User::loadFromSession();
return true;
}
示例10: index
public function index()
{
$user = System::getUser();
$form = new Form('form-profile');
$form->setAttribute('data-noajax', 'true');
$form->binding = $user;
$fieldset = new Fieldset(System::getLanguage()->_('General'));
$firstname = new Text('firstname', System::getLanguage()->_('Firstname'));
$firstname->binding = new Databinding('firstname');
$lastname = new Text('lastname', System::getLanguage()->_('Lastname'));
$lastname->binding = new Databinding('lastname');
$email = new Text('email', System::getLanguage()->_('EMail'), true);
$email->binding = new Databinding('email');
$email->blacklist = $this->getListOfMailAdresses($user);
$email->error_msg[4] = System::getLanguage()->_('ErrorMailAdressAlreadyExists');
$language = new Radiobox('lang', System::getLanguage()->_('Language'), L10N::getLanguages());
$language->binding = new Databinding('lang');
$fieldset->addElements($firstname, $lastname, $email, $language);
$form->addElements($fieldset);
$fieldset = new Fieldset(System::getLanguage()->_('Password'));
$password = new Password('password', System::getLanguage()->_('Password'));
$password->minlength = PASSWORD_MIN_LENGTH;
$password->binding = new Databinding('password');
$password2 = new Password('password2', System::getLanguage()->_('ReenterPassword'));
$fieldset->addElements($password, $password2);
$form->addElements($fieldset);
$fieldset = new Fieldset(System::getLanguage()->_('Settings'));
$quota = new Text('quota', System::getLanguage()->_('Quota'));
if ($user->quota > 0) {
$quota->value = System::getLanguage()->_('QuotaAvailabe', Utils::formatBytes($user->getFreeSpace()), Utils::formatBytes($user->quota));
} else {
$quota->value = System::getLanguage()->_('Unlimited');
}
$quota->readonly = true;
$fieldset->addElements($quota);
$form->addElements($fieldset);
if (Utils::getPOST('submit', false) !== false) {
if (!empty($password->value) && $password->value != $password2->value) {
$password2->error = System::getLanguage()->_('ErrorInvalidPasswords');
} else {
if ($form->validate()) {
$form->save();
System::getUser()->save();
System::getSession()->setData('successMsg', System::getLanguage()->_('ProfileUpdated'));
System::forwardToRoute(Router::getInstance()->build('ProfileController', 'index'));
exit;
}
}
} else {
$form->fill();
}
$form->setSubmit(new Button(System::getLanguage()->_('Save'), 'floppy-disk'));
$smarty = new Template();
$smarty->assign('title', System::getLanguage()->_('MyProfile'));
$smarty->assign('heading', System::getLanguage()->_('MyProfile'));
$smarty->assign('form', $form->__toString());
$smarty->display('form.tpl');
}
示例11: run
public function run()
{
$this->init();
if (!Router::getInstance()->route($_SERVER['REQUEST_METHOD'], Uri::detectPath())) {
// No valid route found
http_response_code(404);
echo '<h1>Page not found.</h1>';
}
}
示例12: Load
public function Load()
{
$module = Router::getInstance()->getModule();
$file = $this->ent['CONF_FILE'] = $this->ent['CONF_FILE'] ?: 'Conf.php';
$filep = $this->ent['APP_PATH'] . 'Modules/' . $this->app['modulelist'][$module] . '/' . $file;
$this->moduleConfig = G($filep);
//configmix
$this->mixConfig($module);
return true;
}
示例13: checkAuthentification
/**
* Checks if user is authentificated
* if not - user is redirected to login page
*/
public final function checkAuthentification()
{
if (System::getUser() == NULL) {
if (System::$isXHR) {
System::displayError(System::getLanguage()->_('PermissionDenied'), '403 Forbidden');
} else {
System::forwardToRoute(Router::getInstance()->build('AuthController', 'login'));
exit;
}
}
}
示例14: get
public static function get($name = null, $default = null)
{
if (!static::$params) {
static::$params = Router::getInstance()->request()->params();
}
if ($name) {
return isset(static::$params[$name]) ? static::$params[$name] : $default;
} else {
return static::$params;
}
}
示例15: getInstance
/**
* Singleton
* @return app
*/
public static function getInstance()
{
if (self::$self != NULL) {
return self::$self;
}
self::$self = new self();
/// Получение параметров конфигурации из файла
self::$config = (include __NGN__ . '/config.inc');
/// Подключение простого модуля кэширования с помощью APC
# include(__SYSTEM__.'/aeon.cache.php');
# self::$cache = new SimpleCache();
/// Если есть APC храним в нём список helper'ов
/*
if(__APC__){
if(apc_exists('helpers-list')) $ext = json_decode(apc_fetch('helpers-list'), true);
else {
$ext = glob(__HELPERS__.'/*.php');
apc_add('helpers-list', json_encode($ext), 2);
}
} else {
$ext = glob(__HELPERS__.'/*.php');
};
*/
/// Модуль авторизации
# self::$extensions['auth'] = \Auth::getInstance();
/*
/// Подключаем Helper'ы
foreach($ext as $v) {
include($v);
$ext_name = substr(basename($v), 0, -4);
$ext_class_name = '\Helper\\'.$ext_name;
self::$extensions[$ext_name] = $ext_class_name::getInstance(self::$self);
};
unset($ext);
*/
include __SYSTEM__ . '/aeon.local.php';
\Eva\Local::getInstance(self::$self);
/// Сайт работает с БД?
if (self::getParam('db:enabled')) {
try {
/// Пытаемся подключится
self::$db = new PDO('mysql:host=' . self::getParam('db:server') . '; dbname=' . self::getParam('db:name'), self::getParam('db:user'), self::getParam('db:password'), array(PDO::ATTR_PERSISTENT => true));
self::$db->query('SET character_set_client="utf8", character_set_results="utf8", collation_connection="cp1251_general_ci"');
} catch (Exception $e) {
/// Падаем и ложим весь сайт
error_log('PDO is not supported on this OS! Please, contact your administrator!', 0);
msg503();
}
}
/// Роутер
self::$router = \Router::getInstance();
/// Возвращаем экземпляр класса движка
return self::$self;
}