PluginProbe
Redirection / 5.2
Redirection v5.2
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / models / action.php

action.php in Redirection 5.2, at models/action.php

137 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * A redirect action - what happens after a URL is matched.
5 */
6 abstract class Red_Action {
7 /**
8 * The action code (i.e. HTTP code)
9 *
10 * @var integer
11 */
12 protected $code = 0;
13
14 /**
15 * The action type
16 *
17 * @var string
18 */
19 protected $type = '';
20
21 /**
22 * Target URL, if any
23 *
24 * @var String|null
25 */
26 protected $target = null;
27
28 /**
29 * Constructor
30 *
31 * @param array $values Values.
32 */
33 public function __construct( $values = [] ) {
34 if ( is_array( $values ) ) {
35 foreach ( $values as $key => $value ) {
36 $this->$key = $value;
37 }
38 }
39 }
40
41 abstract public function name();
42
43 /**
44 * Create an action object
45 *
46 * @param string $name Action type.
47 * @param integer $code Action code.
48 * @return Red_Action|null
49 */
50 public static function create( $name, $code ) {
51 $avail = self::available();
52
53 if ( isset( $avail[ $name ] ) ) {
54 if ( ! class_exists( strtolower( $avail[ $name ][1] ) ) ) {
55 include_once dirname( __FILE__ ) . '/../actions/' . $avail[ $name ][0];
56 }
57
58 /**
59 * @var Red_Action
60 */
61 $obj = new $avail[ $name ][1]( [ 'code' => $code ] );
62 $obj->type = $name;
63 return $obj;
64 }
65
66 return null;
67 }
68
69 /**
70 * Get list of available actions
71 *
72 * @return array
73 */
74 public static function available() {
75 return [
76 'url' => [ 'url.php', 'Url_Action' ],
77 'error' => [ 'error.php', 'Error_Action' ],
78 'nothing' => [ 'nothing.php', 'Nothing_Action' ],
79 'random' => [ 'random.php', 'Random_Action' ],
80 'pass' => [ 'pass.php', 'Pass_Action' ],
81 ];
82 }
83
84 /**
85 * Get the action code
86 *
87 * @return integer
88 */
89 public function get_code() {
90 return $this->code;
91 }
92
93 /**
94 * Get action type
95 *
96 * @return string
97 */
98 public function get_type() {
99 return $this->type;
100 }
101
102 /**
103 * Set the target for this action
104 *
105 * @param String $target_url The original URL from the client.
106 * @return void
107 */
108 public function set_target( $target_url ) {
109 $this->target = $target_url;
110 }
111
112 /**
113 * Get the target for this action
114 *
115 * @return String|null
116 */
117 public function get_target() {
118 return $this->target;
119 }
120
121 /**
122 * Does this action need a target?
123 *
124 * @return boolean
125 */
126 public function needs_target() {
127 return false;
128 }
129
130 /**
131 * Run this action. May not return from this function.
132 *
133 * @return void
134 */
135 abstract public function run();
136 }
137