/** * Initialize class * * @param string $basepath */ public function __construct($basepath) { if (class_exists(\Luba\ExceptionHandler::class)) { set_exception_handler([new \Luba\ExceptionHandler(), 'handle']); set_error_handler([new \Luba\ErrorHandler(), 'handle']); } else { set_exception_handler([$this, 'handleException']); } self::setInstance($this); $this->basePath = $basepath; parent::__construct(); $this->request = new Request(); $this->url = new URL(); $this->input = new Input(); $this->router = new Router\Router(); Session::start(); }
public function validateToken() { $sToken = Session::get('__formtoken'); $fToken = Input::post('_token'); if ($fToken) { if ($fToken == $sToken) { return true; } } $this->passed = false; $this->errors['_token'] = $this->getErrorMessage('tokenMismatch'); Session::remove('__formtoken'); }
public static function user() { return Session::get('__auth_user'); }
/** * Render the form * * @return View */ public function render() { $this->makeTokenField(); $rendered = []; $attributes = $this->renderAttributes($this->attributes); $files = $this->files ? "enctype=\"multipart/form-data\"" : ""; $method = "method=\"{$this->method}\""; $action = "action=\"{$this->action}\""; $fields = []; $formtemplate = file_exists($this->templates . 'form.lb') ? $this->templates : __DIR__ . '/templates/'; $formfieldtemplate = file_exists($this->templates . 'formfield.lb') ? $this->templates : __DIR__ . '/templates/'; foreach ($this->fields as $field) { if (is_string($field)) { $rendered[] = $field; continue; } $arr = $field->render(); $session =& Session::get('__formerrors')[$field->getName()]; $error = is_null(Session::get("__formerrors")) ? NULL : isset($session) ? $session : NULL; $fields[] = (new View('formfield', ['label' => $arr['label'], 'field' => $arr['field'], 'error' => $error], $formfieldtemplate))->render(); } $template = new View('form', compact('method', 'action', 'files', 'attributes', 'fields'), $formtemplate); Session::remove('__formerrors'); return $template; }