Esempio n. 1
0
 /**
  * Defer a method to native PHP.
  *
  * @param string $class  The class
  * @param string $method The method
  *
  * @return string The correct function to call
  */
 public static function toNative($class, $method)
 {
     // Aliased native function
     $native = Method::getNative($method);
     if ($native) {
         return $native;
     }
     // Transform class to php function prefix
     switch ($class) {
         case static::TYPES . 'Arrays':
             $prefix = 'array_';
             break;
         case static::TYPES . 'Strings':
             $prefix = 'str_';
             break;
     }
     // If no function prefix found, return false
     if (!isset($prefix)) {
         return false;
     }
     // Native function
     $function = $prefix . $method;
     if (function_exists($function)) {
         return $function;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Tries to find the right class to call
  *
  * @param string $callingClass The original class
  * @param string $method       The method
  * @param array  $arguments    The arguments
  *
  * @return string The correct class
  */
 protected static function computeClassToCall($callingClass, $method, $arguments)
 {
     if (!StringMethods::find($callingClass, 'Underscore\\Types')) {
         if (isset($arguments[0])) {
             $callingClass = Dispatch::toClass($arguments[0]);
         } else {
             $callingClass = Method::findInClasses($callingClass, $method);
         }
     }
     return $callingClass;
 }
Esempio n. 3
0
 public function testCanFindMethodsInClasses()
 {
     $method = Method::findInClasses('\\Underscore\\Underscore', 'range');
     $this->assertEquals('\\Underscore\\Types\\Arrays', $method);
 }