本文整理汇总了PHP中lithium\action\Dispatcher类的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher类的具体用法?PHP Dispatcher怎么用?PHP Dispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processResponseBodies
/**
* Builds a composite AMF response based on the response bodies inside the
* original AMF request.
*
* @return Zend_Amf_Response_Http
*/
public function processResponseBodies()
{
$responseBodies = $this->request->getAmfBodies();
foreach ($responseBodies as $body) {
//Extract params from request body
$return = $this->extractUriAndParams($body);
//Create fake request object
$liRequest = new Request(array('data' => $return['params']));
//Assign URL to request based on details
if (isset($return['source'])) {
$liRequest->url = '/' . $return['source'] . '/' . $return['method'];
} elseif (isset($return['targetURI'])) {
$liRequest->url = '/' . $return['targetURI'];
}
//Assign request params
$liRequest->params += $return['params'];
//Dispatch the request normally, and get the controller data
$controllerResponse = Dispatcher::run($liRequest);
//Add on the response data (or error) to the current response
if (isset($controllerResponse->body['error'])) {
$netStatusEvent = new StdClass();
$netStatusEvent->_explicitType = 'flex.messaging.messages.ErrorMessage';
$netStatusEvent->faultString = $controllerResponse->body['error'];
$newBody = new \Zend_Amf_Value_MessageBody($body->getResponseURI() . \Zend_AMF_Constants::STATUS_METHOD, null, $netStatusEvent);
$this->response->addAmfBody($newBody);
} else {
$newBody = new \Zend_Amf_Value_MessageBody($body->getResponseURI() . \Zend_AMF_Constants::STATUS_METHOD, null, $controllerResponse->body);
$this->response->addAmfBody($newBody);
}
}
return $this->response;
}
示例2: function
if (!class_exists('li3_access\\security\\Access')) {
Libraries::add('li3_access');
}
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
// Run other filters first. This allows this one to not exactly be overwritten or excluded...But it does allow for a different login action to be used...
// TODO: Perhaps allow this to be skipped...
$next = $chain->next($self, $params, $chain);
$request = $params['request'];
$action = $request->action;
$user = Auth::check('li3b_user');
// Protect all admin methods except for login and logout.
if ($request->admin === true && $action != 'login' && $action != 'logout') {
$action_access = Access::check('default', $user, $request, array('rules' => array('allowManagers')));
if (!empty($action_access)) {
FlashMessage::write($action_access['message'], 'default');
if ($user) {
header('Location: ' . Router::match($action_access['redirect']));
} else {
header('Location: ' . Router::match(array('library' => 'li3b_users', 'controller' => 'users', 'action' => 'login')));
}
// None shall pass.
exit;
}
}
// Sets the current user in each request for convenience.
$params['request']->user = $user;
return $next;
// return $chain->next($self, $params, $chain);
});
Access::config(array('default' => array('adapter' => 'Rules', 'filters' => array())));
// Set some basic rules to be used from anywhere
// Allow access for users with a role of "administrator" or "content_editor"
示例3: array
* Lithium: the most rad php framework
*
* @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
/**
* This file creates a default cache configuration using the most optimized adapter available, and
* uses it to provide default caching for high-overhead operations.
*/
use lithium\storage\Cache;
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\storage\cache\adapter\Apc;
/**
* If APC is not available and the cache directory is not writeable, bail out.
*/
if (!($apcEnabled = Apc::enabled() && !is_writable(LITHIUM_APP_PATH . '/resources/tmp/cache'))) {
return;
}
Cache::config(array('default' => array('adapter' => '\\lithium\\storage\\cache\\adapter\\' . ($apcEnabled ? 'Apc' : 'File'))));
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
if ($cache = Cache::read('default', 'core.libraries')) {
$cache = (array) unserialize($cache) + Libraries::cache();
Libraries::cache($cache);
}
$result = $chain->next($self, $params, $chain);
if ($cache != Libraries::cache()) {
Cache::write('default', 'core.libraries', serialize(Libraries::cache()), '+1 day');
}
return $result;
});
示例4: function
use lithium\action\Dispatcher;
/**
* This filter intercepts the `run()` method of the `Dispatcher`, and first passes the `'request'`
* parameter (an instance of the `Request` object) to the `Environment` class to detect which
* environment the application is running in. Then, loads all application routes in all plugins,
* loading the default application routes last.
*
* Change this code if plugin routes must be loaded in a specific order (i.e. not the same order as
* the plugins are added in your bootstrap configuration), or if application routes must be loaded
* first (in which case the default catch-all routes should be removed).
*
* If `Dispatcher::run()` is called multiple times in the course of a single request, change the
* `include`s to `include_once`.
*
* @see lithium\action\Request
* @see lithium\core\Environment
* @see lithium\net\http\Router
*/
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
Environment::set($params['request']);
foreach (array_reverse(Libraries::get()) as $name => $config) {
if ($name === 'lithium') {
continue;
}
$file = "{$config['path']}/config/routes.php";
file_exists($file) ? call_user_func(function () use($file) {
include $file;
}) : null;
}
return $chain->next($self, $params, $chain);
});
示例5: function
if ($name === 'lithium') {
continue;
}
$file = "{$config['path']}/config/routes.php";
file_exists($file) ? include $file : null;
}
return $chain->next($self, $params, $chain);
});
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
$ctrl = $chain->next($self, $params, $chain);
$request = isset($params['request']) ? $params['request'] : null;
$action = $params['params']['action'];
if ($request->args) {
$arguments = array();
foreach ($request->args as $value) {
$param = explode(":", $value);
$arguments[$param[0]] = isset($param[1]) ? $param[1] : null;
}
$request->args = $arguments;
}
if (Auth::check('default') || preg_match('|test.*|', $request->url)) {
return $ctrl;
}
if (isset($ctrl->publicActions) && in_array($action, $ctrl->publicActions)) {
return $ctrl;
}
return function () use($request) {
Session::write('message', 'You need to login to access that page.');
return new Response(compact('request') + array('location' => 'Sessions::add'));
};
});
示例6: function
<?php
use lithium\action\Dispatcher;
use lithium\template\View;
use lithium\core\Libraries;
use lithium\net\http\Router;
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
$result = $chain->next($self, $params, $chain);
return $result;
});
Dispatcher::applyFilter('_call', function ($self, $params, $chain) {
$result = $chain->next($self, $params, $chain);
return $result;
});
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
$result = $chain->next($self, $params, $chain);
$li3_show = Libraries::get('li3_show');
$View = new View(array('paths' => array('template' => $li3_show['path'] . '/views/index.html.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
$Show_SQL_View = $View->render('all', array($GLOBALS['Show_SQL']));
if (!isset($result->body[0])) {
$result = $Show_SQL_View . $result;
} else {
$result->body[0] = $Show_SQL_View . $result->body[0];
}
return $result;
});
示例7: function
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
if (substr($params['request']->url, 0, 17) == '/li3_perf/profile') {
return $chain->next($self, $params, $chain);
}
Data::append('timers', array('li3_perf_start_dispatch' => microtime(true)));
$result = $chain->next($self, $params, $chain);
// Mark the end of li3_perf.
// Note: The time it takes to render the toolbar will not be included.
Data::append('timers', array('li3_perf_end' => microtime(true)));
// Render the toolbar (unless it's an asset from the li3_perf library)
// Why? See li3_perf\extensions\util\Asset
$content_type = isset($result->headers['Content-Type']) ? $result->headers['Content-Type'] : '';
$content_type = explode(';', $content_type, 2);
$content_type = array_shift($content_type);
if (!isset($params['request']->params['asset_type']) && (!$content_type || $content_type == 'text/html')) {
$skip = false;
$li3_perf = Libraries::get('li3_perf');
if (isset($li3_perf['skip'])) {
$controller = isset($params['request']->params['controller']) ? $params['request']->params['controller'] : null;
$action = isset($params['request']->params['action']) ? $params['request']->params['action'] : null;
$library = isset($params['request']->params['library']) ? $params['request']->params['library'] : null;
// Check to see if the toolbar should be shown for this library
if (isset($li3_perf['skip']['library'])) {
if (in_array($library, $li3_perf['skip']['library'])) {
$skip = true;
}
}
// Check to see if the toolbar should be shown for this controller
if (isset($li3_perf['skip']['controller'])) {
if (in_array($controller, $li3_perf['skip']['controller'])) {
$skip = true;
}
}
// Check to see if the toolbar should be shown for this action
if (isset($li3_perf['skip']['action'])) {
if (in_array($action, $li3_perf['skip']['action'])) {
$skip = true;
}
}
}
if ($skip || !isset($result->body[0])) {
return $result;
}
$timers = Data::get('timers') + array('li3_perf_start' => 0, 'li3_perf_end' => 0, 'li3_perf_start_dispatch' => 0, 'li3_perf_has_route' => 0, 'li3_perf_start_call' => 0, 'li3_perf_end_call' => 0, '_filter_for_variables' => 0, '_filter_for_queries' => 0);
$View = new View(array('paths' => array('template' => '{:library}/views/elements/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
$toolbar = $View->render('all', array('timers' => $timers += array('dispatch_cycle' => $timers['li3_perf_end'] - $timers['li3_perf_start_dispatch'], 'routing' => $timers['li3_perf_has_route'] - $timers['li3_perf_start_dispatch'], 'call' => isset($timers['li3_perf_end_call']) && isset($timers['li3_perf_start_call']) ? $timers['li3_perf_end_call'] - $timers['li3_perf_start_call'] : 0, 'complete_load_with_li3_perf' => microtime(true) - $timers['li3_perf_start'], 'complete_load' => $timers['li3_perf_end'] - $timers['li3_perf_start'] - $timers['_filter_for_variables'] - $timers['_filter_for_queries']), 'vars' => array('request' => $params['request']->params, 'view' => Data::get('view_vars')), 'queries' => Data::get('queries')), array('library' => 'li3_perf', 'template' => 'toolbar', 'layout' => 'default'));
if (preg_match('/<!--\\s*LI3_PERF_TOOLBAR\\s*-->/si', $result->body[0], $match)) {
$result->body[0] = str_replace($match[0], $toolbar, $result->body[0]);
} else {
$result->body[0] = $toolbar . $result->body[0];
}
}
return $result;
});
示例8: join
StaticClockwork::getInstance()->getTimeline()->endEvent('li3_clockwork_start_call');
if (is_array($params['request']->params) && array_key_exists('controller', $params['request']->params) && array_key_exists('action', $params['request']->params)) {
StaticClockwork::getInstance()->getRequest()->controller = join('::', [$params['request']->params['controller'], $params['request']->params['action']]);
}
// Requests should have special headers
if (!stripos($params['request']->url, '__clockwork') && $result instanceof Controller) {
$result->response->headers('X-Clockwork-Id', StaticClockwork::getInstance()->getRequest()->id, true);
$result->response->headers('X-Clockwork-Version', Clockwork::VERSION, true);
}
return $result;
});
Dispatcher::applyFilter('_call', function ($self, $params, $chain) {
StaticClockwork::getInstance()->getTimeline()->startEvent('li3_clockwork_end_call', 'The controller action has been called and now a response will be returned.');
$result = $chain->next($self, $params, $chain);
// At this point the controller action has been called and now a response will be returned.
// $result here contains the response and we've been setting timers all along the way...
// The next time we'll be working with the same response is under the next filter below on
// run() AFTER $result = $chain->next() is called... That's the end of the dispatch cycle.
// The $result = part below is actually before this filter and the filter on _callable() above.
StaticClockwork::getInstance()->getTimeline()->endEvent('li3_clockwork_end_call');
return $result;
});
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
if (stripos($params['request']->url, '__clockwork')) {
return $chain->next($self, $params, $chain);
}
$result = $chain->next($self, $params, $chain);
StaticClockwork::getInstance()->resolveRequest();
StaticClockwork::getInstance()->storeRequest();
return $result;
});
示例9: function
Dispatcher::applyFilter('_callable', function($self, $params, $chain) {
var_dump(MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common');
/*
* So the problem with redirects and building requests is that since the "app" folder was changed to "minerva"
* the "_base" property is not set properly. In the Request class there's a method called base() that sets it.
* It basically does a string replace on "app/webroot" ... But we have "minerva/webroot" So we can change the
* /minerva/webroot/index.php file and pass in an empty base key of "" to fix the issue.
* I would rather set it here in the filter since that's where all the major changes are taking place.
* I'd like to limit changes to a specific area to avoid complexity...But _base is protected as well as base().
* So we can't set it here. It can only be set by instantiation.
* Alternatively we can write a new class (extending Request) and use that instead...
* TODO: Look into that and in general a sub dispatcher that might avoid several issues and clean up this code.
*
* For now the index.php file has been changed, but that may cause problems elsewhere. Not sure yet.
* Now all the redirects don't show a URL of site.com/minerva/blog it will be the expected site.com/blog
* Both work though.
*/
// Don't apply this for test cases
if($params['request']->params['controller'] == '\lithium\test\Controller') {
return $chain->next($self, $params, $chain);
}
// Get the library if provided from the route params
// (Note: Pages, Users, and Blocks are the only models considered, if any additional are created, the following array must change)
// TODO: ...which is why... consider going back to a standard field name, it makes for less if thens....but it could create more problems for several reasons when it comes to 3rd party addons...the if thens here guarantee things to a good degree
// this array is defined here and also in MinervaController.php
// todo: or maybe just put elsewhere; better maintainability.. can't go back to a standard field name once distributed. this is a very critical thing
$library_fields = array('page_type', 'user_type', 'block_type');
foreach($library_fields as $field) {
if(in_array($field, array_keys($params['request']->params))) {
$library = (isset($params['request']->params[$field])) ? $params['request']->params[$field]:null;
}
}
// The admin flag from routes helps give control over the templates to use
$admin = ((isset($params['request']->params['admin'])) && ($params['request']->params['admin'] == 1 || $params['request']->params['admin'] === true || $params['request']->params['admin'] == 'true')) ? true:false;
// The layout key from the routes give us even more control, it's the final authority on where to check, but things do cascade down
$layout = (isset($params['request']->params['layout'])) ? $params['request']->params['layout']:false;
// Also a template key from the routes again for more control and flexibility
$template = (isset($params['request']->params['template'])) ? $params['request']->params['template']:false;
// DEFAULTS & MISSING TEMPLATE PAGES
$params['options']['render']['paths']['layout'] = array(
MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php',
MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_missing' . DIRECTORY_SEPARATOR . 'missing_layout.{:type}.php'
);
$params['options']['render']['paths']['template'] = array(
MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '{:controller}' . DIRECTORY_SEPARATOR . '{:template}.{:type}.php',
MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_missing' . DIRECTORY_SEPARATOR . 'missing_template.{:type}.php'
);
/**
* DEFAULT FOR PAGE/USER/BLOCK TYPES
* First by default we're going to see if this is even a controller that has a bridge model.
* $library in this case is NOT the route's "library" key, if provided, it's the library name for when
* bridging either a page, user, or a block. We want to use templates from that library's views folder.
* This is not for admin view templates. This is for ex. /minerva/libraries/blog/views/pages/read.html.php
*/
if((!empty($library)) && (empty($admin))) {
// Look at a common if the bridge library doesn't have the templates
array_unshift($params['options']['render']['paths']['layout'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php');
array_unshift($params['options']['render']['paths']['template'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '{:controller}' . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
// These will be on top of the array so it'll look first for something like: minerva/libraries/blog/views/...
array_unshift($params['options']['render']['paths']['layout'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . $library . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php');
array_unshift($params['options']['render']['paths']['template'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . $library . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '{:controller}' . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
}
/**
* 3RD PARTY LIBRARIES
* If the route passed a "library" key then we're going to render from it's views folder.
* This is likely for a 3rd party library that is stand alone, it doesn't hook into pages, users, blocks, etc.
* This is so other applications can be dropped in more easily without template confusion or conflict.
*/
if(isset($params['request']->params['library'])) {
array_unshift($params['options']['render']['paths']['layout'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . $params['request']->params['library'] . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php');
array_unshift($params['options']['render']['paths']['template'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . $params['request']->params['library'] . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '{:controller}' . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
}
/**
* ADMIN TEMPLATES & CORE
* If "admin" is set in the route then we will allow 3rd party templates in the common/views/_admin folder,
* but default back to core. So if an alternative admin interface is desired, then templates need to be
* created in common/views/_admin/...
* NOTE: Admin templates are a specific setting from the routes, they are never defaulted to
*/
if($admin === true) {
// Core (doubles as admin)
array_unshift($params['options']['render']['paths']['layout'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php');
array_unshift($params['options']['render']['paths']['template'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '{:controller}' . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
// Common (for when the default admin interface is desired to be changed)
array_unshift($params['options']['render']['paths']['layout'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_admin' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php');
array_unshift($params['options']['render']['paths']['template'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_admin' . DIRECTORY_SEPARATOR . '{:controller}' . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
// 3rd party libraries can also put in an _admin folder under its views folder they will override templates in common if present. They get priority. (easy portability)
if(!empty($library)) {
array_unshift($params['options']['render']['paths']['layout'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . $library . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_admin' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . '{:layout}.{:type}.php');
array_unshift($params['options']['render']['paths']['template'], MINERVA_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . $library . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . '_admin' . DIRECTORY_SEPARATOR . '{:controller}' . DIRECTORY_SEPARATOR . '{:template}.{:type}.php');
//.........这里部分代码省略.........
示例10: function
/**
* This filter is a convenience method which allows you to automatically route requests for static
* assets stored within active plugins. For example, given a JavaScript file `bar.js` inside the
* `li3_foo` plugin installed in an application, requests to `http://app/path/li3_foo/js/bar.js`
* will be routed to `/path/to/app/libraries/plugins/li3_foo/webroot/js/bar.js` on the filesystem.
* In production, it is recommended that you disable this filter in favor of symlinking each
* plugin's `webroot` directory into your main application's `webroot` directory, or adding routing
* rules in your web server's configuration.
*/
use \lithium\action\Dispatcher;
use \lithium\core\Libraries;
use \lithium\net\http\Media;
Dispatcher::applyFilter('_callable', function($self, $params, $chain) {
list($plugin, $asset) = explode('/', $params['request']->url, 2) + array("", "");
if ($asset && $library = Libraries::get($plugin)) {
$asset = "{$library['path']}/webroot/{$asset}";
if (file_exists($asset)) {
return function () use ($asset) {
$info = pathinfo($asset);
$type = Media::type($info['extension']);
header("Content-type: {$type['content']}");
return file_get_contents($asset);
};
}
}
return $chain->next($self, $params, $chain);
});
?>
示例11: function
<?php
/**
* Initialize code index.
*/
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\console\Dispatcher as ConsoleDispatcher;
use li3_docs\extensions\docs\Code;
$filter = function ($self, $params, $chain) {
$indexPath = Libraries::get(true, 'path') . '/resources/docs.index.json';
if (file_exists($indexPath) && is_readable($indexPath)) {
Code::index((array) json_decode(file_get_contents($indexPath), true));
}
$result = $chain->next($self, $params, $chain);
if (($index = Code::index()) && is_array($index) && is_writable(dirname($indexPath))) {
file_put_contents($indexPath, json_encode($index));
}
return $result;
};
Dispatcher::applyFilter('run', $filter);
ConsoleDispatcher::applyFilter('run', $filter);
/**
* Setup default options:
*
* - `'index'` _array|void_: Allows to restrict indexing to provided set of libraries.
* By default all libraries registered in the application are indexed.
* - `'categories'` _array|void_: Allows manually provide a set of category names. By
* default categories are extracted from all indexed libraries.
*/
Libraries::add('li3_docs', array('bootstrap' => false) + Libraries::get('li3_docs') + array('url' => '/docs', 'index' => null, 'categories' => null));
示例12: dirname
require dirname(__DIR__) . '/libraries/lessphp/lessc.inc.php';
/**
* TODO: Make sure, that subfolders are possible (currently not)
*
*/
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
if (strstr($params['request']->url, '.css')) {
// look for a matching less file
$basename = basename($params['request']->url);
$css_file = "less/{$basename}";
$less_file = "less/{$basename}.less";
if (file_exists($less_file)) {
header('Content-Type: text/css');
// if there's an up-to-date css file, serve it
if (file_exists($css_file) && filemtime($css_file) >= filemtime($less_file)) {
return file_get_contents($css_file);
}
try {
$less = new lessc($less_file);
$output = array('/**', ' * generated ' . date('r'), ' * by li3_less/lessphp', ' * ', ' * @link https://github.com/glaszig/li3_less', ' * @link http://leafo.net/lessphp', ' */');
$output = join(PHP_EOL, $output) . PHP_EOL . $less->parse();
} catch (Exception $e) {
header('Content-Type: text/css', true, 500);
$output = "/* less compiler exception: {$e->getMessage()} */";
}
file_put_contents("less/{$basename}", $output);
return $output;
}
}
return $chain->next($self, $params, $chain);
});
示例13: array
<?php
require 'bootstrap.php';
use lithium\net\http\Router;
use lithium\action\Dispatcher;
use lithium\action\Response;
Router::connect('/', array(), function ($request) {
$body = '<h1>Welcome to Sinatrium</h1>';
return new Response(compact('body'));
});
Router::connect('/hello/{:name}', array('name' => false), function ($request) {
$name = ucwords($request->name) ?: 'World';
$body = "<h1>Hello {$name}!</h1>";
return new Response(compact('body'));
});
echo Dispatcher::run(new lithium\action\Request());
示例14: define
<?php
/**
* radium: lithium application framework
*
* @copyright Copyright 2013, brünsicke.com GmbH (http://bruensicke.com)
* @license http://opensource.org/licenses/BSD-3-Clause The BSD License
*/
define('RADIUM_PATH', dirname(__DIR__));
require __DIR__ . '/bootstrap/media.php';
require __DIR__ . '/bootstrap/validators.php';
use radium\extensions\storage\FlashMessage;
use lithium\action\Dispatcher;
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
return FlashMessage::bindTo($chain->next($self, $params, $chain));
});
// use radium\models\BaseModel;
// if (!BaseModel::finder('random')) {
// BaseModel::finder('random', function($self, $params, $chain){
// $amount = $self::find('count', $params['options']);
// $offset = rand(0, $amount-1);
// $params['options']['offset'] = $offset;
// return $self::find('first', $params['options']);
// });
// }
示例15: function
* $posts = Post::find('all');
* return $posts->to('json');
* }}}
*/
use lithium\util\Collection;
Collection::formats('lithium\\net\\http\\Media');
/**
* This filter is a convenience method which allows you to automatically route requests for static
* assets stored within active plugins. For example, given a JavaScript file `bar.js` inside the
* `li3_foo` plugin installed in an application, requests to `http://app/path/li3_foo/js/bar.js`
* will be routed to `/path/to/app/libraries/plugins/li3_foo/webroot/js/bar.js` on the filesystem.
* In production, it is recommended that you disable this filter in favor of symlinking each
* plugin's `webroot` directory into your main application's `webroot` directory, or adding routing
* rules in your web server's configuration.
*/
use lithium\action\Dispatcher;
use lithium\action\Response;
use lithium\net\http\Media;
Dispatcher::applyFilter('_callable', function ($self, $params, $chain) {
list($library, $asset) = explode('/', $params['request']->url, 2) + array("", "");
if ($asset && ($path = Media::webroot($library)) && file_exists($file = "{$path}/{$asset}")) {
return function () use($file) {
$info = pathinfo($file);
$media = Media::type($info['extension']);
$content = (array) $media['content'];
return new Response(array('headers' => array('Content-type' => reset($content)), 'body' => file_get_contents($file)));
};
}
return $chain->next($self, $params, $chain);
});
Media::type('js', array('application/javascript', 'text/javascript'), array('view' => 'lithium\\template\\View', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php', 'element' => array('{:library}/views/elements/{:template}.{:type}.php', '{:library}/views/elements/{:template}.html.php'))));