本文整理汇总了PHP中Application::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::get方法的具体用法?PHP Application::get怎么用?PHP Application::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Application
的用法示例。
在下文中一共展示了Application::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bootstrap
/**
* Bootstrap method to be called during application bootstrap stage.
*
* @param Application $app the application currently running
*/
public function bootstrap($app)
{
/** @var Module $module */
if ($app->hasModule('user') && ($module = $app->getModule('user')) instanceof Module) {
if (!isset($app->get('i18n')->translations['user*'])) {
$app->get('i18n')->translations['user*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
}
if ($app instanceof ConsoleApplication) {
$module->controllerNamespace = 'johnitvn\\userplus\\commands';
} else {
$module->controllerNamespace = 'johnitvn\\userplus\\controllers';
}
}
}
示例2: call_if_exists
/**
* Call a hook if it exists, fail silently if not
*
* @access public
* @param string $name
* @param array $arguments
* @return bool
*/
public static function call_if_exists($name, $arguments = [])
{
if (self::exists($name)) {
$application = Application::get();
$classname = 'Hook_' . ucfirst($application->name);
call_user_func_array([$classname, $name], $arguments);
}
}
示例3: auth
public function auth()
{
$client_id = $this->input->get('clent_id');
$application = new Application();
$application->client_id = $client_id;
$application->get();
if (!$application->exists()) {
$data['title'] = 'Auth Page';
$data['content'] = 'oauth/noapplication';
$this->load->view('master', $data);
} elseif (!$this->user_id) {
$redirect = 'users/login?redirect_url=oauth/auth?client_id=' . $application->id;
redirect($redirect);
} elseif ($this->input->post()) {
$allow = $this->input->post('allow');
if ($allow) {
$user = new User($this->user_id);
$existing_token = new Token();
$existing_token->where('user_id', $user->id);
$existing_token->where('application_id', $application->id);
$existing_token->get();
if ($existing_token->exists()) {
$existing_token->delete();
}
$token = $this->generate_token();
$token->save(array($application, $user));
die;
echo 'here';
}
} else {
$this->load->helper('form');
$data['application'] = array('id' => $application->id, 'name' => $application->name, 'client_id' => $application->client_id, 'client_secret' => $application->client_secret, 'redirect_url' => $application->redirect_url);
$data['title'] = 'Auth Page';
$data['content'] = 'oauth/authorize';
$this->load->view('master', $data);
}
}
示例4: coll
/**
* @param string $collection
* @return \MongoCollection
*/
public static function coll($collection)
{
return Application::get('mongodb')->selectCollection($collection);
}
示例5: parameters
/**
* Return all parameters, $_POST,$_GET and user parameters
* @return array - all parameters to the application
* @access public
* @static
*/
public static function parameters()
{
$ret = Application::post();
$ret = ArrayUtility::merge($ret, Application::get());
$ret = ArrayUtility::merge($ret, Session::getRegistered('userParams'));
return $ret;
}
示例6: detect
/**
* Detect
*
* @param string $hostname
* @param string $request_uri
* @access public
* @return Application $application
*/
public static function detect($hostname, $request_uri)
{
// If we already have a cached application, return that one
if (self::$application !== null) {
return Application::get();
}
// If multiple host headers have been set, use the last one
if (strpos($hostname, ', ') !== false) {
list($hostname, $discard) = array_reverse(explode(', ', $hostname));
}
// Find matching applications
$applications = self::get_all();
$matched_applications = [];
// Regular matches
foreach ($applications as $application) {
if (in_array($hostname, $application->config->hostnames)) {
$matched_applications[] = $application;
}
}
// If we don't have any matched applications, try to match wildcards
if (count($matched_applications) === 0) {
foreach ($applications as $application) {
$wildcard_hostnames = $application->config->hostnames;
foreach ($wildcard_hostnames as $key => $wildcard_hostname) {
if (strpos($wildcard_hostname, '*') === false) {
unset($wildcard_hostnames[$key]);
}
}
if (count($wildcard_hostnames) == 0) {
continue;
}
foreach ($wildcard_hostnames as $wildcard_hostname) {
if (fnmatch($wildcard_hostname, $hostname)) {
$matched_applications[] = $application;
}
}
}
}
// Set required variables in the matched Application objects
foreach ($matched_applications as $key => $application) {
// Set the relative request URI according to the application
if (isset($application->config->base_uri) and $application->config->base_uri !== '/') {
$application->request_relative_uri = str_replace($application->config->base_uri, '', $request_uri);
} else {
$application->request_relative_uri = $request_uri;
}
$application->hostname = $hostname;
$matched_applications[$key] = $application;
}
// Now that we have matching applications, see if one matches the
// request specifically. Otherwise, simply return the first one.
$matched_applications_sorted = [];
foreach ($matched_applications as $application) {
if (isset($application->config->base_uri)) {
// base_uri should not be empty, default to '/'
if ($application->config->base_uri == '') {
$application->config->base_uri = '/';
}
if (strpos($request_uri, $application->config->base_uri) === 0) {
$matched_applications_sorted[strlen($application->config->base_uri)] = $application;
}
} else {
$matched_applications_sorted[0] = $application;
}
}
// Sort the matched array by key, so the most specific one is at the end
ksort($matched_applications_sorted);
if (count($matched_applications_sorted) > 0) {
// Get the most specific one
$application = array_pop($matched_applications_sorted);
Application::set($application);
return Application::get();
}
throw new \Exception('No application found for ' . $hostname);
}
示例7: Application
<?php
namespace App;
require_once 'Application.php';
$app = new Application();
$data = [['id' => 4, 'age' => 15], ['id' => 3, 'age' => 28], ['id' => 8, 'age' => 3], ['id' => 1, 'age' => 23]];
// BEGIN (write your solution here)
$app->get('/', function ($params) use($data) {
if (array_key_exists('sort', $params)) {
list($key, $order) = split(' ', $params['sort']);
usort($data, function ($prev, $next) use($key, $order) {
$prevVal = $prev[$key];
$nextVal = $next[$key];
if ($prevVal == $nextVal) {
return 0;
}
if ($order == 'desc') {
return $prevVal < $nextVal ? 1 : -1;
} else {
if ($order == 'asc') {
return $prevVal > $nextVal ? 1 : -1;
}
}
});
}
return json_encode($data);
});
// END
$app->run();
示例8: any_handler
public function any_handler()
{
$this->template('any');
}
// Add a custom header
public function add_header()
{
echo '<h1>My custom header</h1>';
}
// Output a template
protected function template($template)
{
include dirname(__FILE__) . "/templates/{$template}.html";
}
}
// Create the instance
$app = new Application();
// Run a before filter
$app->before('get_info', 'add_header');
// Link up the urls
$app->get('', 'get_index');
$app->get('info', 'get_info');
$app->get('json', 'get_json');
$app->get('xml', 'get_xml');
$app->get('redirect', 'get_redirect');
$app->get('page/<page>', 'get_page');
$app->any('any', 'any_handler');
$app->get('page/<page:\\d{4}>/<id>', 'get_page');
$app->get('page/<page:.*>', 'get_page');
// Run the application
$app->run();
示例9: translate
/**
* Translate a string
*
* @access public
* @return string $translated_string
* @param string $string
*/
public static function translate($string, Translation $translation = null)
{
if ($translation !== null) {
$translation = self::get($translation->language, $translation->application_name);
} else {
$translation = self::get(\Application::get()->language, \Application::get()->name);
}
return $translation->translate_string($string);
}
示例10: rewrite_reverse_routes
/**
* Do a reverse rewrite of a link
*
* @access private
* @param string $url_raw
* @return string $reverse_rewrite
*/
private static function rewrite_reverse_routes($url_raw)
{
$url = parse_url($url_raw);
$params = [];
$application = \Skeleton\Core\Application::Get();
$routes = $application->config->routes;
if (isset($url['query'])) {
// Allow & instead of &
$url['query'] = str_replace('&', '&', $url['query']);
parse_str($url['query'], $params);
}
/**
* Add language to the known parameters
*/
if (isset($application->language) and !isset($params['language'])) {
$params['language'] = $application->language->name_short;
}
/**
* Search for the requested module
*/
if (!isset($url['path'])) {
return $url_raw;
}
if ($url['path'] != '' and $url['path'][0] == '/') {
$url['path'] = substr($url['path'], 1);
}
$module_name = null;
/**
* Check skeleton packages
*/
$packages = \Skeleton\Core\Package::get_all();
foreach ($packages as $package) {
$parts = explode('/', $url['path']);
if (isset($parts[0]) and $parts[0] == $package->name) {
unset($parts[0]);
$package_parts = explode('-', str_replace('skeleton-package-', '', $package->name));
foreach ($package_parts as $key => $package_part) {
$package_parts[$key] = ucfirst($package_part);
}
$module_name = '\\Skeleton\\Package\\' . implode('\\', $package_parts) . '\\Web\\Module\\' . str_replace('_', '\\', implode('/', $parts));
}
}
if ($module_name === null) {
$module_name = 'web_module_' . str_replace('/', '_', $url['path']);
}
$module_defined = false;
$package_module = false;
if (isset($routes[$module_name])) {
$module_defined = true;
} elseif (isset($routes[$module_name . '_index'])) {
$module_name = $module_name . '_index';
$module_defined = true;
} else {
foreach ($routes as $classname => $dummy) {
$application = Application::get();
$module_filename = str_replace('web_module_', '', $classname);
$filename_parts = explode('_', $module_filename);
$module_filename = '';
foreach ($filename_parts as $filename_part) {
$module_filename .= '/' . strtolower($filename_part);
}
$module_filename .= '.php';
$module_filename = $application->module_path . $module_filename;
if (file_exists($module_filename) and !class_exists($classname)) {
require_once $module_filename;
}
if (class_exists($classname) and (strtolower(get_parent_class($classname)) == strtolower($module_name) or is_subclass_of($classname, $module_name))) {
$module_name = strtolower($classname);
$module_defined = true;
$package_module = true;
}
}
}
if (!$module_defined) {
return $url_raw;
}
$routes = $routes[$module_name];
$correct_route = null;
foreach ($routes as $route) {
$route_parts = explode('/', $route);
$route_part_matches = 0;
foreach ($route_parts as $key => $route_part) {
if (trim($route_part) == '') {
unset($route_parts[$key]);
continue;
}
if ($route_part[0] != '$') {
$route_part_matches++;
continue;
}
/**
* $language[en,nl] => language[en,nl]
*/
//.........这里部分代码省略.........
示例11: getCreate
<?php
include '../lib/soprano.php';
class Application extends Soprano
{
public function getCreate()
{
$hangman = Factory::build('Hangman', 'new');
$this->template->hangman = $hangman;
$this->template->render('create');
}
public function getGuess($letter)
{
$hangman = Factory::build('Hangman');
$this->template->hangman = $hangman;
if ($hangman->guess(strtoupper($letter))) {
$this->template->render('winner');
}
$this->template->render('guess');
}
}
$app = new Application();
$app->get('/', 'getCreate');
$app->get('/create', 'getCreate');
$app->get('/guess/:letter', 'getGuess');
$app->run();
示例12: testAfterApplicationFiltersShouldBeCalledAfterRouteExecution
public function testAfterApplicationFiltersShouldBeCalledAfterRouteExecution()
{
$app = new Application();
$app->get('/test', function (Response $response) {
$response->appendContents('route');
});
$app->after(function (Response $response) {
$response->appendContents('after1');
});
$app->after(function (Response $response) {
$response->appendContents('after2');
});
$response = new ResponseMock();
$app->run(Request::create(false, 'localhost', '/test'), $response);
$this->assertEquals('routeafter1after2', $response->contents());
}
示例13: trans
/**
* @param string $id
* @param array $parameters
* @return string
*/
public static function trans($id, $parameters = [])
{
return Application::get('i18n')->trans($id, $parameters);
}
示例14: getClientInfo
/**
* @return array
*/
public static function getClientInfo()
{
return ['ip' => Application::get('request')->getClientIp(), 'userAgent' => Application::get('request')->getUserAgent()];
}
示例15: hello
<?php
/**
* Pico Web Application Framework Sample
* @package Picowa
* @since 2010-04-09
*/
class Application extends Picowa
{
function hello()
{
$name = $this->args->name;
return "Hello {$name}!\n";
}
}
$app = new Application();
$app->get('/:name', $app->_hello(), array('name' => '.*'));
$app->init()->run();