PostsController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace TestApp\Controller;
  16. use Cake\Event\Event;
  17. use TestApp\Controller\AppController;
  18. /**
  19. * PostsController class
  20. */
  21. class PostsController extends AppController
  22. {
  23. /**
  24. * Components array
  25. *
  26. * @var array
  27. */
  28. public $components = [
  29. 'Flash',
  30. 'RequestHandler',
  31. 'Security',
  32. ];
  33. /**
  34. * beforeFilter
  35. *
  36. * @return void
  37. */
  38. public function beforeFilter(Event $event)
  39. {
  40. if ($this->request->param('action') !== 'securePost') {
  41. $this->eventManager()->off($this->Security);
  42. }
  43. }
  44. /**
  45. * Index method.
  46. *
  47. * @return void
  48. */
  49. public function index()
  50. {
  51. $this->Flash->error('An error message');
  52. $this->response->cookie([
  53. 'name' => 'remember_me',
  54. 'value' => 1
  55. ]);
  56. $this->set('test', 'value');
  57. }
  58. /**
  59. * Stub get method
  60. *
  61. * @return void
  62. */
  63. public function get()
  64. {
  65. // Do nothing.
  66. }
  67. /**
  68. * Post endpoint for integration testing with security component.
  69. *
  70. * @return void
  71. */
  72. public function securePost()
  73. {
  74. $this->response->body('Request was accepted');
  75. return $this->response;
  76. }
  77. public function file()
  78. {
  79. $this->response->file(__FILE__);
  80. return $this->response;
  81. }
  82. }