コード例 #1
0
 public static function getNavBarIfcs($menu)
 {
     $session = Session::singleton();
     $navBarIfcs = array();
     // Add public interfaces
     $interfaces = InterfaceObject::getPublicInterfaces();
     // Add interfaces for active roles
     foreach ($session->getActiveRoles() as $role) {
         $interfaces = array_merge($interfaces, $role->interfaces());
     }
     // Filter duplicate interfaces
     $interfaces = array_unique($interfaces);
     // Filter interfaces for requested part of navbar
     $interfaces = array_filter($interfaces, function ($ifc) use($menu) {
         switch ($menu) {
             case 'top':
                 if (($ifc->srcConcept->name == 'SESSION' || $ifc->srcConcept->name == 'ONE') && $ifc->crudR) {
                     return true;
                 } else {
                     return false;
                 }
             case 'new':
                 // crudC, otherwise the atom cannot be created
                 // isIdent (interface expr = I[Concept]), because otherwise a src atom is necesarry, which we don't have wiht +-menu
                 if ($ifc->crudC && $ifc->isIdent) {
                     return true;
                 } else {
                     return false;
                 }
             default:
                 throw new Exception("Cannot get navbar interfaces. Unknown menu: '{$menu}'", 500);
         }
     });
     // Create return object
     $result = array_map(function ($ifc) {
         return array('id' => $ifc->id, 'label' => $ifc->label, 'link' => '/' . $ifc->id);
     }, $interfaces);
     return array_values($result);
     // reindex array
 }
コード例 #2
0
<?php

use Ampersand\Config;
use Ampersand\Interfacing\InterfaceObject;
global $app;
$app->get('/interfaces', function () use($app) {
    if (Config::get('productionEnv')) {
        throw new Exception("List of all interfaces is not allowed in production environment", 403);
    }
    $content = InterfaceObject::getAllInterfaces();
    // Return all interfaces
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->get('/interfaces/public', function () use($app) {
    if (Config::get('productionEnv')) {
        throw new Exception("List of public interfaces is not allowed in production environment", 403);
    }
    $content = InterfaceObject::getPublicInterfaces();
    // Return all public interfaces
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
コード例 #3
0
ファイル: Session.php プロジェクト: AmpersandTarski/Ampersand
 /**
  * Constructor of Session class
  * private to prevent any outside instantiation of this object
  */
 private function __construct()
 {
     $this->logger = Logger::getLogger('FW');
     $this->database = Database::singleton();
     $conceptSession = Concept::getConceptByLabel('SESSION');
     // Also checks if 'SESSION' is defined as concept in Ampersand script
     $this->id = session_id();
     $this->sessionAtom = new Atom($this->id, $conceptSession);
     $this->logger->debug("Session id: {$this->id}");
     // Remove expired Ampersand sessions from __SessionTimeout__ and all concept tables and relations where it appears.
     $expiredSessionsAtoms = array_column((array) $this->database->Exe("SELECT SESSION FROM `__SessionTimeout__` WHERE `lastAccess` < " . (time() - Config::get('sessionExpirationTime'))), 'SESSION');
     foreach ($expiredSessionsAtoms as $expiredSessionAtom) {
         if ($expiredSessionAtom == $this->id) {
             // Notify user that session is expired when login functionality is enabled
             if (Config::get('loginEnabled')) {
                 Logger::getUserLogger()->warning("Your session has expired, please login again");
             }
             // 440 Login Timeout -> is redirected by frontend to login page
         }
         $this->destroyAmpersandSession($expiredSessionAtom);
     }
     // Create a new Ampersand session atom if not yet in SESSION table (browser started a new session or Ampersand session was expired)
     $sessionAtom = new Atom($this->id, $conceptSession);
     if (!$sessionAtom->atomExists()) {
         $sessionAtom->addAtom();
         $this->database->commitTransaction();
         //TODO: ook door Database->closeTransaction() laten doen, maar die verwijst terug naar Session class voor de checkrules. Oneindige loop
     }
     $this->database->Exe("INSERT INTO `__SessionTimeout__` (`SESSION`,`lastAccess`) VALUES ('" . $this->id . "', '" . time() . "') ON DUPLICATE KEY UPDATE `lastAccess` = '" . time() . "'");
     // Add public interfaces
     $this->accessibleInterfaces = InterfaceObject::getPublicInterfaces();
 }