terabytesoftw /
app-basic
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace terabytesoft\app\basic\controllers; |
||||||
| 4 | |||||||
| 5 | use terabytesoft\app\basic\forms\ContactForm; |
||||||
| 6 | use terabytesoft\helpers\Mailer; |
||||||
| 7 | use yii\base\Model; |
||||||
| 8 | use yii\base\Module; |
||||||
| 9 | use yii\captcha\CaptchaAction; |
||||||
| 10 | use yii\filters\AccessControl; |
||||||
| 11 | use yii\filters\VerbFilter; |
||||||
| 12 | use yii\web\Controller; |
||||||
| 13 | use yii\web\ErrorAction; |
||||||
| 14 | use yii\web\Response; |
||||||
| 15 | |||||||
| 16 | /** |
||||||
| 17 | * SiteController |
||||||
| 18 | * |
||||||
| 19 | * Controller web application basic |
||||||
| 20 | */ |
||||||
| 21 | class SiteController extends Controller |
||||||
| 22 | { |
||||||
| 23 | /** |
||||||
| 24 | * @var object |
||||||
| 25 | */ |
||||||
| 26 | private $mailer; |
||||||
| 27 | |||||||
| 28 | /** |
||||||
| 29 | * behaviors |
||||||
| 30 | */ |
||||||
| 31 | 12 | public function behaviors() |
|||||
| 32 | { |
||||||
| 33 | return [ |
||||||
| 34 | 'verbs' => [ |
||||||
| 35 | 12 | 'class' => VerbFilter::class, |
|||||
| 36 | 'actions' => [ |
||||||
| 37 | 'logout' => ['post'], |
||||||
| 38 | ], |
||||||
| 39 | ], |
||||||
| 40 | ]; |
||||||
| 41 | } |
||||||
| 42 | |||||||
| 43 | |||||||
| 44 | /** |
||||||
| 45 | * actions |
||||||
| 46 | */ |
||||||
| 47 | 12 | public function actions() |
|||||
| 48 | { |
||||||
| 49 | return [ |
||||||
| 50 | 'error' => [ |
||||||
| 51 | 12 | 'class' => ErrorAction::class, |
|||||
| 52 | ], |
||||||
| 53 | 'captcha' => [ |
||||||
| 54 | 'class' => CaptchaAction::class, |
||||||
| 55 | 12 | 'fixedVerifyCode' => (YII_ENV === 'test') ? 'testme' : null, |
|||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||
| 56 | ], |
||||||
| 57 | ]; |
||||||
| 58 | } |
||||||
| 59 | |||||||
| 60 | /** |
||||||
| 61 | * __construct |
||||||
| 62 | */ |
||||||
| 63 | 14 | public function __construct($id, Module $module, array $config = []) |
|||||
| 64 | { |
||||||
| 65 | 14 | $this->mailer = new Mailer(); |
|||||
| 66 | 14 | parent::__construct($id, $module, $config); |
|||||
| 67 | 14 | } |
|||||
| 68 | |||||||
| 69 | /** |
||||||
| 70 | * actionIndex |
||||||
| 71 | */ |
||||||
| 72 | 2 | public function actionIndex(): string |
|||||
| 73 | { |
||||||
| 74 | 2 | return $this->render('index'); |
|||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | /** |
||||||
| 78 | * actionAbout |
||||||
| 79 | **/ |
||||||
| 80 | 1 | public function actionAbout(): string |
|||||
| 81 | { |
||||||
| 82 | 1 | return $this->render('about'); |
|||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | /** |
||||||
| 86 | * actionContact |
||||||
| 87 | * @return response|string |
||||||
| 88 | **/ |
||||||
| 89 | 8 | public function actionContact() |
|||||
| 90 | { |
||||||
| 91 | 8 | $model = new ContactForm(); |
|||||
| 92 | |||||||
| 93 | 8 | if ($model->load($this->module->request->post()) && $model->validate()) { |
|||||
|
0 ignored issues
–
show
The method
post() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 94 | 2 | $this->sendContact($model); |
|||||
| 95 | |||||||
| 96 | 2 | $this->module->session->setFlash('contactFormSubmitted'); |
|||||
|
0 ignored issues
–
show
The method
setFlash() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 97 | |||||||
| 98 | 2 | return $this->refresh(); |
|||||
| 99 | } |
||||||
| 100 | |||||||
| 101 | 8 | return $this->render('contact', [ |
|||||
| 102 | 8 | 'model' => $model, |
|||||
| 103 | ]); |
||||||
| 104 | } |
||||||
| 105 | |||||||
| 106 | /** |
||||||
| 107 | * sendContact |
||||||
| 108 | * @param Model $model |
||||||
| 109 | **/ |
||||||
| 110 | 3 | public function sendContact(Model $model): void |
|||||
| 111 | { |
||||||
| 112 | 3 | $this->mailer->sendMessage( |
|||||
| 113 | 3 | $model->email, |
|||||
| 114 | 3 | $model->subject, |
|||||
| 115 | [ |
||||||
| 116 | 'replyTo' => [ |
||||||
| 117 | 3 | $model->email => $model->name |
|||||
| 118 | ], |
||||||
| 119 | 3 | 'textBody' => $model->body |
|||||
| 120 | ] |
||||||
| 121 | ); |
||||||
| 122 | 3 | } |
|||||
| 123 | } |
||||||
| 124 |