本文整理汇总了PHP中Slim\Slim::notFound方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::notFound方法的具体用法?PHP Slim::notFound怎么用?PHP Slim::notFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::notFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param \Slim\Slim $app Slim app reference
*/
public function __construct(\Slim\Slim $app)
{
$this->app = $app;
$this->app->notFound(function () use($app) {
$data = array('error' => array('message' => 'Invalid route'));
$app->contentType('application/json');
$app->halt(400, json_encode($data));
});
}
示例2: setAssetsRoute
protected function setAssetsRoute()
{
$renderer = $this->debugbar->getJavascriptRenderer();
$this->app->get('/_debugbar/fonts/:file', function ($file) use($renderer) {
// e.g. $file = fontawesome-webfont.woff?v=4.0.3
$files = explode('?', $file);
$file = reset($files);
$path = $renderer->getBasePath() . '/vendor/font-awesome/fonts/' . $file;
if (file_exists($path)) {
$this->app->response->header('Content-Type', (new \finfo(FILEINFO_MIME))->file($path));
echo file_get_contents($path);
} else {
// font-awesome.css referencing fontawesome-webfont.woff2 but not include in the php-debugbar.
// It is not slim-debugbar bug.
$this->app->notFound();
}
})->name('debugbar.fonts');
$this->app->get('/_debugbar/resources/:file', function ($file) use($renderer) {
$files = explode('.', $file);
$ext = end($files);
if ($ext === 'css') {
$this->app->response->header('Content-Type', 'text/css');
$renderer->dumpCssAssets();
} elseif ($ext === 'js') {
$this->app->response->header('Content-Type', 'text/javascript');
$renderer->dumpJsAssets();
}
})->name('debugbar.resources');
$this->app->get('/_debugbar/openhandler', function () {
$openHandler = new OpenHandler($this->debugbar);
$data = $openHandler->handle($request = null, $echo = false, $sendHeader = false);
$this->app->response->header('Content-Type', 'application/json');
$this->app->response->setBody($data);
})->name('debugbar.openhandler');
}
示例3: pageNotFound
function pageNotFound($controller, $method)
{
return parent::notFound(function () use($controller, $method) {
$instance = new $controller();
call_user_func_array(array($instance, $method), array());
});
}
示例4: setupNotFound
/**
* @return $this
*/
protected function setupNotFound()
{
$app = $this->app;
$this->app->notFound(function () use($app) {
$app->render('404.phtml');
});
return $this;
}
示例5: __construct
public function __construct(Neo4j\Client $client, Slim\Slim $app, Theme $theme = null, array $options = null)
{
$this->setOptions($options);
$this->app = $app;
$this->client = $client;
$this->schema = new Schema($client);
if ($theme) {
$this->setTheme($theme);
}
if ($this->hasOption('upload.directory')) {
$this->setUploadDirectory($this->getOption('upload.directory'));
}
// Set up the home route.
$app->get('/', Closure::bind(function () {
$controller = new Controllers\HomeController($this->app, $this->schema, $this->client);
$controller->read();
}, $this));
// Set up the uploads route.
$app->get($this->getOption('path.format.uploads'), Closure::bind(function ($file_name) {
$controller = new Controllers\UploadController($this->app);
$controller->read($file_name);
}, $this));
// Set up the search controller.
$app->get($this->getOption('path.format.search'), Closure::bind(function () {
$controller = new Controllers\SearchController($this->app, $this->schema, $this->client);
$controller->run();
}, $this))->name('search');
// Set up the resources controller.
$this->app->get($this->getOption('path.format.resources'), Closure::bind(function (array $resource_path) {
$theme = $this->getTheme();
// Pass if not an instance or child of the default theme, as Theme#renderResource won't be present.
// In non-standard use cases, this allows the user to use a regular Slim\View as the view.
if (!$theme) {
$this->getApp()->pass();
}
$controller = new Controllers\FileController($this->app);
if ($theme->hasResource($resource_path)) {
$controller->read($theme->getResourcePath($resource_path));
} else {
$this->getApp()->notFound(new Exceptions\Exception('Unknown resource "' . implode('/', $resource_path) . '".'));
}
}, $this))->name('resources');
// Set up a default handler for 404 errors.
// Only Penelope application-generated exceptions are permitted.
$app->notFound(function (Exceptions\Exception $e = null) {
if (!$e) {
$e = new Exceptions\NotFoundException('The requested page cannot be found.');
}
$controller = new Controllers\Controller($this->app);
$this->app->render('error', array('title' => $controller->_m('error_404_title'), 'error' => $e), 404);
});
}
示例6: __construct
/**
* Constructor.
*
* @param array $options The SameAs Lite Store for which we shall
* provide RESTful interfaces.
*/
public function __construct(array $options = array())
{
// fake $_SERVER parameters if required (eg command line invocation)
\SameAsLite\Helper::initialiseServerParameters();
// set the default format of acceptable parameters
// see http://docs.slimframework.com/routing/conditions/#application-wide-route-conditions
\Slim\Route::setDefaultConditions(array('store' => '[a-zA-Z0-9_\\-\\.]+'));
// initialise and configure Slim, using Twig template engine
$mode = isset($options['mode']) ? $options['mode'] : 'production';
$this->app = new \Slim\Slim(array('mode' => $mode, 'debug' => false, 'view' => new \Slim\Views\Twig()));
// configure Twig
$this->app->view()->setTemplatesDirectory('assets/twig/');
$this->app->view()->parserOptions['autoescape'] = false;
$this->app->view()->set('path', $this->app->request()->getRootUri());
// register 404 and custom error handlers
$this->app->notFound(array(&$this, 'outputError404'));
$this->app->error(array(&$this, 'outputException'));
// '\SameAsLite\Exception\Exception::outputException'
set_exception_handler(array(&$this, 'outputException'));
// '\SameAsLite\Exception\Exception::outputException'
// Hook to set the api path
$this->app->hook('slim.before.dispatch', function () {
// fix api pages such that if viewing a particular store
// then the store name is automatically injected for you
$params = $this->app->router()->getCurrentRoute()->getParams();
if (isset($params['store'])) {
$apiPath = "datasets/{$params['store']}/api";
} else {
$apiPath = 'api';
}
$this->app->view()->set('apiPath', $apiPath);
});
// save the options
$this->appOptions = $options;
// apply options to template
foreach ($options as $k => $v) {
$this->app->view->set($k, $v);
}
}
示例7: addRouteDefinitions
/**
* This methods will be called at application startup
* @param $appInstance
* @return void
* @throws \Exception
*/
public static function addRouteDefinitions(Slim $appInstance)
{
$appInstance->map('/protected-storage/:inst/:id/:accessMethod/:path+', function ($inst, $id, $accessMethod, $path) use($appInstance) {
if (!in_array($accessMethod, cProtectedStorage::$allowedAccessMethods, true)) {
$appInstance->halt(400, 'Invalid request');
}
$fileName = array_pop($path);
$rel = '';
foreach ($path as $value) {
$rel .= $value . '/';
}
$rel .= $fileName;
$user = null;
if ($accessMethod === 'private') {
try {
$user = new MembersAuth();
$user->isUserLoggedIn();
} catch (LoginExceptions $e) {
$appInstance->halt(401, 'Unauthorized');
}
}
$fullPath = $inst . '/' . $id . '/' . $accessMethod . '/' . $rel;
$controller = new cProtectedStorage($inst, $id, $accessMethod, $rel);
if ($controller->isCorrectPath($fullPath)) {
$appInstance->etag(md5($fullPath));
$appInstance->expires('+1 week');
$headers = $controller->outputFile();
if (array_key_exists('download', $_REQUEST)) {
$headers['Content-Type'] = 'application/octet-stream';
}
foreach ($headers as $key => $value) {
$appInstance->response->headers->set($key, $value);
}
} else {
$appInstance->notFound();
}
})->via('GET', 'POST');
}
示例8: function
$data['langs'] = (require '../app/langs/' . $data['lang'] . '.php');
$pages = (require '../app/config/pages.php');
$lang = $data['lang'];
$data['route'] = function ($routeName) use($pages, $lang, $route) {
return $route . $pages[$routeName][$lang]['route'];
};
$app->group($route, function () use($app, $data, $pages) {
require '../app/routes/site.php';
});
// ==================================================================
//
// Errors 404 and 500
//
// ------------------------------------------------------------------
$app->notFound(function () use($app) {
$data['metas']['title'] = '404 Page not Found';
$app->render('404', $data);
});
$app->error(function () use($app) {
$data['metas']['title'] = 'Internal server error';
$app->render('500', $data);
});
// ==================================================================
//
// Cookies advise
//
// ------------------------------------------------------------------
$data['cookieState'] = !isset($_COOKIE[$data['cookies']['name']]) ? true : false;
// ==================================================================
//
// Add before.dispatch and run app
//
示例9: attach
/**
* @param Slim $slim
*
* @return void
*/
public function attach(Slim $slim)
{
// Register Global Exception Handler
$slim->notFound([$this, 'handleNotFound']);
// Register Global Exception Handler
$slim->error([$this, 'handleException']);
}
示例10: function
$app->put('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
$resource = Resource::load($app->version, $resource, $subResource);
if ($resource === null) {
Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
} else {
$resource->put();
}
});
// Delete
$app->delete('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
$resource = Resource::load($app->version, $resource, $subResource);
if ($resource === null) {
Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
} else {
$resource->delete();
}
});
// Options
$app->options('/:resource(/(:action)(/))', function ($resource, $subResource = null) use($app) {
$resource = Resource::load($app->version, $resource, $subResource);
if ($resource === null) {
Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
} else {
$resource->options();
}
});
// Not found
$app->notFound(function () {
Resource::error(Resource::STATUS_NOT_FOUND, 'Cannot find requested resource.');
});
$app->run();
示例11: Slim
}
$app = new Slim(['mode' => $slimMode, 'debug' => $debug, 'view' => $di->layoutHtml]);
// Allow to decode json request body
$app->add(new ContentTypesMiddleware());
$app->get('/auth/login', function () use($app) {
$app->render('auth/login');
});
$app->get('/auth/twitter/login', function () {
AuthTwitterController::getInstance()->login();
});
$app->get('/auth/twitter/callback', function () {
AuthTwitterController::getInstance()->callback();
});
$app->get('/auth/logout', function () {
AuthentifierController::getInstance()->logout();
});
$app->get('/home', function () {
HomeController::getInstance()->home();
});
$app->get('/api/articles', function () {
ArticlesController::getInstance()->get();
});
$app->patch('/api/articles/:id', function ($id) {
ArticlesController::getInstance()->update($id);
});
$app->notFound(function () use($app) {
$status = 404;
$app->response->setStatus($status);
$app->render('error', ['errno' => $status, 'message' => $app->response->getMessageForCode($status)]);
});
return $app;
示例12: function
/**
* LEGACY REDIRECT
**/
$app->get('/redeem/redeem.php?c=:code&p=:album', function ($album, $code) use($app) {
$app->redirect('./redeem/' . $album . '/' . $code);
});
/**
* Album Download page
**/
$app->get('/download/:album/:code', function ($album, $code) use($app, $dl) {
$download = $dl->file_download($album, $code);
$dl->use_code($code, $album);
})->name('download');
// Custom 404 Page
$app->notFound(function () use($app) {
$app->render('notfound.twig');
});
// Temporary Admin Page
$app->get('/webhook/', function () use($app) {
$app->response->setStatus(200);
});
// Temporary Admin Page
$app->post('/webhook/', function () use($app, $dl) {
$app->response->setStatus(200);
$wh = json_decode($app->request->post('mandrill_events'), true);
foreach ($wh as $event) {
$sent_time = date("Y-m-d H:i:s", $event['msg']['ts']);
$event_time = date("Y-m-d H:i:s", $event['ts']);
$state = $event['msg']['state'];
$id = $event['msg']['_id'];
$email = $event['msg']['email'];
示例13: Slim
use Slim\Slim;
require 'includes/classmap.php';
require 'Vendor/autoload.php';
spl_autoload_register('autoloadlitpi');
//Init slim object
$app = new Slim();
/////////////////////////
///// Important, process to include controller file
///This is the main different with LITPI framework core
//Parsing route information to include module/controller
$route = trim($app->request->getPathInfo(), '/');
$parts = explode('/', $route);
for ($i = 0; $i < count($parts); $i++) {
$parts[$i] = htmlspecialchars($parts[$i]);
}
$module = array_shift($parts);
$controller = array_shift($parts);
$action = array_shift($parts);
$class = '\\controller\\' . $module . '\\' . $controller;
//check if valid controller
if (classmap($class) != '') {
/** @var \Controller\BaseController $myControllerObj */
$myControllerObj = new $class($app);
$myControllerObj->run();
} else {
$app->notFound(function () use($app) {
echo 'Not found';
});
}
$app->run();
示例14: Slim
<?php
use ComPHPPuebla\Slim\Hook\PhpSettingsHook;
use ComPHPPuebla\Slim\Handler\ErrorHandler;
use ComPHPPuebla\Slim\Handler\NotFoundHandler;
use ComPHPPuebla\Slim\Middleware\JsonpMiddleware;
use ComPHPPuebla\Slim\Middleware\ContentNegotiationMiddleware;
use ComPHPPuebla\Slim\Middleware\HttpCacheMiddleware;
use Slim\Slim;
use Api\Station\StationRoutes;
use Api\ApplicationContainer;
use Api\Station\StationContainer;
chdir(__DIR__);
require 'vendor/autoload.php';
$app = new Slim(require 'config/app.config.php');
$app->notFound(new NotFoundHandler($app));
$app->error(new ErrorHandler($app));
$app->hook('slim.before', new PhpSettingsHook(require 'config/phpini.config.php'));
$container = new ApplicationContainer();
$container->register($app);
$app->add(new HttpCacheMiddleware($app->cache));
$app->add(new ContentNegotiationMiddleware());
$app->add(new JsonpMiddleware());
$stationContainer = new StationContainer();
$stationContainer->register($app);
$stationRoutes = new StationRoutes($app);
$stationRoutes->register();
示例15: checkRoute
protected function checkRoute($controllerName, $action)
{
if (is_callable(array($controllerName, $action)) === false) {
$this->app->notFound();
}
}