当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::request方法代码示例

本文整理汇总了PHP中Pagekit\Application::request方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::request方法的具体用法?PHP Application::request怎么用?PHP Application::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pagekit\Application的用法示例。


在下文中一共展示了Application::request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveAction

 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"submission": "array", "id": "int", "g-recaptcha-response": "string"}, csrf=true)
  */
 public function saveAction($data, $id = 0, $gRecaptchaResponse = '')
 {
     if (!($submission = Submission::find($id))) {
         $submission = Submission::create();
         unset($data['id']);
         $submission->form_id = $data['form_id'];
         $submission->created = new \DateTime();
         $submission->ip = App::request()->getClientIp();
     }
     unset($data['created']);
     if (!($form = Form::find($submission->form_id))) {
         App::abort(404, 'Form not found.');
     }
     $submission->form = $form;
     if ($form->get('recaptcha') && $id == 0) {
         $resp = (new ReCaptcha(App::module('formmaker')->config('recaptha_secret_key')))->verify($gRecaptchaResponse, App::request()->server->get('REMOTE_ADDR'));
         if (!$resp->isSuccess()) {
             $errors = $resp->getErrorCodes();
             App::abort(403, $errors[0]);
         }
     }
     $submission->save($data);
     $submission->email = $submission->getUserEmail();
     if ($id == 0 && $submission->email) {
         try {
             (new MailHelper($submission))->sendMail();
             $submission->save();
         } catch (Exception $e) {
             App::abort(400, $e->getMessage());
         }
     }
     return ['message' => 'Submission successfull', 'submission' => $submission];
 }
开发者ID:4nxiety,项目名称:pagekit-formmaker,代码行数:38,代码来源:SubmissionApiController.php

