Exemple #1
0
 public function __invoke(array $record)
 {
     if ($record['level'] < $this->level) {
         return $record;
     }
     // pid indicates a background process
     $pid = Process::get('pid');
     if ($pid) {
         $record['extra']['pid'] = $pid;
     }
     return $record;
 }
Exemple #2
0
 public function __invoke(array $record)
 {
     if ($record['level'] < $this->level) {
         return $record;
     }
     if (Session::current()) {
         $record['extra']['user'] = (int) Session::current('UserID');
     } else {
         if (is_numeric(@Process::get('type'))) {
             $record['extra']['user'] = (int) Process::get('type');
         }
     }
     return $record;
 }
 public function resolve(Request $req, Response $res)
 {
     $req->user = new User();
     // User from CLI
     switch ($req->client('type')) {
         case 'cli':
             // Retrieve user context from process data, then CLI argument.
             $userId = (int) Process::get('type');
             if (!$userId) {
                 $req->cli()->options('u', array('alias' => 'user', 'type' => 'integer', 'describe' => 'Idenitfier of target context user.'));
                 $userId = (int) $req->meta('user');
             }
             if ($userId) {
                 $req->user->load($userId);
             }
             unset($userId);
             break;
         default:
             // Session ID provided, validate it.
             $sid = $req->meta('sid');
             if ($sid) {
                 $ret = Session::ensure($sid, $req->meta('token'), $req->fingerprint());
                 // Session doesn't exist, delete the cookie.
                 if ($ret === false || $ret === Session::ERR_EXPIRED) {
                     $res->cookie('__sid', '', time() - 3600);
                 } else {
                     if (is_integer($ret)) {
                         switch ($ret) {
                             // note: System should treat as public user.
                             case Session::ERR_INVALID:
                                 break;
                         }
                     } else {
                         // Success, proceed.
                         $req->user->load(Session::current('username'));
                         unset($req->user->password);
                     }
                 }
             } else {
                 if ($this->setupSession && !@\core\Node::get('User')) {
                     $req->user->data(['id' => 0, 'groups' => ['Administrators'], 'username' => '__default']);
                 }
             }
             break;
     }
 }