当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassLoader::defineType方法代码示例

本文整理汇总了PHP中lang\ClassLoader::defineType方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::defineType方法的具体用法?PHP ClassLoader::defineType怎么用?PHP ClassLoader::defineType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lang\ClassLoader的用法示例。


在下文中一共展示了ClassLoader::defineType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: define

 /**
  * Defines a type
  *
  * @param  string $declaration
  * @param  string[] $extends
  * @return lang.XPClass
  */
 protected function define($declaration, $extends = [Object::class])
 {
     if (!isset(self::$fixtures[$declaration])) {
         $definition = ['kind' => 'class', 'extends' => $extends, 'implements' => [], 'use' => [], 'imports' => [Identity::class => null]];
         self::$fixtures[$declaration] = ClassLoader::defineType(nameof($this) . sizeof(self::$fixtures), $definition, $declaration);
     }
     return self::$fixtures[$declaration];
 }
开发者ID:xp-forge,项目名称:mirrors,代码行数:15,代码来源:TypeDefinition.class.php

示例2: type

 /**
  * Defines an anonymous type
  *
  * @param  string $decl Type declaration
  * @param  int $modifiers
  * @return lang.XPClass
  */
 protected function type($decl = null, $modifiers = '')
 {
     if (!isset(self::$fixtures[$decl])) {
         $definition = ['modifiers' => $modifiers, 'kind' => 'class', 'extends' => [Object::class], 'implements' => [], 'use' => [CompareTo::class], 'imports' => [Value::class => null]];
         self::$fixtures[$decl] = ClassLoader::defineType(get_class($this) . sizeof(self::$fixtures), $definition, $decl);
     }
     return self::$fixtures[$decl];
 }
开发者ID:xp-framework,项目名称:core,代码行数:15,代码来源:TypeDefinition.class.php

示例3: anonymous_instance_from_abstract_base_class

 public function anonymous_instance_from_abstract_base_class()
 {
     \lang\ClassLoader::defineType('net.xp_lang.tests.Command', ['kind' => 'abstract class', 'extends' => ['lang.Object'], 'implements' => ['lang.Runnable'], 'use' => []], []);
     $command = $this->run('return new net.xp_lang.tests.Command() {
   public void run() {
     throw new lang.MethodNotImplementedException("run");
   }
 };');
     $this->assertAnonymousInstanceOf('net.xp_lang.tests.Command', $command);
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:10,代码来源:InstanceCreationTest.class.php

示例4: newinstance

function newinstance($spec, $args, $def = null)
{
    static $u = 0;
    if ('#' === $spec[0]) {
        $p = strrpos($spec, ' ');
        $annotations = substr($spec, 0, $p) . ' ';
        $spec = substr($spec, $p + 1);
    } else {
        $annotations = '';
    }
    // Create unique name
    $n = "·" . ++$u;
    if (0 === strncmp($spec, 'php.', 4)) {
        $spec = substr($spec, 4);
    } else {
        if (false === strpos($spec, '.')) {
            $spec = \lang\XPClass::nameOf($spec);
        }
    }
    // Handle generics, PHP types and all others.
    if (strstr($spec, '<')) {
        $class = \lang\Type::forName($spec);
        $type = $class->literal();
        $generic = xp::$meta[$class->getName()]['class'][DETAIL_GENERIC];
    } else {
        if (false === strpos($spec, '.')) {
            $type = $spec;
            $generic = null;
        } else {
            try {
                $type = xp::$loader->loadClass0($spec);
            } catch (\lang\ClassLoadingException $e) {
                xp::error($e->getMessage());
            }
            $generic = null;
        }
    }
    $name = strtr($type, '\\', '.') . $n;
    if (interface_exists($type)) {
        $decl = ['kind' => 'class', 'extends' => ['lang.Object'], 'implements' => ['\\' . $type], 'use' => []];
    } else {
        if (trait_exists($type)) {
            $decl = ['kind' => 'class', 'extends' => ['lang.Object'], 'implements' => [], 'use' => ['\\' . $type]];
        } else {
            $decl = ['kind' => 'class', 'extends' => ['\\' . $type], 'implements' => [], 'use' => []];
        }
    }
    $defined = \lang\ClassLoader::defineType($annotations . $name, $decl, $def);
    if (false === strpos($type, '\\')) {
        xp::$cn[$type . $n] = $spec . $n;
    }
    if ($generic) {
        \lang\XPClass::detailsForClass($name);
        xp::$meta[$name]['class'][DETAIL_GENERIC] = $generic;
    }
    if ($defined->hasConstructor()) {
        return $defined->getConstructor()->newInstance($args);
    } else {
        return $defined->newInstance();
    }
}
开发者ID:johannes85,项目名称:core,代码行数:61,代码来源:lang.base.php

示例5: declareType

 /**
  * Creates a type from a given type body
  *
  * @param  string[] $interfaces
  * @param  string $body The string `<T>` is replaced by the unique type name
  * @return lang.XPClass
  */
 protected function declareType($interfaces, $body)
 {
     $declaration = ['kind' => 'class', 'extends' => ['\\lang\\Object'], 'implements' => $interfaces, 'use' => []];
     $unique = typeof($this)->getSimpleName() . '_' . $this->name;
     return ClassLoader::defineType($unique, $declaration, strtr($body, ['<T>' => $unique]));
 }
开发者ID:xp-forge,项目名称:partial,代码行数:13,代码来源:PartialTest.class.php

示例6: defineImplementation

 public static function defineImplementation()
 {
     $implementation = static::implementation();
     self::$fixture = ClassLoader::defineType($implementation . 'Instance', ['kind' => 'class', 'extends' => [], 'implements' => [], 'use' => [$implementation]], '{ public $buffer; public function __construct($initial) { $this->buffer= (string)$initial; }}');
 }
开发者ID:xp-forge,项目名称:wrappers,代码行数:5,代码来源:ImplementationTest.class.php


注:本文中的lang\ClassLoader::defineType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。