Ejemplo n.º 1
0
 /**
  * Logs with an arbitrary level.
  *
  * @param string $uClass
  * @param mixed $uLevel
  * @param array $uContext
  * @return null
  */
 public static function write($uClass, $uLevel, array $uContext = array())
 {
     if (!isset($uContext['type'])) {
         $uContext['type'] = $uLevel === LogLevel::DEBUG || $uLevel === LogLevel::INFO ? 'log' : 'error';
     }
     self::$typeCounts[$uContext['type']]++;
     $uContext['class'] = $uClass;
     $uContext['category'] = $uLevel;
     $uContext['ip'] = $_SERVER['REMOTE_ADDR'];
     if (isset($uContext['message'])) {
         $uContext['message'] = String::prefixLines($uContext['message'], '- ', PHP_EOL);
     }
     if (isset($uContext['file'])) {
         if (Framework::$development) {
             $uContext['location'] = Io::extractPath($uContext['file']);
             if (isset($uContext['line'])) {
                 $uContext['location'] .= ' @' . $uContext['line'];
             }
         } else {
             $uContext['location'] = pathinfo($uContext['file'], PATHINFO_FILENAME);
         }
     } else {
         $uContext['location'] = '-';
     }
     $uContext['stackTrace'] = array();
     foreach (array_slice(debug_backtrace(), 2) as $tFrame) {
         $tArgs = array();
         /*
         if (isset($tFrame['args'])) {
             foreach ($tFrame['args'] as $tArg) {
                 $tArgs[] = var_export($tArg, true);
             }
         }
         */
         if (isset($tFrame['class'])) {
             $tFunction = $tFrame['class'] . $tFrame['type'] . $tFrame['function'];
         } else {
             $tFunction = $tFrame['function'];
         }
         if (isset($tFrame['file'])) {
             if (Framework::$development) {
                 $tLocation = Io::extractPath($tFrame['file']);
                 if (isset($tFrame['line'])) {
                     $tLocation .= ' @' . $tFrame['line'];
                 }
             } else {
                 $tLocation = pathinfo($tFrame['file'], PATHINFO_FILENAME);
             }
         } else {
             $tLocation = '-';
         }
         $uContext['stackTrace'][] = $tFunction . '(' . implode(', ', $tArgs) . ') in ' . $tLocation;
     }
     $uContext['eventDepth'] = Events::$eventDepth;
     Events::$disabled = true;
     if (!Framework::$readonly) {
         $tContent = '+ ' . String::format(Logger::$line, $uContext);
         $tFilename = Io::translatePath('{writable}logs/' . String::format(Logger::$filename, $uContext), true);
         Io::write($tFilename, $tContent, LOCK_EX | FILE_APPEND);
     }
     self::$console[] = $uContext;
     Events::$disabled = false;
     if (isset($uContext['halt']) && $uContext['halt']) {
         Events::invoke('reportError', $uContext);
         Framework::end(-1);
     }
 }
Ejemplo n.º 2
0
 /**
  * @ignore
  */
 public static function login($uForcePermissions = false, $uRedirectUrl = null)
 {
     $tResult = self::loginUrl($uForcePermissions, $uRedirectUrl);
     if (!$tResult[0] && $tResult[1] !== null) {
         header('Location: ' . $tResult[1], true);
         Framework::end(0);
     }
     return $tResult[0];
 }
Ejemplo n.º 3
0
 /**
  * Redirects users to another location if user does not have required roles
  *
  * @uses Auth::check($uRequiredRoles)
  * @param string $uRequiredRoles roles
  */
 public static function checkRedirect($uRequiredRoles = 'user')
 {
     self::load();
     if (self::check($uRequiredRoles)) {
         return;
     }
     $tLoginUrl = Config::get('auth/loginUrl', null);
     if ($tLoginUrl !== null) {
         //! todo: warning messages like insufficent privileges.
         Http::redirect($tLoginUrl, true);
     }
     Framework::end(0);
 }
Ejemplo n.º 4
0
 /**
  * @ignore
  */
 public static function sendRedirectPermanent($uLocation, $uTerminate = true)
 {
     self::sendStatus(301);
     header('Location: ' . $uLocation, true);
     if ($uTerminate) {
         Framework::end(0);
     }
 }