本文整理汇总了PHP中Route::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getInstance方法的具体用法?PHP Route::getInstance怎么用?PHP Route::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::getInstance方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Main dispatcher
*
* @return string Return the compiled view content
*/
public function dispatch()
{
ob_start();
// Module and action are not defined by setters
if (!$this->_explicit) {
// Get uri from routes
$uri = Route::getInstance()->parseUrl();
// No uri found, try to load asset
if (!$uri->isDefined() && Config::get('route.routed_only') == '1' && $uri->getUri(false) != '/') {
$this->_loadAsset();
Error::show404();
}
// Get module and action from route
$this->_parseFromRequest($uri);
}
// Convert module/action to className
$this->_getActionClassName();
// Add to chaining for logs
$this->_addToChain();
// Initialize result
$mv = '';
// If action is authorized ...
if ($this->_isAuthorized()) {
//... process execute()
$mv = $this->_processAction();
} else {
//... else process handleError()
$mv = $this->_handleError();
}
// Action method result is an object, render view
if (is_object($mv)) {
$mv = $this->_processView($mv);
}
// Display to browser
echo $mv;
// Remove action from chain for logs
$this->_removeFromChain();
// No more actions in chain, render to browser
if (empty($this->_chain['classNames'])) {
ob_end_flush();
}
}
示例2: ErrorHandler
<?php
namespace ThemeCheck;
require_once 'include/Bootstrap.php';
function ErrorHandler($errLevel, $errMsg, $errFile, $errLine)
{
if ($errLevel & E_USER_ERROR) {
$response["error"] = $errMsg;
ob_clean();
header('Content-Type: application/json');
echo json_encode($response);
die;
}
}
set_error_handler(__NAMESPACE__ . "\\ErrorHandler");
// Multilingual url un-rewriting
$routeParts = Route::getInstance()->match();
if (empty($_GET["controller"]) || empty($_GET["action"])) {
die;
}
$controller = $_GET["controller"];
$action = $_GET["action"];
if ($controller == "home" && $action == "seemore" || $controller == "home" && $action == "sort" || $controller == "massimport" && ($action == "importnext" || $action == "updatenext") || $controller == "unittests" && $action == "sample") {
include TC_ROOTDIR . '/controllers/controller_' . $controller . '.php';
$classname = '\\ThemeCheck\\Controller_' . $controller;
$controller = new $classname();
$action = "ajax_" . $action;
$controller->{$action}();
}
示例3: ajax_sample
public function ajax_sample()
{
$time_start = microtime(true);
$response["error"] = "none";
$response["html"] = "";
$themeid = 1;
if (isset($_POST["themeid"])) {
$themeid = intval($_POST["themeid"]);
}
if ($themeid < 1) {
$themeid = 1;
}
$checkid = $_POST["checkid"];
if (USE_DB) {
$history = new History();
$themInfo = $history->getFewInfo($themeid);
$hash = $themInfo["hash"];
$fileValidator = FileValidator::unserialize($hash);
$fileValidator->validate($checkid);
//if (UserMessage::getCount(ERRORLEVEL_FATAL) == 0) // serialize only if no fatal errors
$validationResults = $fileValidator->getValidationResults(I18N::getCurLang());
if (count($validationResults->check_critical) > 0 || count($validationResults->check_warnings) > 0 || count($validationResults->check_info) > 0) {
$url = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => "en", "phpfile" => "results", "hash" => $hash));
$html = '<h2 style="color:#D00;">' . $themInfo["name"] . '<a href="' . $url . '" target="_blank" style="font-size:14px;margin-left:6px"><span class="glyphicon glyphicon-new-window"></span></a>' . '</h2>';
}
if (count($validationResults->check_critical) > 0) {
//$html .= '<h2 style="line-height:100px;color:#D00;">'.__("Critical alerts").'</h2>';
$html .= '<ol>';
foreach ($validationResults->check_critical as $check) {
$html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>';
if (!empty($check->messages)) {
$html .= '<p style="color:#c94b4b;">' . implode('<br/>', $check->messages) . '</p>';
}
}
$html .= '</ol>';
}
if (count($validationResults->check_warnings) > 0) {
//$html .= '<h2 style="line-height:100px;color:#eea43a;">'.__("Warnings").'</h2>';
$html .= '<ol>';
foreach ($validationResults->check_warnings as $check) {
$html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>';
if (!empty($check->messages)) {
$html .= '<p style="color:#eea43a;">' . implode('<br/>', $check->messages) . '</p>';
}
}
$html .= '</ol>';
}
if (count($validationResults->check_info) > 0) {
//$html .= '<h2 style="line-height:100px;color:#eea43a;">'.__("Warnings").'</h2>';
$html .= '<ol>';
foreach ($validationResults->check_info as $check) {
$html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>';
if (!empty($check->messages)) {
$html .= '<p style="color:#00b6e3;">' . implode('<br/>', $check->messages) . '</p>';
}
}
$html .= '</ol>';
}
$response["html"] = $html;
$prevId = $history->getPrevId($themeid);
if (!empty($prevId)) {
$themInfoNext = $history->getFewInfo($prevId);
$response["next_id"] = $prevId;
$response["next_name"] = $themInfoNext["name"];
} else {
$response["next_id"] = null;
$response["next_name"] = null;
}
}
$time_end = microtime(true);
$time = $time_end - $time_start;
$response["duration"] = $time;
//ob_clean();
header('Content-Type: application/json');
echo json_encode($response);
}
示例4: __
echo $script . "\n";
echo '</script>' . "\n";
}
}
?>
<div class="navbar navbar-inverse">
<!--<div class="navbar navbar-inverse">-->
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="<?php
echo TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "index.php"));
?>
"><img src="<?php
echo TC_HTTPDOMAIN;
?>
/img/headerlogo.png"></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="<?php
echo TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "contact"));
?>
"><?php
echo __("Contact us");
?>
</a></li>
</ul>
</div>
</div>
</div>
<?php
示例5: render
public function render()
{
if (isset($_POST['send'])) {
$errors = array();
if (isset($_SESSION['token_' . $_POST['token']])) {
unset($_SESSION['token_' . $_POST['token']]);
if (empty($_POST['name'])) {
$errors['name'] = __("Required field");
}
if (empty($_POST['email'])) {
$errors['email'] = __("Required field");
} elseif (false === filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors['email'] = __("invalid email address");
}
if (empty($_POST['message'])) {
$errors['message'] = __("Required field");
}
// Send email
if (count($errors) == 0) {
require_once TC_INCDIR . '/Swift-4.3.0/lib/swift_required.php';
$message = \Swift_Message::newInstance();
$message->setSubject('CONTACT THEMECHECK');
$message->setFrom(array('mailer@themecheck.org' => 'Themecheck.org'));
$text = "Contact from : " . htmlspecialchars($_POST['name']) . " : " . htmlspecialchars($_POST['email']) . "<br>";
if (!empty($_POST['website'])) {
$text .= "Website: " . htmlspecialchars($_POST['website']) . "<br>";
}
$text .= "<br>Message:<br>";
$text .= nl2br(htmlspecialchars($_POST['message']));
$message->setBody($text, 'text/html');
$to = array();
$to[TC_CONTACT_MAIL] = TC_CONTACT_NAME;
$message->setTo($to);
if (TC_ENVIRONMENT == 'dev') {
// for unconfigured php.ini smtp use (xampp/wamp etc...):
$transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('username')->setPassword('password');
} else {
$transport = \Swift_SmtpTransport::newInstance();
}
$mailer = \Swift_Mailer::newInstance($transport);
$test = $mailer->send($message);
echo '<div class="container"><div class="alert alert-success">' . __("Message sent. We'll contact you soon.") . '</div><a href="' . TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "index.php")) . '">' . __("Back to home page") . '</a></div>';
}
} else {
$errors['token'] = __("Invalid form");
}
}
if (!isset($_POST['send']) || count($errors) > 0) {
$token = uniqid(true);
$_SESSION['token_' . $token] = time();
?>
<div class="container">
<h1><?php
echo __("Contact us");
?>
</h1>
<br/><br/>
<div id="contact-form">
<form method="post" action="">
<div class="row">
<div class="form-group <?php
if (isset($errors['name'])) {
?>
has-error<?php
}
?>
col-md-4 col-sm-6">
<label class="label-text control-label" for="name"><?php
echo __("Name (required)");
?>
</label>
<input type="text" class="name form-control" value="" id="name" name="name">
<?php
if (isset($errors['name'])) {
?>
<span class='control-label'><?php
echo $errors['name'];
?>
</span><?php
}
?>
</div>
</div>
<div class="row">
<div class="form-group <?php
if (isset($errors['email'])) {
?>
has-error<?php
}
?>
col-md-4 col-sm-6">
<label class="label-email control-label" for="email"><?php
echo __("Email (required)");
?>
</label>
<input type="text" class="email font-primary form-control" value="" id="email" name="email">
<?php
if (isset($errors['email'])) {
?>
<span class='control-label'><?php
//.........这里部分代码省略.........
示例6: header
<?php
header('Content-type:text/html; charset=UTF-8');
require '../lib/Route.class.php';
$rulelist = array('rule_startpage' => array('rule' => '/', 'action' => 'homepage.php'), 'rule_homepage' => array('rule' => '/home', 'action' => 'homepage.php'), 'rule_produto' => array('rule' => '/produto/{titulo_slug}_{id}.{_format}', 'action' => 'produto.php', 'params' => array('id' => array('pattern' => '\\d+'), 'titulo_slug' => array('pattern' => '[a-z0-9-_]+'), '_format' => array('pattern' => 'html|pdf|txt'))));
$my_protocol = 'http';
$my_domain = 'localhost';
$my_basedir = '/jonas-php-library/demo/';
$my_url_prefix = $my_protocol . '://' . $my_domain . $my_basedir;
try {
$myRoute = Route::getInstance();
$myRoute->setConfig($rulelist, $my_domain, $my_basedir, $my_protocol)->init($_SERVER['REQUEST_URI'])->check();
include $myRoute->getMatchedRouteAction();
} catch (RouteNotFoundException $e) {
include 'route-not-found.php';
}
示例7: define
*********************************************/
//Variables globales d'accès au fichiers
define('ROOT', str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']));
define('WEBROOT', str_replace('index.php', '', $_SERVER['SCRIPT_NAME']));
define('MODEL', "model/");
define('VIEW', "view/");
define('CONTROLLER', "controller/");
define('CSS', WEBROOT . "src/css/");
define('JS', WEBROOT . "src/js/");
define('IMG', WEBROOT . "src/img/");
//Instanciation de la session
session_start();
//Inclusion de l'autoloader
require_once 'autoloader.php';
//On instancie le routeur
$r = Route::getInstance();
//Si l'utilisateur vient de se connecter ou de se déconnecter on rafraichi l'état de connexion
$r->refreshConnection();
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<meta author='Cédric Eloundou & Guillaume Fauvet'>
<link rel="icon" href=<?php
echo "'" . IMG . "site.ico'";
?>
/>
示例8: displayShield
ga('send', 'pageview', loc, '<?php
if ($themeInfo->themetype == 1) {
echo '[WP] ';
}
if ($themeInfo->themetype == 2) {
echo '[Joomla] ';
}
if ($themeInfo->themetype == 4) {
echo '[WP child] ';
}
echo $themeInfo->namesanitized;
?>
');
</script>
<?php
$href = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => $lang, "phpfile" => "results", "hash" => $hash));
displayShield($themeInfo, $lang, $size, $href, '');
} else {
?>
<script>
ga('send', 'pageview');
</script><?php
echo __("Error : non existant id.", $lang);
}
} else {
?>
<script>
ga('send', 'pageview');
</script><?php
echo __("Error : invalid id.", $lang);
}
示例9: render
public function render()
{
$max_size = Helpers::returnBytes(ini_get('upload_max_filesize'));
if ($max_size > Helpers::returnBytes(ini_get('post_max_size'))) {
$max_size = Helpers::returnBytes(ini_get('post_max_size'));
}
$max_size_MB = $max_size / (1024 * 1024);
$token = uniqid(true);
$_SESSION['token_' . $token] = time();
?>
<div class="jumbotron">
<div class="container">
<h1><?php
echo __("Verify web themes and templates");
?>
</h1>
<p><?php
echo __("Themecheck.org is a quick service that lets you verify web themes or templates for security and code quality. This service is free and compatible with Wordpress themes and Joomla templates.");
?>
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"><?php
echo __("More...");
?>
</a>
</p>
<div class="row">
<div id="collapseOne" class="panel-collapse collapse">
<div class="panel-body">
<div class="col-lg-6">
<h2><?php
echo __("Website owners");
?>
</h2>
<p><?php
echo __("Check themes or templates you download before installing them on your site");
?>
</p>
<ul>
<li><?php
echo __("Check code quality");
?>
</li>
<li><?php
echo __("Check presence of malware");
?>
</li>
</ul>
</div>
<div class="col-lg-6">
<h2><?php
echo __("Developers");
?>
</h2>
<p><?php
echo __("Your create or distribute themes ?");
?>
</p>
<ul>
<li><?php
echo __("Themecheck.org helps you verify they satisfy CMS standards and common users needs.");
?>
</li>
<li><?php
echo __("Share verification score on your site with ThemeCheck.org widget ");
?>
<img src="<?php
echo TC_HTTPDOMAIN;
?>
/img/pictosuccess40.png"></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container text-center">
<h2 ><?php
echo __("Upload a zip file and get its verification score :");
?>
</h2><br/>
<form role="form" class="text-center" action="<?php
echo TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "results"));
?>
" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php
echo Helpers::returnBytes(ini_get('upload_max_filesize'));
?>
" />
<input type="file" name="file" id="file" class="filestyle" data-buttonText="<?php
echo __("Select file");
?>
" data-classButton="btn btn-default btn-lg" data-classInput="input input-lg">
</div>
<?php
echo __("Maximum file size") . " : {$max_size_MB} MB";
//.........这里部分代码省略.........
示例10: __
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1><?php
echo __("Error 404.");
?>
</h1>
<p><?php
echo __("Sorry, the page you requested doesn't exist.");
?>
</p>
</div>
</div>
<?php
$samepage_i18n = array('en' => TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => "en", "phpfile" => "error404.php")), 'fr' => TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => "fr", "phpfile" => "error404.php")));
require "footer.php";
?>
<!-- /container --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="<?php
echo TC_HTTPDOMAIN;
?>
/js/vendor/jquery-1.10.1.min.js"><\/script>')</script>
<script src="<?php
echo TC_HTTPDOMAIN;
?>
/js/vendor/bootstrap.min.js"></script>
<script src="<?php
echo TC_HTTPDOMAIN;
?>
示例11: renderRulesSet
private function renderRulesSet($themeInfo, $validationResults)
{
?>
<div class="row" style="color:#888;font-weight:normal;margin:30px 0 0 0;background:#F8F8F8;border-radius: 3px;">
<div class="col-md-8 text-center" style="">
<br/>
<?php
$userMessage = UserMessage::getInstance();
echo UserMessage::getInstance()->getMessagesHtml();
$img = 'shieldperfect240.png';
$color = 'a6af11';
$text = sprintf(__('Validation score : %s%%'), intval($themeInfo->score));
if ($themeInfo->score < 100.0) {
if ($themeInfo->score > 95) {
$img = "shieldgreen240.png";
$color = 'cbd715';
} else {
if ($themeInfo->score > 80) {
$img = "shieldorange240.png";
$color = 'ff8214';
} else {
$img = "shieldred240.png";
$color = 'ff1427';
}
}
if ($themeInfo->criticalCount > 0) {
$text = sprintf(__('Validation score : %s%% (%s critical alerts)'), intval($themeInfo->score), $themeInfo->criticalCount);
} else {
$text = sprintf(__('Validation score : %s%%'), intval($themeInfo->score));
}
}
?>
<div class="shield1" style="width:201px;height:240px;background-image:url(<?php
echo TC_HTTPDOMAIN;
?>
/img/<?php
echo $img;
?>
);" title="<?php
echo $text;
?>
">
<div class="shield2" style="color:#<?php
echo $color;
?>
;">
<?php
if ($themeInfo->score < 100.0) {
echo intval($themeInfo->score);
}
?>
</div>
</div>
<?php
echo '<p "color:#' . $color . '">' . __("validation score") . ' : ' . intval($themeInfo->score) . ' %</p>';
echo '<p>' . sprintf(__("%s critical alerts. %s warnings."), $themeInfo->criticalCount, $themeInfo->warningsCount) . '</p>';
if (!isset($_POST["donotstore"]) && UserMessage::getCount(ERRORLEVEL_FATAL) == 0) {
?>
<br/><br/>
<?php
echo __("Share this page with the following link :");
?>
<p>
<?php
echo '<a href="' . $this->samepage_i18n[I18N::getCurLang()] . '">' . $this->samepage_i18n[I18N::getCurLang()] . '</a>';
?>
</p>
<?php
echo __("Display this score on your website with the following HTML code that links to this page :");
?>
<p style="color:red"><i>( corrected 2014-06-09 )</i></p>
<pre style="font-size:11px;width:70%;margin:auto;"><?php
echo htmlspecialchars('<iframe src="' . TC_HTTPDOMAIN . '/score.php?lang=' . I18N::getCurLang() . '&id=' . $themeInfo->hash . '&size=big" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:240px; width:200px;" allowTransparency="true"></iframe>');
?>
</pre>
<button class="btn" data-toggle="collapse" data-target="#moreembedoptions" style="height:20px;padding:1px;font-size:12px">more options</button>
<div id="moreembedoptions" class="collapse">
<?php
displayShield($themeInfo, I18N::getCurLang(), 80, '#', TC_HTTPDOMAIN . '/');
?>
<?php
echo __("Medium size icon (default) :");
?>
<pre style="font-size:11px;width:70%;margin:auto;"><?php
echo htmlspecialchars('<iframe src="' . TC_HTTPDOMAIN . '/score.php?id=' . $themeInfo->hash . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px; width:67px;" allowTransparency="true"></iframe>');
?>
</pre>
<?php
displayShield($themeInfo, I18N::getCurLang(), 40, '#', TC_HTTPDOMAIN . '/');
?>
<?php
echo __("Small size icon :");
?>
<pre style="font-size:11px;width:70%;margin:auto;"><?php
echo htmlspecialchars('<iframe src="' . TC_HTTPDOMAIN . '/score.php?id=' . $themeInfo->hash . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px; width:40px;" allowTransparency="true"></iframe>');
?>
</pre>
<?php
echo htmlspecialchars(__("You can switch language with <strong>lang</strong> parameter in iframe's url. So far <strong>fr</strong> and <strong>en</strong> are supported. Default value is <strong>en</strong>."));
//.........这里部分代码省略.........