コード例 #1
0
 public function array_of_issues()
 {
     $issue1 = new net·xp_framework·unittest·webservices·rest·IssueWithField(1, 'test1');
     $issue2 = new net·xp_framework·unittest·webservices·rest·IssueWithField(2, 'test2');
     $this->assertEquals(array($issue1, $issue2), $this->fixture->convert(ArrayType::forName($issue1->getClassName() . '[]'), array(array('issue_id' => 1, 'title' => 'test1'), array('issue_id' => 2, 'title' => 'test2'))));
 }
コード例 #2
0
 public function cast_raises_exceptions_for_non_arrays($value)
 {
     ArrayType::forName('var[]')->cast($value);
 }
コード例 #3
0
ファイル: TypeTest.class.php プロジェクト: xp-framework/core
 public function arrayOfString()
 {
     $this->assertEquals(ArrayType::forName('string[]'), Type::forName('string[]'));
 }
コード例 #4
0
 public function intArray()
 {
     $this->assertEquals(ArrayType::forName('var[]'), typeof(array(1, 2, 3)));
 }
コード例 #5
0
 public function varArrayAssignableFromIntArray()
 {
     $this->assertFalse(ArrayType::forName('var[]')->isAssignableFrom('int[]'));
 }
コード例 #6
0
 public function arrayComponentType()
 {
     $this->assertEquals(ArrayType::forName('int[]'), MapType::forName('[:int[]]')->componentType());
 }
コード例 #7
0
 public function varArgsArrayType()
 {
     $this->assertEquals(ArrayType::forName('string[]'), $this->methodParameter('printf', 1)->getType());
 }
コード例 #8
0
ファイル: lang.base.php プロジェクト: Gamepay/xp-framework
function typeof($arg)
{
    if ($arg instanceof Generic) {
        return $arg->getClass();
    } else {
        if (NULL === $arg) {
            return Type::$VOID;
        } else {
            if (is_array($arg)) {
                return 0 === key($arg) ? ArrayType::forName('var[]') : MapType::forName('[:var]');
            } else {
                return Type::forName(gettype($arg));
            }
        }
    }
}
コード例 #9
0
 public function stringArrayDeprecatedSyntax()
 {
     $this->assertEquals(ArrayType::forName('string[]'), Type::forName('array<string>'));
 }
コード例 #10
0
 /**
  * Gets a type for a given name
  *
  * Checks for:
  * <ul>
  *   <li>Primitive types (string, integer, double, boolean, array)</li>
  *   <li>Array notations (string[] or string*)</li>
  *   <li>Resources</li>
  *   <li>Any type (var or *)</li>
  *   <li>Generic notations (util.collections.HashTable<lang.types.String, lang.Generic>)</li>
  *   <li>Anything else will be passed to XPClass::forName()</li>
  * </ul>
  *
  * @param   string name
  * @return  lang.Type
  */
 public static function forName($name)
 {
     static $deprecated = array('char' => 'string', 'integer' => 'int', 'boolean' => 'bool', 'float' => 'double', 'mixed' => 'var', '*' => 'var', 'array' => 'var[]', 'resource' => 'var');
     static $primitives = array('string' => TRUE, 'int' => TRUE, 'double' => TRUE, 'bool' => TRUE);
     // Map deprecated type names
     $type = isset($deprecated[$name]) ? $deprecated[$name] : $name;
     // Map well-known primitives, var and void, handle rest syntactically:
     // * T[] is an array
     // * [:T] is a map
     // * T* is a vararg
     // * T<K, V> is a generic
     // * Anything else is a qualified or unqualified class name
     if (isset($primitives[$type])) {
         return Primitive::forName($type);
     } else {
         if ('var' === $type) {
             return self::$VAR;
         } else {
             if ('void' === $type) {
                 return self::$VOID;
                 return $type;
             } else {
                 if ('[]' === substr($type, -2)) {
                     return ArrayType::forName($type);
                 } else {
                     if ('[:' === substr($type, 0, 2)) {
                         return MapType::forName($type);
                     } else {
                         if ('*' === substr($type, -1)) {
                             return ArrayType::forName(substr($type, 0, -1) . '[]');
                         } else {
                             if (FALSE === ($p = strpos($type, '<'))) {
                                 return strstr($type, '.') ? XPClass::forName($type) : new XPClass($type);
                             }
                         }
                     }
                 }
             }
         }
     }
     // Generics
     // * D<K, V> is a generic type definition D with K and V componenty
     // * Deprecated: array<T> is T[], array<K, V> is [:T]
     $base = substr($type, 0, $p);
     $components = self::forNames(substr($type, $p + 1, -1));
     if ('array' !== $base) {
         return cast(self::forName($base), 'lang.XPClass')->newGenericType($components);
     }
     $s = sizeof($components);
     if (2 === $s) {
         return MapType::forName('[:' . $components[1]->name . ']');
     } else {
         if (1 === $s) {
             return ArrayType::forName($components[0]->name . '[]');
         }
     }
     throw new IllegalArgumentException('Unparseable name ' . $name);
 }