r109938 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109937‎ | r109938 | r109939 >
Date:18:49, 24 January 2012
Author:aaron
Status:ok
Tags:filebackend 
Comment:
r109904: worked around PHP < 5.3 suckage to keep this compatible
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FileOp.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FileOp.php
@@ -28,10 +28,6 @@
2929 protected $sourceSha1; // string
3030 protected $destSameAsSource; // boolean
3131
32 - /* Operation parameters */
33 - protected static $requiredParams = array();
34 - protected static $optionalParams = array();
35 -
3632 /* Object life-cycle */
3733 const STATE_NEW = 1;
3834 const STATE_CHECKED = 2;
@@ -50,15 +46,15 @@
5147 */
5248 final public function __construct( FileBackendBase $backend, array $params ) {
5349 $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 ) {
5652 if ( isset( $params[$name] ) ) {
5753 $this->params[$name] = $params[$name];
5854 } else {
5955 throw new MWException( "File operation missing parameter '$name'." );
6056 }
6157 }
62 - foreach ( $class::$optionalParams as $name ) {
 58+ foreach ( $optional as $name ) {
6359 if ( isset( $params[$name] ) ) {
6460 $this->params[$name] = $params[$name];
6561 }
@@ -217,6 +213,15 @@
218214 }
219215
220216 /**
 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+ /**
221226 * Get a list of storage paths read from for this operation
222227 *
223228 * @return Array
@@ -387,8 +392,9 @@
388393 * overwriteSame : override any existing file at destination
389394 */
390395 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+ }
393399
394400 protected function doPrecheck( array &$predicates ) {
395401 $status = Status::newGood();
@@ -448,8 +454,9 @@
449455 * overwriteSame : override any existing file at destination
450456 */
451457 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+ }
454461
455462 protected function doPrecheck( array &$predicates ) {
456463 $status = Status::newGood();
@@ -499,8 +506,9 @@
500507 * overwriteSame : override any existing file at destination
501508 */
502509 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+ }
505513
506514 protected function doPrecheck( array &$predicates ) {
507515 $status = Status::newGood();
@@ -553,8 +561,9 @@
554562 * overwriteSame : override any existing file at destination
555563 */
556564 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+ }
559568
560569 protected function doPrecheck( array &$predicates ) {
561570 $status = Status::newGood();
@@ -611,8 +620,9 @@
612621 * ignoreMissingSource : don't return an error if the file does not exist
613622 */
614623 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+ }
617627
618628 protected $needsDelete = true;
619629

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109904Made FileOp classes enforce required params. Also reverts r109823.aaron05:54, 24 January 2012

Status & tagging log