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


PHP ClassLoader::defineClass方法代码示例

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


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

示例1: __static

    static function __static()
    {
        self::$rewriter = \lang\ClassLoader::defineClass('InliningOptimization··Rewriter', 'xp.compiler.ast.Visitor', [], '{
      protected $replacements;
      protected $protect;

      public function __construct($replacements, $protect) {
        $this->replacements= $replacements;
        $this->protect= $protect;
      }

      protected function visitMethodCall(\\xp\\compiler\\ast\\MethodCallNode $node) {
        if ($node->name === $this->protect) $node->inlined= true;
        return parent::visitMethodCall($node);
      }

      protected function visitStaticMethodCall(\\xp\\compiler\\ast\\StaticMethodCallNode $node) {
        if ($node->name === $this->protect) $node->inlined= true;
        return parent::visitStaticMethodCall($node);
      }

      protected function visitVariable(\\xp\\compiler\\ast\\VariableNode $node) {
        return isset($this->replacements[$node->name])
          ? clone $this->replacements[$node->name]
          : $node
        ;
      } 
    }');
    }
开发者ID:xp-lang,项目名称:compiler,代码行数:29,代码来源:InliningOptimization.class.php

示例2: defineCommandClass

 public static function defineCommandClass()
 {
     self::$class = ClassLoader::defineClass('util.cmd.unittest.BatchImport', Command::class, [], ['run' => function () {
     }]);
     self::$global = ClassLoader::defineClass('BatchImport', Command::class, [], ['run' => function () {
     }]);
 }
开发者ID:xp-framework,项目名称:command,代码行数:7,代码来源:CommandsTest.class.php

