本文整理汇总了PHP中Slim::map方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::map方法的具体用法?PHP Slim::map怎么用?PHP Slim::map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim
的用法示例。
在下文中一共展示了Slim::map方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _call
/**
* Generic routes handler
* @param String $method Http method, e.g. GET, POST
* @param String $url method url
* @param String $action action to perform
* @return [type] [description]
*/
private function _call($method, $url, $action)
{
//return $this->app->$method($url, function () use ($action) {
return $this->app->map($url, function () use($action) {
$action = explode('@', $action);
$modelClass = $action[0] . 'Model';
$modelClassFile = ROOT . DS . APP_DIR . DS . 'Model' . DS . $modelClass . '.php';
$model = NULL;
if (file_exists($modelClassFile)) {
require $modelClassFile;
$model = new $modelClass($this->app);
}
$controllerClass = $action[0] . 'Controller';
$controllerClassFile = ROOT . DS . APP_DIR . DS . 'Controller' . DS . $controllerClass . '.php';
// TODO: check if file exists. Throw exception if it doesn't
require $controllerClassFile;
$method = $action[1];
$controller = new $controllerClass($this->app, $model);
// call controller
call_user_func_array([$controller, $method], func_get_args());
// Render view if no redirection has been set
if ($this->app->response->getStatus() !== 302) {
call_user_func_array([$controller, 'renderer'], [$action[0], $method]);
}
})->via($method);
//return $this->app;
}
示例2: __construct
/**
* REST actions
*
* This function contains the REST actions with the assignments to
* the functions.
*/
public function __construct()
{
// initialize slim
if (!isset($_SERVER['REQUEST_METHOD'])) {
} else {
$this->app = new \Slim\Slim(array('debug' => true));
$this->app->response->headers->set('Content-Type', 'application/json');
$this->app->map('/test', array($this, 'testLFile'))->via('POST');
$this->app->map('/fileDb/:path+/hash/:hash', array($this, 'fileDbGet'))->via('GET');
$this->app->map('/fileDb/file', array($this, 'fileDbPost'))->via('POST');
$this->app->map('/file/file', array($this, 'fileFsPost'))->via('POST');
// run Slim
$this->app->run();
}
}
示例3: __construct
/**
* REST actions
*
* This function contains the REST actions with the assignments to
* the functions.
*/
public function __construct()
{
// runs the CConfig
$com = new CConfig(LFormProcessor::getPrefix() . ',course,link', dirname(__FILE__));
// runs the LFormProcessor
if ($com->used()) {
return;
}
$conf = $com->loadConfig();
// initialize slim
$this->app = new \Slim\Slim(array('debug' => true));
$this->app->response->headers->set('Content-Type', 'application/json');
// initialize component
$this->_conf = $conf;
$this->_formDb = CConfig::getLinks($conf->getLinks(), "formDb");
$this->_pdf = CConfig::getLinks($conf->getLinks(), "pdf");
$this->_postProcess = CConfig::getLinks($conf->getLinks(), "postProcess");
$this->_deleteProcess = CConfig::getLinks($conf->getLinks(), "deleteProcess");
$this->_getProcess = CConfig::getLinks($conf->getLinks(), "getProcess");
// POST PostProcess
$this->app->map('/' . $this->getPrefix() . '(/)', array($this, 'postProcess'))->via('POST');
// POST AddCourse
$this->app->post('/course(/)', array($this, 'addCourse'));
// POST DeleteCourse
$this->app->delete('/course/:courseid(/)', array($this, 'deleteCourse'));
// GET GetExistsCourse
$this->app->get('/link/exists/course/:courseid(/)', array($this, 'getExistsCourse'));
// run Slim
$this->app->run();
}
示例4: setRoutes
/**
* Set Application routes based on the routes specified in config
* Also sets layout file if it's enabled for that specific route
*/
private function setRoutes()
{
$this->_routes = $this->slim->config('routes');
foreach ($this->_routes as $key => $value) {
$self = $this;
$this->slim->map($value['route'], function () use($self, $key, $value) {
$args = func_get_args();
if (isset($value['layout']) && !$value['layout']) {
$self->enableLayout = false;
} else {
$self->setLayout();
}
$self->slim->view()->appendGlobalData(array('page.title' => ucfirst($key)));
if ($key == '__root__') {
$self->slim->view()->appendGlobalData(array('page.title' => 'Home'));
$self->loadArticles(10);
} elseif ($key == 'rss' || $key == 'atom') {
$self->loadArticles(10);
} elseif ($key == 'article') {
$ext = $self->slim->config('file.extension');
$self->loadArticle($self->getPath($args), true);
} elseif ($key == 'archives') {
$self->loadArchives($args);
}
$self->render($value['template']);
})->via('GET')->name($key)->conditions(isset($value['conditions']) ? $value['conditions'] : array());
}
}
示例5: __construct
/**
* REST actions
*
* This function contains the REST actions with the assignments to
* the functions.
*/
public function __construct()
{
// runs the CConfig
$com = new CConfig(LProcessor::getPrefix() . ',submission,course,link', dirname(__FILE__));
// runs the LProcessor
if ($com->used()) {
return;
}
$conf = $com->loadConfig();
// initialize slim
$this->app = new \Slim\Slim();
$this->app->response->headers->set('Content-Type', 'application/json');
// initialize component
$this->_conf = $conf;
$this->_submission = CConfig::getLinks($conf->getLinks(), "submission");
$this->_marking = CConfig::getLinks($conf->getLinks(), "marking");
$this->_processorDb = CConfig::getLinks($conf->getLinks(), "processorDb");
$this->_attachment = CConfig::getLinks($conf->getLinks(), "attachment");
$this->_workFiles = CConfig::getLinks($conf->getLinks(), "workFiles");
$this->_file = CConfig::getLinks($conf->getLinks(), "file");
$this->_createCourse = CConfig::getLinks($conf->getLinks(), "postCourse");
$this->_getExerciseExerciseFileType = CConfig::getLinks($conf->getLinks(), "getExerciseExerciseFileType");
// POST PostSubmission
$this->app->map('/submission(/)', array($this, 'postSubmission'))->via('POST');
// POST AddProcess
$this->app->map('/' . $this->getPrefix() . '(/)', array($this, 'addProcess'))->via('POST');
// POST AddCourse
$this->app->post('/course(/)', array($this, 'addCourse'));
// POST DeleteCourse
$this->app->delete('/course/:courseid(/)', array($this, 'deleteCourse'));
// GET GetExistsCourse
$this->app->get('/link/exists/course/:courseid(/)', array($this, 'getExistsCourse'));
// run Slim
$this->app->run();
}
示例6: setRoutes
/**
* Set Application routes based on the routes specified in config
* Also sets layout file if it's enabled for that specific route
*/
public function setRoutes()
{
$this->_routes = $this->getConfig('routes');
$self = $this;
$prefix = $this->getConfig('prefix');
foreach ($this->_routes as $key => $value) {
$this->slim->map($prefix . $value['route'], function () use($self, $key, $value) {
$args = func_get_args();
$layout = isset($value['layout']) ? $value['layout'] : true;
// This will store a custom function if defined into the route
$custom = isset($value['custom']) ? $value['custom'] : false;
$self->slim->view()->appendGlobalData(array("route" => $key));
$template = isset($value['template']) ? $value['template'] : false;
//set view data for article and archives routes
switch ($key) {
case '__root__':
case 'rss':
case 'atom':
$self->allArticles = array_slice($self->allArticles, 0, 10);
break;
case 'sitemap':
$self->slim->response->headers->set('Content-Type', 'text/xml');
$self->setSitemapData();
break;
case 'article':
$article = $self->setArticle($self->getPath($args));
$template = $article->getMeta('template') && $article->getMeta('template') != "" ? $article->getMeta('template') : $template;
break;
case 'archives':
$self->loadArchives($args);
break;
case 'category':
case 'tag':
$self->filterArticles($key, $args[0]);
break;
// If key is not matched, check if a custom function is declared
// If key is not matched, check if a custom function is declared
default:
if ($custom && is_callable($custom)) {
call_user_func($custom, $self, $key, $value);
}
break;
}
if (!$layout) {
$self->enableLayout = false;
} else {
$self->setLayout($layout);
}
// render the template file
$self->render($template);
})->via('GET')->name($key)->conditions(isset($value['conditions']) ? $value['conditions'] : array());
}
// Register not found handler
$this->slim->notFound(function () use($self) {
$self->slim->render('404');
});
}
示例7: __construct
/**
* REST actions
*
* This function contains the REST actions with the assignments to
* the functions.
*/
public function __construct()
{
// runs the CConfig
$com = new CConfig(LOOP::getPrefix() . ',course,link', dirname(__FILE__));
// runs the LOOP
if ($com->used()) {
return;
}
$conf = $com->loadConfig();
// lädt die Daten der CConfig.json
// initialize slim
$this->app = new \Slim\Slim(array('debug' => true));
$this->app->response->headers->set('Content-Type', 'application/json');
// initialize component
// hier werden die Verknüpfungen aus der CConfig.json ausgelesen (entsprechend ihrem Namen)
$this->_conf = $conf;
$this->_pdf = CConfig::getLinks($conf->getLinks(), "pdf");
// wird nicht genutzt, theoretisch koennten hier PDFs erzeugt werden
// für POST /course zum eintragen als Verarbeitung (wird dann in CreateSheet aufgelistet)
$this->_postProcess = CConfig::getLinks($conf->getLinks(), "postProcess");
$this->_deleteProcess = CConfig::getLinks($conf->getLinks(), "deleteProcess");
// für DELETE /course/xyz
$this->_getProcess = CConfig::getLinks($conf->getLinks(), "getProcess");
// GET /link/exists/course/:courseid
// POST PostProcess
$this->app->map('/' . $this->getPrefix() . '(/)', array($this, 'postProcess'))->via('POST');
// POST AddCourse
// fügt die Komponente der Veranstaltung hinzu (Daten kommen im Anfragekörper)
$this->app->post('/course(/)', array($this, 'addCourse'));
// DELETE DeleteCourse
// entfernt die Komponente aus der Veranstaltung
$this->app->delete('/course/:courseid(/)', array($this, 'deleteCourse'));
// GET GetExistsCourse
// zum Prüfen, ob diese Kompoenten korrekt installiert wurde (existiert Tabelleneintrag, konf-Dateien etc.)
$this->app->get('/link/exists/course/:courseid(/)', array($this, 'getExistsCourse'));
// run Slim
$this->app->run();
}
示例8: start
This is a full-featured conference bridge, written for Tropo's WebAPI
using the Slim Framework for PHP (http://www.slimframework.com/) and
the Tropo WebAPI library (https://github.com/tropo/tropo-webapi-php)
To use, install Slim Framework according to the documentation. Adjust
the require lines to match your locations of Slim and the Tropo classes.
Set your Tropo application's start URL to be the url to your Slim
installation and call your application.
*/
// Which voice would you like to use in prompts?
$voice = 'Veronica';
require '../tropo.class.php';
require 'Slim/Slim.php';
$app = new Slim();
$app->map('/', 'start')->via('GET')->via('POST');
$app->post('/restart', 'start');
function start()
{
global $voice;
$tropo = new Tropo();
$tropo->setVoice($voice);
$tropo->ask("Enter your conference ID, followed by the pound key.", array("choices" => "[1-10 DIGITS]", "name" => "confid", "attempts" => 5, "timeout" => 60, "mode" => "dtmf", "terminator" => "#", "event" => array("incomplete" => 'Sorry, I didn\'t hear anything.', "nomatch" => 'Sorry, that is not a valid conference ID.')));
$tropo->on(array("event" => "continue", "next" => "conference"));
$tropo->on(array("event" => "incomplete", "next" => "restart"));
$tropo->RenderJson();
}
$app->post('/conference', 'conference');
function conference()
{
global $voice;
示例9: function
}
// process referrer tag
if (isset($_GET['ref']) && isset($referrers[$_GET['ref']])) {
$_SESSION['ref'] = $_GET['ref'];
$_SESSION['tag'] = $referrers[$_GET['ref']];
} else {
$_SESSION['ref'] = null;
}
});
$routes = (include 'routes.php');
// Use Slim with Class#method style routes
foreach ($routes as $name => $details) {
$fn = function () use($details) {
list($class, $method) = explode('.', $details[1]);
$class = "{$class}Controller";
call_user_func_array(array(new $class(), $method), func_get_args());
};
$route = $app->map($details[0], $fn)->name($name);
if (isset($details['method'])) {
if (!is_array($details['method'])) {
$details['method'] = array($details['method']);
}
call_user_func_array(array($route, 'via'), $details['method']);
} else {
$route->via('GET');
}
if (isset($details['conditions'])) {
$route->conditions($details['conditions']);
}
}
$app->run();
示例10: function
return $argument;
});
// End FILTERS
/* == *
*
* ROUTES
*
* ==============================================*/
$app->map('/', function () use($app) {
if ($app->request()->isPost() && sizeof($app->request()->post()) == 2) {
// if valid login, set auth cookie and redirect
$testp = sha1('uAX8+Tdv23/3YQ==');
$post = (object) $app->request()->post();
if (isset($post->username) && isset($post->password) && sha1($post->password) == $testp && $post->username == 'bppenne') {
//$app->setEncryptedCookie('bppasscook', $post->password, 0);
$app->setCookie('user_cook', $post->username, 0);
$app->setCookie('pass_cook', $post->password, 0);
$app->redirect('./review');
} else {
$app->redirect('.');
}
}
$app->render('login.html');
})->via('GET', 'POST')->name('login');
$authUser = function ($role = 'member') use($app) {
return function () use($role) {
$app = Slim::getInstance();
// Check for password in the cookie
if ($app->getCookie('pass_cook') != 'uAX8+Tdv23/3YQ==' || $app->getCookie('user_cook') != 'bppenne') {
//if ( $app->getEncryptedCookie('bppasscook', false) != 'uAX8+Tdv23/3YQ==') {
$app->redirect('..');
//$app->redirect('review');
示例11: testGenericRoute
/**
* Test GENERIC route
*/
public function testGenericRoute()
{
$s = new Slim();
$callable = function () {
echo "foo";
};
$route = $s->map('/bar', $callable);
$this->assertInstanceOf('Slim_Route', $route);
$this->assertEmpty($route->getHttpMethods());
}
示例12: testNotFoundIfNoMatchingRoutes
/**
* Test that app returns 404 response when there are no matching routes
*/
public function testNotFoundIfNoMatchingRoutes()
{
$_SERVER['REQUEST_URI'] = "/foo";
$_SERVER['REQUEST_METHOD'] = 'GET';
$app = new Slim();
$app->map('/foo/bar', function () {
echo "Foo bar!";
})->via('GET');
$app->run();
$this->assertEquals(404, $app->response()->status());
}
示例13: setRoutes
/**
* Set Application routes based on the routes specified in config
* Also sets layout file if it's enabled for that specific route
*/
public function setRoutes()
{
$this->_routes = $this->config('routes');
$self = $this;
$prefix = $self->slim->config('prefix');
foreach ($this->_routes as $key => $value) {
$this->slim->map($prefix . $value['route'], function () use($self, $key, $value) {
$args = func_get_args();
$layout = isset($value['layout']) ? $value['layout'] : true;
if (!$layout) {
$self->enableLayout = false;
} else {
$self->setLayout($layout);
}
$self->slim->view()->appendGlobalData(array("route" => $key));
$template = $value['template'];
//set view data for article and archives routes
switch ($key) {
case '__root__':
case 'rss':
case 'atom':
$self->allArticles = array_slice($self->allArticles, 0, 10);
break;
case 'article':
$article = $self->setArticle($self->getPath($args));
$template = isset($article['meta']['template']) && $article['meta']['template'] != "" ? $article['meta']['template'] : $template;
break;
case 'archives':
$self->loadArchives($args);
break;
case 'category':
case 'tag':
$self->filterArticles($key, $args[0]);
break;
}
// render the template file
$self->render($template);
})->via('GET')->name($key)->conditions(isset($value['conditions']) ? $value['conditions'] : array());
}
// load all articles
// This isn't necessary for route to an article though
// will help to generate tag cloud/ category listing
$self->loadArticles();
// Register not found handler
$this->slim->notFound(function () use($self) {
$self->slim->render('404');
});
}
示例14: function
$app->map('/connect/', function () use($app) {
$params = App::start();
$params['title'] = "Connect";
$params['page'] = "connect";
$params['errors'] = array();
# This user already has an active session
if (App::user()) {
$user = App::getUser();
$params['user_email'] = $user->email;
$params['user_name'] = $user->first_name . ' ' . $user->last_name;
$params['button'] = "Logout";
} else {
# This user is not yet authenticated
# (it is their first visit, or they were redirected here after logout)
if ($app->request()->get('code')) {
# This user has just authenticated, get their access token and store it
$connect = App::connect($app->request()->get('code'));
if (array_key_exists('error', $connect)) {
$params['errors'][] = $connect['error'];
} else {
if (array_key_exists('access_token', $connect)) {
App::begin($connect['access_token'], 1);
$user = App::getUser($connect['access_token']);
$params['user_email'] = $user->email;
$params['user_name'] = $user->first_name . ' ' . $user->last_name;
$params['button'] = "Logout";
}
}
} else {
if ($app->request()->get('error') == 'access_denied') {
$params['errors'][] = "Access Denied";
}
}
}
$params['oauth_link'] = App::getOauthLink();
$app->render('app.tpl', $params);
})->via('GET', 'POST');