|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Cadmium\System\Modules\Auth |
|
5
|
|
|
* @author Anton Romanov |
|
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
|
7
|
|
|
* @link http://cadmium-cms.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Modules\Auth\Utils { |
|
11
|
|
|
|
|
12
|
|
|
use Modules\Auth, Utils\Messages, Utils\View, Language, Request, Template; |
|
13
|
|
|
|
|
14
|
|
|
abstract class Action { |
|
15
|
|
|
|
|
16
|
|
|
protected $code = null, $user = null, $form = null; |
|
17
|
|
|
|
|
18
|
|
|
# Action configuration interface |
|
19
|
|
|
|
|
20
|
|
|
protected static $view = '', $form_class = '', $controller_class = ''; |
|
21
|
|
|
|
|
22
|
|
|
protected static $redirect = '', $messages = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get the contents block |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
private function getContents() : Template\Block { |
|
29
|
|
|
|
|
30
|
|
|
$contents = View::get((Auth::isAdmin() ? 'Blocks/Auth/' : 'Blocks/Profile/Auth/') . static::$view); |
|
31
|
|
|
|
|
32
|
|
|
# Set code |
|
33
|
|
|
|
|
34
|
|
|
if (null !== $this->code) $contents->code = $this->code; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
# Implement form |
|
37
|
|
|
|
|
38
|
|
|
if (null !== $this->form) $this->form->implement($contents); |
|
39
|
|
|
|
|
40
|
|
|
# ------------------------ |
|
41
|
|
|
|
|
42
|
|
|
return $contents; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Handle the request |
|
47
|
|
|
*/ |
|
48
|
|
|
|
|
49
|
|
|
public function handle() : Template\Block { |
|
50
|
|
|
|
|
51
|
|
|
# Create form |
|
52
|
|
|
|
|
53
|
|
|
$this->form = new static::$form_class; |
|
54
|
|
|
|
|
55
|
|
|
# Handle form |
|
56
|
|
|
|
|
57
|
|
View Code Duplication |
if ($this->form->handle(new static::$controller_class($this->user))) { |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
Request::redirect(INSTALL_PATH . (Auth::isAdmin() ? '/admin' : '/profile') . static::$redirect); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
# Display success message |
|
63
|
|
|
|
|
64
|
|
|
foreach (static::$messages as $key => $message) if (Request::get('submitted') === $key) { |
|
65
|
|
|
|
|
66
|
|
|
Messages::set('success', Language::get($message['text']), Language::get($message['title'])); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
# ------------------------ |
|
70
|
|
|
|
|
71
|
|
|
return $this->getContents(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.