| 1 |
<?php |
| 2 |
|
| 3 |
abstract class Red_Action { |
| 4 |
protected $code; |
| 5 |
protected $type; |
| 6 |
|
| 7 |
function __construct( $values ) { |
| 8 |
if ( is_array( $values ) ) { |
| 9 |
foreach ( $values as $key => $value ) { |
| 10 |
$this->$key = $value; |
| 11 |
} |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
static function create( $name, $code ) { |
| 16 |
$avail = self::available(); |
| 17 |
|
| 18 |
if ( isset( $avail[ $name ] ) ) { |
| 19 |
if ( ! class_exists( strtolower( $avail[ $name ][1] ) ) ) { |
| 20 |
include_once dirname( __FILE__ ) . '/../actions/' . $avail[ $name ][0]; |
| 21 |
} |
| 22 |
|
| 23 |
$obj = new $avail[ $name ][1]( array( 'code' => $code ) ); |
| 24 |
$obj->type = $name; |
| 25 |
return $obj; |
| 26 |
} |
| 27 |
|
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
static function available() { |
| 32 |
return array( |
| 33 |
'url' => array( 'url.php', 'Url_Action' ), |
| 34 |
'error' => array( 'error.php', 'Error_Action' ), |
| 35 |
'nothing' => array( 'nothing.php', 'Nothing_Action' ), |
| 36 |
'random' => array( 'random.php', 'Random_Action' ), |
| 37 |
'pass' => array( 'pass.php', 'Pass_Action' ), |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
public function process_before( $code, $target ) { |
| 42 |
return $target; |
| 43 |
} |
| 44 |
|
| 45 |
public function process_after( $code, $target ) { |
| 46 |
return true; |
| 47 |
} |
| 48 |
|
| 49 |
public function get_code() { |
| 50 |
return $this->code; |
| 51 |
} |
| 52 |
|
| 53 |
public function get_type() { |
| 54 |
return $this->type; |
| 55 |
} |
| 56 |
|
| 57 |
abstract public function needs_target(); |
| 58 |
} |
| 59 |
|