Index: trunk/phase3/includes/filerepo/backend/FileOp.php |
— | — | @@ -28,10 +28,6 @@ |
29 | 29 | protected $sourceSha1; // string |
30 | 30 | protected $destSameAsSource; // boolean |
31 | 31 | |
32 | | - /* Operation parameters */ |
33 | | - protected static $requiredParams = array(); |
34 | | - protected static $optionalParams = array(); |
35 | | - |
36 | 32 | /* Object life-cycle */ |
37 | 33 | const STATE_NEW = 1; |
38 | 34 | const STATE_CHECKED = 2; |
— | — | @@ -50,15 +46,15 @@ |
51 | 47 | */ |
52 | 48 | final public function __construct( FileBackendBase $backend, array $params ) { |
53 | 49 | $this->backend = $backend; |
54 | | - $class = get_class( $this ); // simulate LSB |
55 | | - foreach ( $class::$requiredParams as $name ) { |
| 50 | + list( $required, $optional ) = $this->allowedParams(); |
| 51 | + foreach ( $required as $name ) { |
56 | 52 | if ( isset( $params[$name] ) ) { |
57 | 53 | $this->params[$name] = $params[$name]; |
58 | 54 | } else { |
59 | 55 | throw new MWException( "File operation missing parameter '$name'." ); |
60 | 56 | } |
61 | 57 | } |
62 | | - foreach ( $class::$optionalParams as $name ) { |
| 58 | + foreach ( $optional as $name ) { |
63 | 59 | if ( isset( $params[$name] ) ) { |
64 | 60 | $this->params[$name] = $params[$name]; |
65 | 61 | } |
— | — | @@ -217,6 +213,15 @@ |
218 | 214 | } |
219 | 215 | |
220 | 216 | /** |
| 217 | + * Get required operation parameters |
| 218 | + * |
| 219 | + * @return Array (required params list, optional params list) |
| 220 | + */ |
| 221 | + protected function allowedParams() { |
| 222 | + return array( array(), array() ); |
| 223 | + } |
| 224 | + |
| 225 | + /** |
221 | 226 | * Get a list of storage paths read from for this operation |
222 | 227 | * |
223 | 228 | * @return Array |
— | — | @@ -387,8 +392,9 @@ |
388 | 393 | * overwriteSame : override any existing file at destination |
389 | 394 | */ |
390 | 395 | class StoreFileOp extends FileOp { |
391 | | - protected static $requiredParams = array( 'src', 'dst' ); |
392 | | - protected static $optionalParams = array( 'overwrite', 'overwriteSame' ); |
| 396 | + protected function allowedParams() { |
| 397 | + return array( array( 'src', 'dst' ), array( 'overwrite', 'overwriteSame' ) ); |
| 398 | + } |
393 | 399 | |
394 | 400 | protected function doPrecheck( array &$predicates ) { |
395 | 401 | $status = Status::newGood(); |
— | — | @@ -448,8 +454,9 @@ |
449 | 455 | * overwriteSame : override any existing file at destination |
450 | 456 | */ |
451 | 457 | class CreateFileOp extends FileOp { |
452 | | - protected static $requiredParams = array( 'content', 'dst' ); |
453 | | - protected static $optionalParams = array( 'overwrite', 'overwriteSame' ); |
| 458 | + protected function allowedParams() { |
| 459 | + return array( array( 'content', 'dst' ), array( 'overwrite', 'overwriteSame' ) ); |
| 460 | + } |
454 | 461 | |
455 | 462 | protected function doPrecheck( array &$predicates ) { |
456 | 463 | $status = Status::newGood(); |
— | — | @@ -499,8 +506,9 @@ |
500 | 507 | * overwriteSame : override any existing file at destination |
501 | 508 | */ |
502 | 509 | class CopyFileOp extends FileOp { |
503 | | - protected static $requiredParams = array( 'src', 'dst' ); |
504 | | - protected static $optionalParams = array( 'overwrite', 'overwriteSame' ); |
| 510 | + protected function allowedParams() { |
| 511 | + return array( array( 'src', 'dst' ), array( 'overwrite', 'overwriteSame' ) ); |
| 512 | + } |
505 | 513 | |
506 | 514 | protected function doPrecheck( array &$predicates ) { |
507 | 515 | $status = Status::newGood(); |
— | — | @@ -553,8 +561,9 @@ |
554 | 562 | * overwriteSame : override any existing file at destination |
555 | 563 | */ |
556 | 564 | class MoveFileOp extends FileOp { |
557 | | - protected static $requiredParams = array( 'src', 'dst' ); |
558 | | - protected static $optionalParams = array( 'overwrite', 'overwriteSame' ); |
| 565 | + protected function allowedParams() { |
| 566 | + return array( array( 'src', 'dst' ), array( 'overwrite', 'overwriteSame' ) ); |
| 567 | + } |
559 | 568 | |
560 | 569 | protected function doPrecheck( array &$predicates ) { |
561 | 570 | $status = Status::newGood(); |
— | — | @@ -611,8 +620,9 @@ |
612 | 621 | * ignoreMissingSource : don't return an error if the file does not exist |
613 | 622 | */ |
614 | 623 | class DeleteFileOp extends FileOp { |
615 | | - protected static $requiredParams = array( 'src' ); |
616 | | - protected static $optionalParams = array( 'ignoreMissingSource' ); |
| 624 | + protected function allowedParams() { |
| 625 | + return array( array( 'src' ), array( 'ignoreMissingSource' ) ); |
| 626 | + } |
617 | 627 | |
618 | 628 | protected $needsDelete = true; |
619 | 629 | |