replacers: Make Replacer abstract, and add abstract Replacer::replace()
authorKunal Mehta <legoktm@gmail.com>
Thu, 29 Jan 2015 04:49:57 +0000 (20:49 -0800)
committerKunal Mehta <legoktm@gmail.com>
Thu, 29 Jan 2015 04:49:57 +0000 (20:49 -0800)
Change-Id: Ib00dc8585e8ba599491e51e0b99a8667c3b4cd63

includes/libs/replacers/DoubleReplacer.php
includes/libs/replacers/HashtableReplacer.php
includes/libs/replacers/RegexlikeReplacer.php
includes/libs/replacers/Replacer.php

index 20a4089..fed023b 100644 (file)
@@ -37,7 +37,7 @@ class DoubleReplacer extends Replacer {
         * @param array $matches
         * @return mixed
         */
-       public function replace( $matches ) {
+       public function replace( array $matches ) {
                return str_replace( $this->from, $this->to, $matches[$this->index] );
        }
 }
index e1572f2..b3c219d 100644 (file)
@@ -37,7 +37,7 @@ class HashtableReplacer extends Replacer {
         * @param array $matches
         * @return mixed
         */
-       public function replace( $matches ) {
+       public function replace( array $matches ) {
                return $this->table[$matches[$this->index]];
        }
 }
index 630a754..2b1fa74 100644 (file)
@@ -35,7 +35,7 @@ class RegexlikeReplacer extends Replacer {
         * @param array $matches
         * @return string
         */
-       public function replace( $matches ) {
+       public function replace( array $matches ) {
                $pairs = array();
                foreach ( $matches as $i => $match ) {
                        $pairs["\$$i"] = $match;
index 924fb30..f4850bf 100644 (file)
  * Base class for "replacers", objects used in preg_replace_callback() and
  * StringUtils::delimiterReplaceCallback()
  */
-class Replacer {
+abstract class Replacer {
        /**
         * @return array
         */
        public function cb() {
                return array( &$this, 'replace' );
        }
+
+       /**
+        * @param array $matches
+        * @return string
+        */
+       abstract public function replace( array $matches );
 }