本文整理汇总了PHP中dispatch_get函数的典型用法代码示例。如果您正苦于以下问题:PHP dispatch_get函数的具体用法?PHP dispatch_get怎么用?PHP dispatch_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dispatch_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
<?php
require_once 'autoload.php';
//load app classes
require_once 'lib/limonade.php';
dispatch('/css/:css', 'AssetController::css');
dispatch('/js/:js', 'AssetController::js');
//ROUTES
dispatch_get('/', 'PostController::index');
dispatch_get('/new', 'PostController::neew');
//R
dispatch_get('/edit/:post', 'PostController::edit');
//R
dispatch_post('/:post', 'PostController::save');
//C, U
dispatch_get('/:post', 'PostController::post');
dispatch_post('/remove/:post', 'PostController::remove');
//D
run();
示例2: get
/**
* Define a GET route for AJAX GET with token validation
* @param string $route
* @param \Closure $closure
*/
public static function get($route, \Closure $closure, $getNewStuff = true)
{
if (!\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
$getNewStuff = false;
//not available for guests
}
dispatch_get($route, function () use($closure, $getNewStuff) {
Request::processReq($closure, $getNewStuff, func_get_args());
});
}
示例3: dispatch_get
dispatch_get('uni_login/login/:name', function ($name) {
// config and includes
$config = SYSPATH . 'Ext/hybridauth/config.php';
require_once SYSPATH . "Ext/hybridauth/Hybrid/Auth.php";
try {
// hybridauth EP
$hybridauth = new Hybrid_Auth($config);
// automatically try to login with Twitter
$adapter = $hybridauth->authenticate($name);
// get the user profile
$user_profile = $adapter->getUserProfile();
// var_dump($user_profile);
//oauth identifier
$oauth_id = md5($name . $user_profile->identifier);
$db = \DB::getPDO();
$qry = 'SELECT id, username, avatar FROM ' . PREFIX . 'codo_users WHERE oauth_id=:oauth_id';
$stmt = $db->prepare($qry);
$stmt->execute(array(":oauth_id" => $oauth_id));
$username = CODOF\Filter::clean_username($user_profile->displayName);
$profile = $stmt->fetch();
if (!empty($profile)) {
if ($username != $profile['username'] || $user_profile->photoURL != $profile['avatar']) {
//profile has been updated remotely
$qry = 'UPDATE ' . PREFIX . 'codo_users SET username=:name,avatar=:avatar WHERE oauth_id=:id';
$stmt = $db->prepare($qry);
$stmt->execute(array(":name" => $username, ":avatar" => $user_profile->photoURL, ":id" => $oauth_id));
}
CODOF\User\User::login($profile['id']);
} else {
//no local copy of this profile yet
$mail = $user_profile->email;
$create_account = true;
if ($mail == null) {
$mail = '';
} else {
//we got an email, lets check if it exists
$qry = "SELECT id FROM " . PREFIX . "codo_users WHERE mail=:mail";
$stmt = $this->db->prepare($qry);
$stmt->execute(array(":mail" => $mail));
$res = $stmt->fetch();
if (!empty($res)) {
//looks like this user has already registered
$create_account = false;
CODOF\User\User::login($res['id']);
//now this will work if you change authentication from
//fb to gmail etc
}
}
if ($create_account) {
$reg = new CODOF\User\Register($db);
$reg->mail = $mail;
$reg->name = $user_profile->firstName . ' ' . $user_profile->lastName;
$reg->oauth_id = $oauth_id;
$reg->username = $username;
$reg->avatar = $user_profile->photoURL;
$reg->user_status = 1;
//approved user
$reg->register_user();
$reg->login();
}
}
header('Location: ' . CODOF\User\User::getProfileUrl());
//$adapter->logout();
} catch (Exception $e) {
// In case we have errors 6 or 7, then we have to use Hybrid_Provider_Adapter::logout() to
// let hybridauth forget all about the user so we can try to authenticate again.
// Display the recived error,
// to know more please refer to Exceptions handling section on the userguide
switch ($e->getCode()) {
case 0:
echo "Unspecified error.";
break;
case 1:
echo "Hybridauth configuration error.";
break;
case 2:
echo "Provider not properly configured.";
break;
case 3:
echo "Unknown or disabled provider.";
break;
case 4:
echo "Missing provider application credentials.";
break;
case 5:
echo "Authentication failed. " . "The user has canceled the authentication or the provider refused the connection.";
break;
case 6:
echo "User profile request failed. Most likely the user is not connected " . "to the provider and he should to authenticate again.";
$adapter->logout();
break;
case 7:
echo "User not connected to the provider.";
$adapter->logout();
break;
case 8:
echo "Provider does not support this feature.";
break;
}
}
//.........这里部分代码省略.........
示例4: dispatch
/**
* An alias of {@link dispatch_get()}
*
* @return void
*/
function dispatch($path_or_array, $function, $options = array())
{
dispatch_get($path_or_array, $function, $options);
}
示例5: dispatch
{
(int) $id;
return $id;
}
dispatch('/route8c/:id', 'test_route8c', array('params' => array('divider' => 2)));
function test_route8c($divider, $id)
{
(int) $id;
return $id / $divider;
}
dispatch('/route9/*', 'MyController::staticMethod');
dispatch('/route9b/*', 'MyController::staticMethod', array('params' => array(10)));
dispatch(array('/route10/*', array('id')), 'MyController::staticMethod');
dispatch(array('/route10b/*', array('id')), 'MyController::staticMethod', array('params' => array('id' => 10)));
/* http methods dispatching */
dispatch_get('/route11', 'test_route11');
function test_route11()
{
header('X-LIM-CTL: route11');
return "GET";
}
dispatch_post('/route11', 'test_route11post');
function test_route11post()
{
//header('Content-length: 4');
return "POST";
}
dispatch_put('/route11', 'test_route11put');
function test_route11put()
{
return "PUT";
示例6: dispatch
/**
* an alias of dispatch_get
*
* @return void
*/
function dispatch($path_or_array, $function, $agent_regexp = null)
{
dispatch_get($path_or_array, $function, $agent_regexp);
}
示例7: dispatch_get
dispatch_get('/new_topic', function () {
$forum = new \Controller\forum();
$forum->manage_topic();
CODOF\Smarty\Layout::load($forum->view, $forum->css_files, $forum->js_files);
});
dispatch_get('/tags/:tag/:page', function ($tag, $page = 1) {
if (!isset($tag)) {
return \CODOF\Smarty\Layout::not_found();
}
CODOF\Store::set('meta:robots', 'noindex, follow');
$clean_tag = strip_tags($tag);
$forum = new Controller\forum();
$forum->listTaggedTopics($clean_tag, $page);
CODOF\Smarty\Layout::load($forum->view, $forum->css_files, $forum->js_files);
});
//-------------INDEX------------------------------------------------------------
dispatch_get('/', function () {
global $installed;
if (!$installed) {
$url = str_replace("index.php?u=/", "", RURI);
header("Location: " . $url . "install/index.php");
}
$forum = new \Controller\forum();
$forum->topics(1);
CODOF\Smarty\Layout::load($forum->view, $forum->css_files, $forum->js_files);
});
function not_found($errno, $errstr, $errfile = null, $errline = null)
{
CODOF\Smarty\Layout::not_found();
}
Request::start();
示例8: dispatch
/**
* an alias of dispatch_get
*
* @return void
*/
function dispatch($path_or_array, $function)
{
dispatch_get($path_or_array, $function);
}
示例9: option
option('env', $env);
option('dsn', $dsn);
option('db_conn', $db);
option('debug', true);
}
function after($output)
{
$time = number_format((double) substr(microtime(), 0, 10) - LIM_START_MICROTIME, 6);
$output .= "<!-- page rendered in {$time} sec., on " . date(DATE_RFC822) . "-->";
return $output;
}
layout('layout/default.html.php');
// main controller
dispatch('/', 'main_page');
// books controller
dispatch_get('books', 'books_index');
dispatch_post('books', 'books_create');
dispatch_get('books/new', 'books_new');
dispatch_get('books/:id/edit', 'books_edit');
dispatch_get('books/:id', 'books_show');
dispatch_put('books/:id', 'books_update');
dispatch_delete('books/:id', 'books_destroy');
// authors controller
dispatch_get('authors', 'authors_index');
dispatch_post('authors', 'authors_create');
dispatch_get('authors/new', 'authors_new');
dispatch_get('authors/:id/edit', 'authors_edit');
dispatch_get('authors/:id', 'authors_show');
dispatch_put('authors/:id', 'authors_update');
dispatch_delete('authors/:id', 'authors_destroy');
run();
示例10: dispatch_get
dispatch_get('/memo/:id', function () {
$db = option('db_conn');
$user = get('user');
$stmt = $db->prepare('SELECT id, user, content, is_private, created_at, updated_at FROM memos WHERE id = :id');
$stmt->bindValue(':id', params('id'));
$stmt->execute();
$memo = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$memo) {
return halt(404);
}
if ($memo['is_private'] != 0) {
if (!$user || $user['id'] != $memo['user']) {
return halt(404);
}
}
$memo['content_html'] = markdown($memo['content']);
$stmt = $db->prepare('SELECT username FROM users WHERE id = :id');
$stmt->bindValue(':id', $memo['user']);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$memo['username'] = $row['username'];
if ($user && $user['id'] == $memo['user']) {
$cond = "";
} else {
$cond = "AND is_private=0";
}
$stmt = $db->prepare("SELECT * FROM memos WHERE user = :user " . $cond . " ORDER BY created_at");
$stmt->bindValue(':user', $memo['user']);
$stmt->execute();
$memos = $stmt->fetchAll(PDO::FETCH_ASSOC);
$older = null;
$newer = null;
for ($i = 0; $i < count($memos); $i++) {
if ($memos[$i]['id'] == $memo['id']) {
if ($i > 0) {
$older = $memos[$i - 1];
}
if ($i < count($memos) - 1) {
$newer = $memos[$i + 1];
}
}
}
set('memo', $memo);
set('older', $older);
set('newer', $newer);
return html('memo.html.php');
});
示例11: dispatch_get
dispatch_get("/promos/get/:promo", "getPromo");
//get a promo
dispatch_post("/promos/add/:promo/:label", "addPromo");
//add a promo
dispatch_post("/promos/del/:promo", "delPromo");
//delete a promo
dispatch_post("/promos/upd/:promo/:newLabel", "updPromo");
//update promo
dispatch_get("/files/get/:id", "getFile");
//get file
dispatch_get("/files/get/promo/:promo", "getFile");
//get files associated with promo
dispatch_post("/files/add/:promo/:rang/:libelle", "addFile");
//add a file
dispatch_post("/files/del/:id", "delFile");
//delete a file
dispatch_post("/files/upd/:id/:promo/:rang/:libelle", "updFile");
//upd file
dispatch_get("/datas/get/all", "getData");
//gat all data
dispatch_get("/datas/get/:id", "getData");
//get a data
dispatch_get("/datas/xtr", "xtrData");
//export datas
dispatch_post("/datas/upd/:id/:identifiant/:nom_fils/:prenom_fils/:ddn_fils/:tel_mobile/:courriel", "updData");
//update data
dispatch_post("/datas/del/all", "delData");
//delete all datas
dispatch_post("/datas/del/:id", "delData");
//delete one data
run();
示例12: dispatch_get
dispatch_get('/timeline', function () {
$db = option('db_conn');
$user = get('user');
$latest_entry = $_GET['latest_entry'];
if ($latest_entry) {
$stmt = $db->prepare('SELECT * FROM (SELECT * FROM entries WHERE (user = :user OR publish_level = 2 OR (publish_level = 1 AND user IN (SELECT target FROM follow_map WHERE user = :user))) AND id > :id ORDER BY id LIMIT 30) AS e ORDER BY e.id DESC');
$stmt->bindValue(':user', $user['id']);
$stmt->bindValue(':id', $latest_entry);
} else {
$stmt = $db->prepare('SELECT * FROM entries WHERE (user = :user OR publish_level = 2 OR (publish_level = 1 AND user IN (SELECT target FROM follow_map WHERE user = :user))) ORDER BY id DESC LIMIT 30');
$stmt->bindValue(':user', $user['id']);
}
$start = time();
while (time() - $start < constant('TIMEOUT')) {
$stmt->execute();
$entries = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($entries) == 0) {
sleep(constant('INTERVAL'));
continue;
} else {
$latest_entry = $entries[0]['id'];
break;
}
}
$entries_arranged = array();
foreach ($entries as $entry) {
$stmt = $db->prepare('SELECT * FROM users WHERE id = :id');
$stmt->bindValue(':id', $entry['user']);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
$entries_arranged[] = array('id' => $entry['id'], 'image' => uri_for('/image/' . $entry['image']), 'publish_level' => $entry['publish_level'], 'user' => array('id' => $user['id'], 'name' => $user['name'], 'icon' => uri_for('/icon/' . $user['icon'])));
}
return json(array('latest_entry' => $latest_entry, 'entries' => $entries_arranged));
});
示例13: dispatch
<?php
require_once 'autoload.php';
//load app classes
require_once 'lib/limonade.php';
dispatch('/css/:css', 'AssetController::css');
dispatch('/js/:js', 'AssetController::js');
//REST API
dispatch_get('/api/users', 'UserController::index');
dispatch_get('/api/users/:id', 'UserController::get');
dispatch_post('/api/users', 'UserController::post');
dispatch_put('/api/users/:id', 'UserController::put');
dispatch_delete('/api/users/:id', 'UserController::remove');
dispatch_get('/api/users/search/:name', 'UserController::search');
//pages
dispatch('/', 'MainController::index');
run();
示例14: dirname
require dirname(__DIR__) . '/lib/limonade.php';
//
// configuration
//
function configure()
{
option('root_dir', dirname(__DIR__));
option('views_dir', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'views');
option('controllers_dir', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'controllers');
option('lib_dir', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lib');
option('public_dir', __DIR__);
}
function before()
{
layout('layouts/layout.phtml');
}
//
// application
//
dispatch_get('/', function () {
return html('index.phtml');
});
dispatch_get('/shopsavvy/:id', function ($id) {
if (empty($id)) {
halt(NOT_FOUND);
}
$json = file_get_contents("http://api.developer.shopsavvy.mobi/products/{$id}.json?apikey=91f7ccdc3a32b5ba899e64fd191942c8");
return $json;
});
run();
示例15: option
option('env', ENV_DEVELOPMENT);
option('debug', true);
option('session', 'Yummy_Plus3_Session_Cookie');
// true, false or the name of your session
option('encoding', 'utf-8');
}
// END function configure()
# the index request
dispatch('/', function () {
return 'hello world';
});
dispatch('/phpinfo', function () {
phpinfo();
return;
});
$echo = function () {
setcookie('example', 'test');
$response = array();
foreach ($GLOBALS as $key => $data) {
if ($key != 'GLOBALS') {
$response[$key] = $data;
}
}
$response['_HEADERS'] = http_get_request_headers();
return json($response);
};
dispatch_get('/echo', $echo);
dispatch_post('/echo', $echo);
dispatch_put('/echo', $echo);
dispatch_delete('/echo', $echo);
run();