<?php if (!file_exists($scabbiaLoader = __DIR__ . '/vendor/autoload.php')) { throw new RuntimeException('Unable to load Composer which is required for Scabbia Framework. Run `php scabbia update`.'); } $loader = (require $scabbiaLoader); if (defined('SCABBIA_PATH') && SCABBIA_PATH !== false) { $loader->set('Scabbia', SCABBIA_PATH); // } elseif (file_exists($scabbiaPath = __DIR__ . '/../scabbia-dev/src')) { // define('SCABBIA_PATH', $scabbiaPath); // $loader->set('Scabbia', $scabbiaPath); } use Scabbia\Framework; Framework::$development = true; // Framework::$disableCaches = true; Framework::load($loader); Framework::addApplication('App', 'application/'); Framework::run();
/** * 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); } }
/** * @ignore */ public function render($uAction, array $uParams, array $uInput) { $tActionName = $uAction; // strtr($uAction, '/', '_'); if ($tActionName === null || strlen($tActionName) <= 0) { $tActionName = $this->defaultAction; } $tFormat = substr($uInput['format'], 1); // @todo not sure on this // Framework::$responseFormat = $tFormat; if (isset($this->childControllers[$tActionName])) { if (count($uParams) > 0) { $tSubaction = array_shift($uParams); } else { $tSubaction = null; } $tInstance = new $this->childControllers[$tActionName](); return $tInstance->render($tSubaction, $uParams, $uInput); } $tMe = new \ReflectionClass($this); $tActionName2 = String::capitalizeEx($tActionName, '-', '', true); $tMethods = array($uInput['methodext'] . '_' . $tActionName2 . '_' . $tFormat, $uInput['methodext'] . '_' . $tActionName2, $uInput['methodext'] . '_otherwise' . '_' . $tFormat, $uInput['methodext'] . '_otherwise', $uInput['method'] . '_' . $tActionName2 . '_' . $tFormat, $uInput['method'] . '_' . $tActionName2, $uInput['method'] . '_otherwise' . '_' . $tFormat, $uInput['method'] . '_otherwise', $tActionName2 . '_' . $tFormat, 'otherwise' . '_' . $tFormat, $tActionName2, 'otherwise'); foreach ($tMethods as $tMethod) { if ($tMe->hasMethod($tMethod) && $tMe->getMethod($tMethod)->isPublic()) { Controllers::setController($this, $tActionName, $tFormat, $uParams, $uInput); $this->prerender->invoke(); $tReturn = call_user_func_array(array(&$this, $tMethod), $uParams); Framework::$responseFormat = $this->format; $this->postrender->invoke(); return $tReturn; } } return false; }
/** * 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); }
/** * @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]; }
/** * @ignore */ public static function sendRedirectPermanent($uLocation, $uTerminate = true) { self::sendStatus(301); header('Location: ' . $uLocation, true); if ($uTerminate) { Framework::end(0); } }