示例2: confirmAction

 /**
  * @Request({"user", "key"})
  */
 public function confirmAction($username = "", $activation = "")
 {
     if (empty($username) || empty($activation) || !($user = User::where(compact('username', 'activation'))->first())) {
         return $this->messageView(__('Invalid key.'), $success = false);
     }
     if ($user->isBlocked()) {
         return $this->messageView(__('Your account has not been activated or is blocked.'), $success = false);
     }
     $error = '';
     if ('POST' === App::request()->getMethod()) {
         try {
             if (!App::csrf()->validate()) {
                 throw new Exception(__('Invalid token. Please try again.'));
             }
             $password = App::request()->request->get('password');
             if (empty($password)) {
                 throw new Exception(__('Enter password.'));
             }
             if ($password != trim($password)) {
                 throw new Exception(__('Invalid password.'));
             }
             $user->password = App::get('auth.password')->hash($password);
             $user->activation = null;
             $user->save();
             App::message()->success(__('Your password has been reset.'));
             return App::redirect('@user/login');
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     return ['$view' => ['title' => __('Reset Confirm'), 'name' => 'system/user/reset-confirm.php'], 'username' => $username, 'activation' => $activation, 'error' => $error];
 }
开发者ID:nstaeger,项目名称:pagekit,代码行数:35,代码来源:ResetPasswordController.php

示例3: authenticateAction

 /**
  * @Route(methods="POST", defaults={"_maintenance" = true})
  * @Request({"credentials": "array", "remember_me": "boolean", "redirect": "string"})
  */
 public function authenticateAction($credentials, $remember = false, $redirect = '')
 {
     try {
         if (!App::csrf()->validate()) {
             throw new CsrfException(__('Invalid token. Please try again.'));
         }
         App::auth()->authorize($user = App::auth()->authenticate($credentials, false));
         if (($event = App::auth()->login($user, $remember)) && $event->hasResponse()) {
             return $event->getResponse();
         }
         if (App::request()->isXmlHttpRequest()) {
             return App::response()->json(['csrf' => App::csrf()->generate()]);
         } else {
             return App::redirect(preg_replace('#(https?:)?//[^/]+#', '', $redirect));
         }
     } catch (CsrfException $e) {
         if (App::request()->isXmlHttpRequest()) {
             return App::response()->json(['csrf' => App::csrf()->generate()], 401);
         }
         $error = $e->getMessage();
     } catch (BadCredentialsException $e) {
         $error = __('Invalid username or password.');
     } catch (AuthException $e) {
         $error = $e->getMessage();
     }
     if (App::request()->isXmlHttpRequest()) {
         App::abort(401, $error);
     } else {
         App::message()->error($error);
         return App::redirect(preg_replace('#(https?:)?//[^/]+#', '', App::url()->previous()));
     }
 }
开发者ID:nstaeger,项目名称:pagekit,代码行数:36,代码来源:AuthController.php

示例4: authenticateAction

 /**
  * @Route(methods="POST", defaults={"_maintenance" = true})
  * @Request({"credentials": "array", "_remember_me": "boolean"})
  */
 public function authenticateAction($credentials, $remember = false)
 {
     $isXml = App::request()->isXmlHttpRequest();
     try {
         if (!App::csrf()->validate()) {
             throw new AuthException(__('Invalid token. Please try again.'));
         }
         App::auth()->authorize($user = App::auth()->authenticate($credentials, false));
         if (!$isXml) {
             return App::auth()->login($user, $remember);
         } else {
             App::auth()->setUser($user, $remember);
             return ['success' => true];
         }
     } catch (BadCredentialsException $e) {
         $error = __('Invalid username or password.');
     } catch (AuthException $e) {
         $error = $e->getMessage();
     }
     if (!$isXml) {
         App::message()->error($error);
         return App::redirect(App::url()->previous());
     } else {
         App::abort(400, $error);
     }
 }
开发者ID:aqnouch,项目名称:rimbo,代码行数:30,代码来源:AuthController.php

示例5: uploadAction

 /**
  * @param FieldValueBase $fieldValue
  * @return array
  */
 public function uploadAction(FieldValueBase $fieldValue)
 {
     try {
         if (!($path = $this->getPath($fieldValue->field->get('path')))) {
             return $this->error(__('Invalid path.'));
         }
         if (!is_dir($path) || !App::user()->hasAccess('system: manage storage | bixframework: upload files')) {
             return $this->error(__('Permission denied.'));
         }
         $fileInfo = [];
         $files = App::request()->files->get('files');
         if (!$files) {
             return $this->error(__('No files uploaded.'));
         }
         /** @var UploadedFile $file */
         foreach ($files as $file) {
             if (!$file->isValid()) {
                 return $this->error(sprintf(__('Uploaded file invalid. (%s)'), $file->getErrorMessage()));
             }
             if (!($ext = $file->guessExtension()) or !in_array($ext, $fieldValue->field->get('allowed', []))) {
                 return $this->error(__('File extension not allowed.'));
             }
             if (!($size = $file->getClientSize()) or $size > $fieldValue->field->get('max_size', 0) * 1024 * 1024) {
                 return $this->error(__('File is too large.'));
             }
             //give file unique name
             $localFile = $file->move($path, sprintf('%d%d-%s', microtime(true) * 10000, rand(), preg_replace("/[^a-zA-Z0-9\\.]/", "-", $file->getClientOriginalName())));
             $fileInfo[] = ['name' => $file->getClientOriginalName(), 'size' => $localFile->getSize(), 'path' => str_replace(App::path(), '', $localFile->getPathname()), 'url' => ltrim(App::url()->getStatic($localFile->getPathname(), [], 'base'), '/')];
         }
         return ['message' => __('Upload complete.'), 'files' => $fileInfo];
     } catch (\Exception $e) {
         return $this->error(__('Unable to upload.'));
     }
 }
开发者ID:stroborobo,项目名称:pagekit-framework,代码行数:38,代码来源:UploadFieldType.php

示例6: loginAction

 /**
  * @Route("/admin/login", defaults={"_maintenance"=true})
  */
 public function loginAction()
 {
     if (App::user()->isAuthenticated()) {
         return App::redirect('@system');
     }
     return ['$view' => ['title' => __('Login'), 'name' => 'system/theme:views/login.php', 'layout' => false], 'last_username' => App::session()->get(Auth::LAST_USERNAME), 'redirect' => App::request()->get('redirect') ?: App::url('@system', [], true), 'remember_me_param' => Auth::REMEMBER_ME_PARAM];
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:10,代码来源:AdminController.php

示例7: saveAction

 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"submission": "array", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $id = 0)
 {
     if (!($submission = Submission::find($id))) {
         $submission = Submission::create();
         unset($data['id']);
         $submission->form_id = $data['form_id'];
         $submission->created = new \DateTime();
         $submission->ip = App::request()->getClientIp();
     }
     unset($data['created']);
     if (!($form = Form::find($submission->form_id))) {
         App::abort(404, 'Form not found.');
     }
     $submission->form = $form;
     $submission->save($data);
     $submission->email = $submission->getUserEmail();
     if ($id == 0 && $submission->email) {
         try {
             (new MailHelper($submission))->sendMail();
             $submission->save();
         } catch (Exception $e) {
             App::abort(400, $e->getMessage());
         }
     }
     return ['message' => 'Submission successfull', 'submission' => $submission];
 }
开发者ID:nagyistoce,项目名称:pagekit-formmaker,代码行数:31,代码来源:SubmissionApiController.php

示例8: viewAction

 /**
  * @Route("/{id}", name="view", requirements={"id"="\d+"})
  */
 public function viewAction($id)
 {
     $artist = Artist::query()->where('id = ?', [$id])->related('album')->first();
     $request = App::request();
     if (is_null($artist)) {
         $request->getSession()->getFlashBag()->add('error', __('Tried to view an non-existing Artist'));
         return App::response()->redirect('@shoutzor/artist/index');
     }
     $topTracks = $artist->getTopMedia();
     return ['$view' => ['title' => 'Artist: ' . $artist->name, 'name' => 'shoutzor:views/artist/view.php'], 'image' => is_null($artist->image) || empty($artist->image) ? App::url()->getStatic('shoutzor:assets/images/profile-placeholder.png') : App::url()->getStatic('shoutzor:' . App::module('shoutzor')->config('shoutzor')['imageDir'] . '/' . $artist->image), 'summary' => empty($artist->summary) ? __('No summary for this artist is available') : $artist->summary, 'artist' => $artist, 'topTracks' => $topTracks, 'albums' => $artist->getAlbums()];
 }
开发者ID:xorinzor,项目名称:Shoutzor,代码行数:14,代码来源:ArtistController.php

示例9: onUserChange

 /**
  * @param      $event
  * @param User $user
  */
 public function onUserChange($event, User $user)
 {
     $profilevalues = App::request()->request->get('profilevalues', []);
     if (count($profilevalues)) {
         $profileUser = ProfileUser::load($user);
         $profileUser->setProfileValues($profilevalues);
         $profileUser->saveProfile();
         //only save once
         App::request()->request->set('profilevalues', []);
     }
 }
开发者ID:Bixie,项目名称:pagekit-userprofile,代码行数:15,代码来源:UserListener.php

示例10: searchAction

 /**
  * @Route("/search", name="search", methods="GET")
  * @Request({"q":"string", "page":"int"})
  */
 public function searchAction($q = "", $page = 1)
 {
     $query = Artist::query()->select('*');
     $request = App::request();
     if (empty($q)) {
         return ['$view' => ['title' => 'Search', 'name' => 'shoutzor:views/search_error.php']];
     }
     $query = Media::query()->select('m.*')->from('@shoutzor_media m')->leftJoin('@shoutzor_media_artist ma', 'ma.media_id = m.id')->leftJoin('@shoutzor_artist a', 'a.id = ma.artist_id')->where('m.status = :status AND (m.title LIKE :search OR a.name LIKE :search OR m.filename LIKE :search)', ['status' => Media::STATUS_FINISHED, 'search' => "%{$q}%"])->orderBy('m.title', 'DESC');
     $limit = 20;
     $count = $query->count();
     $total = ceil($count / $limit);
     $page = max(1, min($total, $page));
     $results = $query->offset(($page - 1) * $limit)->limit($limit)->orderBy('name', 'ASC')->related(['artist', 'album'])->get();
     return ['$view' => ['title' => 'Search', 'name' => 'shoutzor:views/search.php'], 'searchterm' => htmlspecialchars($q), 'page' => $page, 'totalPage' => $total, 'resultCount' => $count, 'results' => $results];
 }
开发者ID:xorinzor,项目名称:Shoutzor,代码行数:19,代码来源:SiteController.php

示例11: authenticateAction

 /**
  * @Route(methods="POST", defaults={"_maintenance" = true})
  * @Request({"credentials": "array"})
  */
 public function authenticateAction($credentials)
 {
     try {
         if (!App::csrf()->validate()) {
             throw new AuthException(__('Invalid token. Please try again.'));
         }
         App::auth()->authorize($user = App::auth()->authenticate($credentials, false));
         return App::auth()->login($user, App::request()->get(Auth::REMEMBER_ME_PARAM));
     } catch (BadCredentialsException $e) {
         App::message()->error(__('Invalid username or password.'));
     } catch (AuthException $e) {
         App::message()->error($e->getMessage());
     }
     return App::redirect(App::url()->previous());
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:19,代码来源:AuthController.php

示例12: indexAction

 /**
  * TODO: Limit catalogue if maintenance mode is enabled?
  * @Route("/{locale}", requirements={"locale"="[a-zA-Z0-9_-]+"}, defaults={"_maintenance" = true})
  * @Request({"locale"})
  */
 public function indexAction($locale = null)
 {
     $intl = App::module('system/intl');
     $intl->loadLocale($locale);
     $messages = $intl->getFormats($locale) ?: [];
     $messages['locale'] = $locale;
     $messages['translations'] = [$locale => App::translator()->getCatalogue($locale)->all()];
     $messages = json_encode($messages);
     $request = App::request();
     $json = $request->isXmlHttpRequest();
     $response = $json ? App::response()->json() : App::response('', 200, ['Content-Type' => 'application/javascript']);
     $response->setETag(md5($json . $messages))->setPublic();
     if ($response->isNotModified($request)) {
         return $response;
     }
     return $response->setContent($json ? $messages : sprintf('var $locale = %s;', $messages));
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:22,代码来源:IntlController.php

示例13: uploadAction

 /**
  * @Request({"type": "string"}, csrf=true)
  */
 public function uploadAction($type)
 {
     $file = App::request()->files->get('file');
     if ($file === null || !$file->isValid()) {
         App::abort(400, __('No file uploaded.'));
     }
     $package = $this->loadPackage($file->getPathname());
     if (!$package->getName() || !$package->get('title') || !$package->get('version')) {
         App::abort(400, __('"composer.json" file not valid.'));
     }
     if ($package->get('type') !== 'pagekit-' . $type) {
         App::abort(400, __('No Pagekit %type%', ['%type%' => $type]));
     }
     $filename = str_replace('/', '-', $package->getName()) . '-' . $package->get('version') . '.zip';
     $file->move(App::get('path') . '/tmp/packages', $filename);
     return compact('package');
 }
开发者ID:4nxiety,项目名称:pagekit,代码行数:20,代码来源:PackageController.php

示例14: indexAction

 /**
  * @Route("/", name="index")
  */
 public function indexAction()
 {
     $request = App::request();
     $config = App::module('shoutzor')->config('shoutzor');
     $config = array_merge($config, $_POST);
     $form = new FormGenerator('', 'POST', 'uk-form uk-form-horizontal');
     $form->addField(new DivField("Permission Check", $config['mediaDir'] . (is_writable($config['mediaDir']) ? " is writable" : " is not writable! chown manually to www-data:www-data"), "", is_writable($config['mediaDir']) ? "uk-alert uk-alert-success" : "uk-alert uk-alert-danger"));
     $form->addField(new DivField("Permission Check", App::module('shoutzor')->config('root_path') . $config['imageDir'] . (is_writable(App::module('shoutzor')->config('root_path') . $config['imageDir']) ? " is writable" : " is not writable! chown manually to www-data:www-data"), "", is_writable(App::module('shoutzor')->config('root_path') . $config['imageDir']) ? "uk-alert uk-alert-success" : "uk-alert uk-alert-danger"));
     $form->addField(new DividerField());
     $form->addField(new SelectField("upload", "upload", "Allow Uploads", "text", $config['upload'], array(['value' => 0, 'title' => 'Disabled'], ['value' => 1, 'title' => 'Enabled']), false, "Changing this setting will not delete uploaded content"))->setValidationType(FormValidation::TYPE_STRING)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new SelectField("request", "request", "Allow Requests", "text", $config['request'], array(['value' => 0, 'title' => 'Disabled'], ['value' => 1, 'title' => 'Enabled']), false, "Changing this setting will allow / deny user requests"))->setValidationType(FormValidation::TYPE_STRING)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new DividerField());
     $form->addField(new InputField("mediaDir", "mediaDir", "Media Storage Directory", "text", $config['mediaDir'], "The directory where uploads should be stored", "uk-form-width-large"))->setValidationType(FormValidation::TYPE_STRING)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new InputField("imageDir", "imageDir", "Image Storage Directory", "text", $config['imageDir'], "The directory where downloaded images should be stored", "uk-form-width-large"))->setValidationType(FormValidation::TYPE_STRING)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new InputField("parserLastRun", "parserLastRun", "Parser Last Run Timestamp", "text", $config['parserLastRun'], "The timestamp of when the parser last ran - in general you will not have to make any changes to this value"))->setValidationType(FormValidation::TYPE_NUMERIC)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new InputField("parserMaxItems", "parserMaxItems", "Parser Max Items", "text", $config['parserMaxItems'], "The maximum amount of items the parser should parse on each run"))->setValidationType(FormValidation::TYPE_NUMERIC)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new DividerField());
     $form->addField(new InputField("userRequestDelay", "userRequestDelay", "User Request Delay", "text", $config['userRequestDelay'], "The delay in minutes that a user has to wait to be able to request a media object again"))->setValidationType(FormValidation::TYPE_NUMERIC)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new InputField("mediaRequestDelay", "mediaRequestDelay", "Media Request Delay", "text", $config['mediaRequestDelay'], "The delay in minutes before a media object can be played again"))->setValidationType(FormValidation::TYPE_NUMERIC)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new InputField("artistRequestDelay", "artistRequestDelay", "Artist Request Delay", "text", $config['artistRequestDelay'], "The delay in minutes before a media object from the same artist can be played again"))->setValidationType(FormValidation::TYPE_NUMERIC)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new InputField("uploadDurationLimit", "uploadDurationLimit", "Media Duration Limit (Minutes)", "text", $config['uploadDurationLimit'], "The limit of the duration from uploaded media files in minutes - changing this will have no effect on already uploaded files"))->setValidationType(FormValidation::TYPE_NUMERIC)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new SelectField("useFilenameIfUntitled", "useFilenameIfUntitled", "Use Filename If Untitled", "text", $config['useFilenameIfUntitled'], array(['value' => 0, 'title' => 'Disabled'], ['value' => 1, 'title' => 'Enabled']), false, "Use the filename as title when no title could be detected and/or found"))->setValidationType(FormValidation::TYPE_STRING)->setValidationRequirements(array(FormValidation::REQ_NOTEMPTY));
     $form->addField(new InputField("submit", "", "Save Changes", "submit", "Save Changes", "", "uk-button uk-button-primary"));
     $alert = array();
     //Check if a POST request has been made
     if ($request->isMethod('POST')) {
         $form->validate();
         //Make sure no errors have occured during validation
         if ($form->hasErrors() === false) {
             $configValues = array();
             foreach ($form->getFields() as $field) {
                 if (!empty($field->getName())) {
                     $configValues[$field->getName()] = $field->getValue();
                 }
             }
             App::config('shoutzor')->set('shoutzor', $configValues);
             //Do stuff
             $alert = array('type' => 'success', 'msg' => __('Changes saved. Make sure the applicable liquidsoap scripts are restarted for the changes to take effect'));
         } else {
             $alert = array('type' => 'error', 'msg' => __('Not all fields passed validation, correct the problems and try again'));
         }
     }
     $content = $form->render();
     return ['$view' => ['title' => __('Shoutzor Settings'), 'name' => 'shoutzor:views/admin/shoutzor.php'], 'form' => $content, 'alert' => $alert];
 }
开发者ID:xorinzor,项目名称:Shoutzor,代码行数:48,代码来源:ShoutzorController.php

示例15: onUserChange

 public function onUserChange($event, User $user)
 {
     /** @var \Bixie\Userprofile\Model\Profilevalue $profilevalue */
     foreach (App::request()->request->get('profilevalues', []) as $data) {
         // is new ?
         if (!($profilevalue = Profilevalue::find($data['id']))) {
             if ($data['id']) {
                 App::abort(404, __('Userprofilevalue not found.'));
             }
             $profilevalue = Profilevalue::create();
         }
         $profilevalue->field_id = $data['field_id'];
         $profilevalue->user_id = $user->id;
         $profilevalue->multiple = $data['multiple'];
         $profilevalue->setValue($data['value']);
         $profilevalue->save();
     }
 }
开发者ID:4nxiety,项目名称:pagekit-userprofile,代码行数:18,代码来源:UserListener.php


注:本文中的Pagekit\Application::request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。