示例3: defineClass

 /**
  * Helper method
  * @param   string name
  * @param   string parent
  * @param   string[] interfaces
  * @return  lang.XPClass class
  * @throws  unittest.AssertionFailedError
  */
 protected function defineClass($name, $parent, $interfaces, $bytes)
 {
     if (class_exists(\xp::reflect($name), false)) {
         $this->fail('Class "' . $name . '" may not exist!');
     }
     return \lang\ClassLoader::defineClass($name, $parent, $interfaces, $bytes);
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:15,代码来源:RuntimeClassDefinitionTest.class.php

示例4: defineLayout

 public static function defineLayout()
 {
     self::$layout = ClassLoader::defineClass(self::class . '_Layout', Object::class, [WebLayout::class], '{
   public function mappedApplications($profile= null) { /* Intentionally empty */ }
   public function staticResources($profile= null) { /* Intentionally empty */ }
 }');
 }
开发者ID:xp-framework,项目名称:scriptlet,代码行数:7,代码来源:SourceTest.class.php

示例5: defineExiterClass

 public static function defineExiterClass()
 {
     self::$exiterClass = \lang\ClassLoader::defineClass('net.xp_framework.unittest.core.Exiter', 'lang.Object', array(), '{
   public function __construct() { throw new SystemExit(0); }
   public static function doExit() { new self(); }
 }');
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:7,代码来源:SystemExitTest.class.php

示例6: create

 /**
  * Creates a new instance creation fluent interface for a given class
  *
  * @param  lang.mirrors.TypeMirror|lang.XPClass|string $type
  * @return lang.XPClass
  */
 public static final function typeOf($type)
 {
     $mirror = $type instanceof TypeMirror ? $type : new TypeMirror($type);
     $type = $mirror->name();
     if (!isset(self::$creations[$type])) {
         if (!$mirror->kind()->isClass() || $mirror->modifiers()->isAbstract()) {
             throw new IllegalArgumentException('Class ' . $type . ' is not instantiable');
         }
         $constructor = $mirror->constructor();
         if (!$constructor->present()) {
             throw new IllegalArgumentException('Class ' . $type . ' does not have a constructor');
         }
         $setters = $args = '';
         foreach ($constructor->parameters() as $parameter) {
             $name = $parameter->name();
             if ($parameter->isOptional()) {
                 $setters .= 'public $' . $name . '= ' . var_export($parameter->defaultValue(), true) . ';';
             } else {
                 $setters .= 'public $' . $name . ';';
             }
             $setters .= "/**\n * @param " . $parameter->type() . "\n * @return self\n*/";
             $setters .= 'public function ' . $name . '($value) { $this->' . $name . '= $value; return $this; }';
             $args .= ', $this->' . $name;
         }
         self::$creations[$type] = ClassLoader::defineClass($type . 'Creation', 'lang.partial.InstanceCreation', [], '{
     /** @return ' . $mirror->name() . ' */
     public function create() { return new \\' . $mirror->reflect->name . '(' . substr($args, 2) . '); }
     ' . $setters . '
   }');
     }
     return self::$creations[$type];
 }
开发者ID:xp-forge,项目名称:partial,代码行数:38,代码来源:InstanceCreationV7.class.php

示例7: __construct

    static function __static()
    {
        // For singletonInstance test
        ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousSingleton', 'lang.Object', array(), '{
      protected static $instance= NULL;

      static function getInstance() {
        if (!isset(self::$instance)) self::$instance= new AnonymousSingleton();
        return self::$instance;
      }
    }');
        // For returnNewObject and returnNewObjectViaReflection tests
        ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousList', 'lang.Object', array(), '{
      public function __construct() {
        \\net\\xp_framework\\unittest\\core\\ReferencesTest::registry("list", $this);
      }
    }');
        ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousFactory', 'lang.Object', array(), '{
      static function factory() {
        return new AnonymousList();
      }
    }');
        ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousNewInstanceFactory', 'lang.Object', array(), '{
      static function factory() {
        return XPClass::forName("net.xp_framework.unittest.core.AnonymousList")->newInstance();
      }
    }');
    }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:28,代码来源:ReferencesTest.class.php

示例8: dummyConnectionClass

    public static function dummyConnectionClass()
    {
        self::$conn = \lang\ClassLoader::defineClass('RestClientExecutionTest_Connection', 'peer.http.HttpConnection', array(), '{
      protected $result= NULL;
      protected $exception= NULL;

      public function __construct($status, $body, $headers) {
        parent::__construct("http://test");
        if ($status instanceof Throwable) {
          $this->exception= $status;
        } else {
          $this->result= "HTTP/1.1 ".$status."\\r\\n";
          foreach ($headers as $name => $value) {
            $this->result.= $name.": ".$value."\\r\\n";
          }
          $this->result.= "\\r\\n".$body;
        }
      }
      
      public function send(HttpRequest $request) {
        if ($this->exception) {
          throw $this->exception;
        } else {
          return new HttpResponse(new MemoryInputStream($this->result));
        }
      }
    }');
    }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:28,代码来源:RestClientExecutionTest.class.php

示例9: defineExiterClass

 public static function defineExiterClass()
 {
     self::$exiterClass = ClassLoader::defineClass('net.xp_framework.unittest.core.Exiter', Object::class, [], '{
   public function __construct() { throw new \\lang\\SystemExit(0); }
   public static function doExit() { new self(); }
 }');
 }
开发者ID:xp-framework,项目名称:core,代码行数:7,代码来源:SystemExitTest.class.php

示例10: dummyConnectionClass

    public static function dummyConnectionClass()
    {
        self::$conn = ClassLoader::defineClass('EndpointExecutionTest_Connection', 'peer.http.HttpConnection', [], '{
      private $result, $exception;

      public function __construct($status, $body, $headers) {
        parent::__construct("http://test");
        if ($status instanceof \\lang\\Throwable) {
          $this->exception= $status;
        } else {
          $this->result= "HTTP/1.1 ".$status."\\r\\n";
          foreach ($headers as $name => $value) {
            $this->result.= $name.": ".$value."\\r\\n";
          }
          $this->result.= "\\r\\n".$body;
        }
      }
      
      public function send(\\peer\\http\\HttpRequest $request) {
        if ($this->exception) {
          throw $this->exception;
        } else {
          return new \\peer\\http\\HttpResponse(new \\io\\streams\\MemoryInputStream($this->result));
        }
      }
    }');
    }
开发者ID:xp-framework,项目名称:rest,代码行数:27,代码来源:ExecutionTest.class.php

示例11: __construct

 /**
  * Constructor
  *
  * @param   string bytes method sourcecode
  */
 public function __construct($bytes)
 {
     $name = 'xp.unittest.DynamicallyGeneratedTestCase·' . self::$uniqId++;
     $this->testClass = \lang\ClassLoader::defineClass($name, 'unittest.TestCase', array(), '{
   #[@test] 
   public function run() { ' . $bytes . ' }
 }');
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:13,代码来源:EvaluationSource.class.php

示例12: defineResult

 public static function defineResult()
 {
     self::$result = \lang\ClassLoader::defineClass('FileManagerTestEmitterResult', 'lang.Object', ['xp.compiler.emit.EmitterResult'], '{
   protected $type= null;
   public function __construct($name) { $this->type= new \\xp\\compiler\\types\\TypeReference(new \\xp\\compiler\\types\\TypeName($name)); }
   public function type() { return $this->type; }
   public function extension() { return ".test"; }
 }');
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:9,代码来源:FileManagerTest.class.php

示例13: defineVisitor

 public static function defineVisitor()
 {
     self::$visitor = ClassLoader::defineClass('VisitorTest··Visitor', 'xp.compiler.ast.Visitor', [], '{
   public $visited= array();
   public function visitOne($node) {
     $this->visited[]= $node;
     return parent::visitOne($node);
   }
 }');
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:10,代码来源:VisitorTest.class.php

示例14: __static

 static function __static()
 {
     self::$fileStreamAdapter = \lang\ClassLoader::defineClass('FileStreamAdapter', 'io.File', array(), '{
   protected $stream= NULL;
   public function __construct($stream) { $this->stream= $stream; }
   public function exists() { return NULL !== $this->stream; }
   public function getURI() { return Streams::readableUri($this->stream); }
   public function getInputStream() { return $this->stream; }
 }');
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:10,代码来源:FileBasedPropertiesTest.class.php

示例15: __construct

 static function __static()
 {
     self::$fileStreamAdapter = ClassLoader::defineClass('FileStreamAdapter', File::class, [], '{
   protected $stream= null;
   public function __construct($stream) { $this->stream= $stream; }
   public function exists() { return null !== $this->stream; }
   public function getURI() { return \\io\\streams\\Streams::readableUri($this->stream); }
   public function getInputStream() { return $this->stream; }
 }');
 }
开发者ID:johannes85,项目名称:core,代码行数:10,代码来源:FileBasedPropertiesTest.class.php


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