本文整理汇总了PHP中State::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP State::instance方法的具体用法?PHP State::instance怎么用?PHP State::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_index
/**
* Default action in default controller
*/
public function action_index()
{
// get acl
$acl = Acl::instance();
// get first allowed module
// get modules
$modules = Settings::factory('modules')->as_array();
$modules = array_keys($modules);
$module = State::instance()->get('active.module');
if ($module !== FALSE && $module !== 'Default') {
if ($acl->allowed($module, 'access', FALSE, $this->_website) === TRUE) {
$url = URL::to($module, array('website' => $this->_website));
$this->redirect($url);
exit;
}
}
// find the first allowed module & redirect
foreach ($modules as $module) {
if ($acl->allowed($module, 'access', FALSE, $this->_website) === TRUE) {
$url = URL::to($module, array('website' => $this->_website));
$this->redirect($url);
exit;
}
}
}
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:28,代码来源:Default.php
示例2: can
/**
* Perform a permissions check
*
* @param string $action action label (e.g. 'read')
* @param string $context_path context regex (in perm_contexts)
* @param string $cabin (defaults to current cabin)
* @param integer $user_id (defaults to current user)
* @return boolean
*/
public function can(string $action, string $context_path = '', string $cabin = \CABIN_NAME, int $user_id = 0) : bool
{
$state = State::instance();
if (empty($cabin)) {
$cabin = \CABIN_NAME;
}
// If you don't specify the user ID to check, it will use the current
// user ID instead, by default.
if (empty($user_id)) {
if (!empty($_SESSION['userid'])) {
$user_id = (int) $_SESSION['userid'];
}
}
// If you're a super-user, the answer is "yes, yes you can".
if ($this->isSuperUser($user_id)) {
return true;
}
$allowed = false;
$failed_one = false;
// Get all applicable contexts
$contexts = self::getOverlap($context_path, $cabin);
if (empty($contexts)) {
// Sane default: In the absence of permissions, return false
return false;
}
if ($user_id > 0) {
// You need to be allowed in every relevant context.
foreach ($contexts as $c_id) {
if (self::checkUser($action, $c_id, $user_id) || self::checkUsersGroups($action, $c_id, $user_id)) {
$allowed = true;
} else {
$failed_one = true;
}
}
} else {
if (!$state->universal['guest_groups']) {
return false;
}
// Guests can be assigned to groups. This fails closed if they aren't given any.
foreach ($contexts as $c_id) {
$ctx_res = false;
foreach ($state->universal['guest_groups'] as $grp) {
if (self::checkGroup($action, $c_id, $grp)) {
$ctx_res = true;
}
}
if ($ctx_res) {
$allowed = true;
} else {
$failed_one = true;
}
}
}
// We return true if we were allowed at least once and we did not fail
// in one of the overlapping contexts
return $allowed && !$failed_one;
}
示例3: airshipLand
/**
* This function is called after the dependencies have been injected by
* AutoPilot. Think of it as a user-land constructor.
*/
public function airshipLand()
{
parent::airshipLand();
$state = State::instance();
$cabin_names = [];
foreach ($state->cabins as $c) {
$cabin_names[] = $c['name'];
}
$this->airship_lens_object->store('state', ['cabins' => $state->cabins, 'cabin_names' => $cabin_names, 'manifest' => $state->manifest]);
}
示例4: __construct
/**
* AirBrake constructor.
* @param Database|null $db
* @param array $config
*/
public function __construct(Database $db = null, array $config = [])
{
if (!$db) {
$db = \Airship\get_database();
}
if (empty($config)) {
$state = State::instance();
$config = $state->universal['rate-limiting'];
}
$this->db = $db;
$this->config = $config;
}
示例5: getCabinNameFromURL
/**
* Given a URL, return the cabin name that applies to it;
* otherwise, throw a CabinNotFound exception.
*
* @param string $url
* @return string
* @throws CabinNotFound
*/
public function getCabinNameFromURL(string $url) : string
{
$state = State::instance();
/**
* @var AutoPilot
*/
$ap = $state->autoPilot;
$cabin = $ap->testCabinForUrl($url);
if (empty($cabin)) {
throw new CabinNotFound();
}
return $cabin;
}
示例6: __construct
/**
* Installer constructor.
*
* @param Hail|null $hail
* @param string $supplier
* @param string $package
*/
public function __construct(Hail $hail = null, string $supplier = '', string $package = '')
{
$config = State::instance();
if (empty($hail)) {
$this->hail = $config->hail;
} else {
$this->hail = $hail;
}
$this->supplier = $this->getSupplierDontCache($supplier);
$this->package = $package;
if (!self::$continuumLogger) {
self::$continuumLogger = new Log();
}
}
示例7: __construct
/**
* SharedMemory constructor
*.
* @param Key|null $cacheKey
* @param AuthenticationKey|null $authKey
* @param string $personalization
*/
public function __construct(Key $cacheKey = null, AuthenticationKey $authKey = null, string $personalization = '')
{
if (!$cacheKey) {
$state = State::instance();
$cacheKey = $state->keyring['cache.hash_key'];
}
// We need a short hash key:
$this->cacheKeyL = CryptoUtil::safeSubstr($cacheKey->getRawKeyMaterial(), 0, \Sodium\CRYPTO_SHORTHASH_KEYBYTES);
$this->cacheKeyR = CryptoUtil::safeSubstr($cacheKey->getRawKeyMaterial(), \Sodium\CRYPTO_SHORTHASH_KEYBYTES, \Sodium\CRYPTO_SHORTHASH_KEYBYTES);
if ($authKey) {
$this->authKey = $authKey;
}
$this->personalization = $personalization;
}
示例8: autoUpdate
/**
* Process automatic updates:
*
* 1. Check if a new update is available.
* 2. Download the upload file, store in a temporary file.
* 3. Verify the signature (via Halite).
* 4. Verify the update is recorded in Keyggdrasil.
* 5. If all is well, run the update script.
*/
public function autoUpdate()
{
$state = State::instance();
try {
/**
* @var UpdateInfo[]
*/
$updateInfoArray = $this->updateCheck($state->universal['airship']['trusted-supplier'], $this->name, \AIRSHIP_VERSION, 'airship_version');
/**
* Let's iterate through every possible available update,
* until we find the desired version.
*/
foreach ($updateInfoArray as $updateInfo) {
if (!$this->checkVersionSettings($updateInfo, \AIRSHIP_VERSION)) {
// This is not the update we are looking for.
$this->log('Skipping update', LogLevel::DEBUG, ['info' => $updateInfo->getResponse(), 'new_version' => $updateInfo->getVersion(), 'current_version' => \AIRSHIP_VERSION]);
continue;
}
/**
* @var UpdateFile
*/
$updateFile = $this->downloadUpdateFile($updateInfo, 'airship_download');
if ($this->bypassSecurityAndJustInstall) {
// I'm sorry, Dave. I'm afraid I can't do that.
$this->log('Core update verification cannot be bypassed', LogLevel::ERROR);
self::$continuumLogger->store(LogLevel::ALERT, 'CMS Airship core update - security bypass ignored.', $this->getLogContext($updateInfo, $updateFile));
}
/**
* Don't proceed unless we've verified the signatures
*/
if ($this->verifyUpdateSignature($updateInfo, $updateFile)) {
if ($this->checkKeyggdrasil($updateInfo, $updateFile)) {
$this->install($updateInfo, $updateFile);
} else {
$this->log('Keyggdrasil check failed for Airship core update', LogLevel::ALERT);
self::$continuumLogger->store(LogLevel::ALERT, 'CMS Airship core update failed -- checksum not registered in Keyggdrasil', $this->getLogContext($updateInfo, $updateFile));
}
} else {
$this->log('Invalid signature for this Airship core update', LogLevel::ALERT);
self::$continuumLogger->store(LogLevel::ALERT, 'CMS Airship core update failed -- invalid signature', $this->getLogContext($updateInfo, $updateFile));
}
}
} catch (NoAPIResponse $ex) {
// We should log this.
$this->log('Automatic update failure: NO API Response.', LogLevel::ERROR, \Airship\throwableToArray($ex));
self::$continuumLogger->store(LogLevel::ALERT, 'CMS Airship core update failed -- no API Response', ['action' => 'UPDATE', 'name' => $this->name, 'supplier' => $this->supplier->getName(), 'type' => $this->type]);
}
}
示例9: after
/**
* after handler
*/
public function after()
{
// store active module in State
State::instance()->set('active.module', $this->_controller);
}
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:8,代码来源:Base.php
示例10: action_update
/**
* update
*/
public function action_update()
{
// get id
$id = $this->param('id');
// create new model
$model = ORM::factory($this->_settings->get('model'), $id);
// add item to navigation
Viewer::instance('Navigation')->item($model);
// create form
$form = Form::factory($this->_settings->get('form'));
// add request to form
$form->request($this->request);
// add text to form
$form->text(Text::instance());
// add alias settings to form
$form->alias($this->_settings->get('alias.global') ? 'multiple' : ($this->_settings->get('alias.module') ? 'single' : FALSE));
// add model to form
$form->model($model);
// get viewport
$viewport = $this->request->param('viewport');
// add urls
if ($viewport === 'item') {
// urls when directly updating in a dialog
$form->urls(array('submit' => URL::to($this->request->controller() . '@update:' . $id, array('query' => 'after=update')), 'submit_back' => URL::to($this->request->controller() . '@update:' . $id, array('query' => 'after=close')), 'back' => URL::to($this->request->controller() . '@close'), 'preview' => URL::to($this->request->controller() . '@preview:' . $id)));
} else {
// default urls
$url_back = State::instance()->get('url.back', FALSE);
State::instance()->set('url.back', FALSE);
$form->urls(array('submit' => URL::to($this->request->controller() . '@update:' . $id, array('query' => 'after=update')), 'submit_back' => URL::to($this->request->controller() . '@update:' . $id), 'back' => $url_back ? $url_back : URL::to($this->request->controller()), 'preview' => URL::to($this->request->controller() . '@preview:' . $id)));
}
// raise event
Event::raise($this, Event::AFTER_UPDATE_FORM, array('form' => $form, 'model' => $model));
// do the action
if ($this->update($model, $form)) {
// get after
if ($this->request->query('after') === 'update') {
$params = array('controller' => $this->request->controller(), 'action' => 'update', 'id' => $id);
} elseif ($this->request->query('after') === 'close') {
$params = array('controller' => $this->request->controller(), 'action' => 'close', 'id' => $id);
} else {
$params = array();
}
//redirect
$this->redirect_done('updated', $params);
}
}
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:49,代码来源:Item.php
示例11: isAirshipSpecialCabin
/**
* Is this cabin part of the Airship core? (They don't
* get automatically updated separate from the core.)
*
* @return bool
*/
protected function isAirshipSpecialCabin() : bool
{
$state = State::instance();
return $this->supplier->getName() === $state->universal['airship']['trusted-supplier'] && \in_array($this->name, self::AIRSHIP_SPECIAL_CABINS);
}
示例12: notaryDiscovery
/**
* Discover a new notary, grab its public key, channels, and URL
*
* @param string $url
* @return array
*/
protected function notaryDiscovery(string $url) : array
{
$state = State::instance();
if (IDE_HACKS) {
$state->hail = new Hail(new Client());
}
$body = $state->hail->getReturnBody($url);
$pos = \strpos($body, '<meta name="airship-notary" content="');
if ($pos === false) {
// Notary not enabled:
return [];
}
$body = Util::subString($body, $pos + 37);
$end = \strpos($body, '"');
if (!$end) {
// Invalid
return [];
}
$tag = \explode('; ', Util::subString($body, 0, $end));
$channel = null;
$notary_url = null;
foreach ($tag as $t) {
list($k, $v) = \explode('=', $t);
if ($k === 'channel') {
$channel = $v;
} elseif ($k === 'url') {
$notary_url = $v;
}
}
return ['public_key' => $tag[0], 'channel' => $channel, 'url' => $notary_url];
}
示例13: user_motif
/**
* Get the user's selected Motif
*
* @param int|null $userId
* @param string $cabin
* @return array
*/
function user_motif(int $userId = null, string $cabin = \CABIN_NAME) : array
{
static $userCache = [];
$state = State::instance();
if (\count($state->motifs) === 0) {
return [];
}
if (empty($userId)) {
$userId = \Airship\LensFunctions\userid();
if (empty($userId)) {
$k = \array_keys($state->motifs)[0];
return $state->motifs[$k] ?? [];
}
}
// Did we cache these preferences?
if (isset($userCache[$userId])) {
return $state->motifs[$userCache[$userId]];
}
$db = \Airship\get_database();
$userPrefs = $db->cell('SELECT preferences FROM airship_user_preferences WHERE userid = ?', $userId);
if (empty($userPrefs)) {
// Default
$k = \array_keys($state->motifs)[0];
$userCache[$userId] = $k;
return $state->motifs[$k] ?? [];
}
$userPrefs = \Airship\parseJSON($userPrefs, true);
if (isset($userPrefs['motif'][$cabin])) {
$split = \explode('/', $userPrefs['motif'][$cabin]);
foreach ($state->motifs as $k => $motif) {
if (empty($motif['config'])) {
continue;
}
if ($motif['supplier'] === $split[0] && $motif['name'] === $split[1]) {
// We've found a match:
$userCache[$userId] = $k;
return $state->motifs[$k];
}
}
}
// When all else fails, go with the first one
$k = \array_keys($state->motifs)[0];
$userCache[$userId] = $k;
return $state->motifs[$k] ?? [];
}
示例14: generateUniqueId
/**
* Generate a unique random public ID for this user, which is distinct from the username they use to log in.
*
* @return string
*/
protected function generateUniqueId() : string
{
$unique = '';
$query = 'SELECT count(*) FROM airship_users WHERE uniqueid = ?';
do {
if (!empty($unique)) {
// This will probably never be executed. It will be a nice easter egg if it ever does.
$state = State::instance();
$state->logger->log(LogLevel::ALERT, "A unique user ID collision occurred. This should never happen. (There are 2^192 possible values," . "which has approximately a 50% chance of a single collision occurring after 2^96 users," . "and the database can only hold 2^64). This means you're either extremely lucky or your CSPRNG " . "is broken. We hope it's luck. Airship is clever enough to try again and not fail " . "(so don't worry), but we wanted to make sure you were aware.", ['colliding_random_id' => $unique]);
}
$unique = \Airship\uniqueId();
} while ($this->db->exists($query, $unique));
return $unique;
}
示例15: detectCollisions
/**
* Find probable collisions between patterns and cabin names, as well as hard-coded paths
* in the current cabin. It does NOT look for collisions in custom pages, nor in page collisions
* in foreign Cabins (outside of the Cabin itself).
*
* @param string $uri
* @param string $cabin
* @return bool
* @throws \Airship\Alerts\GearNotFound
* @throws \TypeError
*/
protected function detectCollisions(string $uri, string $cabin) : bool
{
$state = State::instance();
$ap = Gears::getName('AutoPilot');
if (!$ap instanceof AutoPilot) {
throw new \TypeError(\__('AutoPilot Blueprint'));
}
$nop = [];
foreach ($state->cabins as $pattern => $cab) {
if ($cab === $cabin) {
// Let's check each existing route in the current cabin for a collision
foreach ($cab['data']['routes'] as $route => $landing) {
$test = $ap::testLanding($ap::$patternPrefix . $route . '$', $uri, $nop, true);
if ($test) {
return true;
}
}
} else {
// Let's check each cabin route for a pattern
$test = $ap::testLanding($ap::$patternPrefix . $pattern, $uri, $nop, true);
if ($test) {
return true;
}
}
}
return \preg_match('#^(static|js|img|fonts|css)/#', $uri) === 0;
}