Pastakhov has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/146421

Change subject: add function GenericObject::checkArguments() (v 2.6.0)
......................................................................

add function GenericObject::checkArguments() (v 2.6.0)

Change-Id: I6aa982e0d73614b97c54e0b1fca50f08c8155768
---
M PhpTags.php
M includes/GenericObject.php
M includes/Hooks.php
3 files changed, 55 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PhpTags 
refs/changes/21/146421/1

diff --git a/PhpTags.php b/PhpTags.php
index c67a4e1..de7177c 100644
--- a/PhpTags.php
+++ b/PhpTags.php
@@ -16,7 +16,7 @@
 }
 
 define( 'PHPTAGS_MAJOR_VERSION', 2 );
-define( 'PHPTAGS_MINOR_VERSION', 5 );
+define( 'PHPTAGS_MINOR_VERSION', 6 );
 define( 'PHPTAGS_RELEASE_VERSION', 0 );
 define( 'PHPTAGS_VERSION', PHPTAGS_MAJOR_VERSION . '.' . PHPTAGS_MINOR_VERSION 
. '.' . PHPTAGS_RELEASE_VERSION );
 
diff --git a/includes/GenericObject.php b/includes/GenericObject.php
index b80e5ec..a4b1ee2 100644
--- a/includes/GenericObject.php
+++ b/includes/GenericObject.php
@@ -83,4 +83,43 @@
                \PhpTags\Runtime::$transit[PHPTAGS_TRANSIT_EXCEPTION][] = new 
\PhpTags\PhpTagsException( $exception, $arguments );
        }
 
+       public static function checkArguments( $object, $method, $arguments, 
$expects = false ) {
+               if ( false === $expects ) {
+                       return true;
+               }
+
+               $argCount = count( $arguments );
+               if( true === isset( $expects[Hooks::EXPECTS_EXACTLY_PARAMETERS] 
) && $argCount != $expects[Hooks::EXPECTS_EXACTLY_PARAMETERS] ) {
+                       \PhpTags\Runtime::$transit[PHPTAGS_TRANSIT_EXCEPTION][] 
= new \PhpTags\PhpTagsException(
+                                       
\PhpTags\PhpTagsException::WARNING_EXPECTS_EXACTLY_PARAMETER,
+                                       array( "$object::$method", 
$expects[Hooks::EXPECTS_EXACTLY_PARAMETERS], $argCount )
+                               );
+                       return false;
+               }
+
+               $error = false;
+               for ( $i = 0; $i < $argCount; $i++ ) {
+                       if ( true === isset( $expects[$i] ) ) {
+                               switch ( $expects[$i] ) {
+                                       case Hooks::TYPE_NUMBER:
+                                               if ( false === is_numeric( 
$arguments[$i] ) ) {
+                                                       $error = 'number';
+                                                       break 2;
+                                               }
+                                               break;
+                               }
+                       }
+               }
+
+               if ( $error === false ) {
+                       return true;
+               }
+
+               \PhpTags\Runtime::$transit[PHPTAGS_TRANSIT_EXCEPTION][] = new 
\PhpTags\PhpTagsException(
+                               
\PhpTags\PhpTagsException::WARNING_EXPECTS_PARAMETER,
+                               array( "$object::$method", $i+1, $error, 
gettype( $arguments[$i] ) )
+                       );
+               return false;
+       }
+
 }
diff --git a/includes/Hooks.php b/includes/Hooks.php
index b95622d..e9f1425 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -11,6 +11,12 @@
  */
 class Hooks {
 
+       const EXPECTS_EXACTLY_PARAMETERS = '=';
+       const TYPE_NUMBER = 1;
+       const TYPE_MIXED = 2;
+       const TYPE_CALLBACK = 3;
+       const TYPE_ARRAY = 4;
+
        /**
         * Array of constant's values
         * self::$constantValues[ constant_name ] = constant_value
@@ -209,12 +215,18 @@
         */
        private static function callObjectsMethod( $arguments, $name, $object ) 
{
                if ( $object instanceof GenericObject ) {
-                       return call_user_func_array( array($object, "m_$name"), 
$arguments );
+                       if ( true === $object->checkArguments( $object, $name, 
$arguments ) ) {
+                               return call_user_func_array( array($object, 
"m_$name"), $arguments );
+                       } else {
+                               return;
+                       }
                }
                // it is calling of static method
                $className = self::getClassNameByObjectName( $object );
-               $arguments[] = $object;
-               return call_user_func_array( array($className, "s_$name"), 
$arguments );
+               if ( true === $className::checkArguments( $object, $name, 
$arguments ) ) {
+                       $arguments[] = $object;
+                       return call_user_func_array( array($className, 
"s_$name"), $arguments );
+               }
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/146421
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6aa982e0d73614b97c54e0b1fca50f08c8155768
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PhpTags
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to