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


PHP newinstance函数代码示例

本文整理汇总了PHP中newinstance函数的典型用法代码示例。如果您正苦于以下问题:PHP newinstance函数的具体用法?PHP newinstance怎么用?PHP newinstance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: get_contents_read_returns_less_than_size

 public function get_contents_read_returns_less_than_size()
 {
     $f = new File(Streams::readableFd(newinstance(MemoryInputStream::class, ['Test'], ['read' => function ($size = 4096) {
         return parent::read(min(1, $size));
     }])));
     $this->assertEquals('Test', FileUtil::getContents($f));
 }
开发者ID:johannes85,项目名称:core,代码行数:7,代码来源:FileUtilTest.class.php

示例2: calls_equals_method_in_maps

 public function calls_equals_method_in_maps($value, $outcome)
 {
     $object = newinstance('lang.Object', [], ['equals' => function ($cmp) {
         return 'Test' === $cmp;
     }]);
     $this->assertEquals($outcome, (new IsEqual(['key' => $object]))->matches($value));
 }
开发者ID:xp-forge,项目名称:match,代码行数:7,代码来源:IsEqualTest.class.php

示例3: __static

 static function __static()
 {
     self::$UNKNOWN = newinstance(__CLASS__, [0.0, 0.0, []], '{
   static function __static() { }
   public function toString() { return "com.maxmind.geoip.Location(UNKNOWN)"; }
 }');
 }
开发者ID:xp-forge,项目名称:geoip,代码行数:7,代码来源:Location.class.php

示例4: setUp

 /**
  * Sets up test case and backups Console::$err stream.
  *
  */
 public function setUp()
 {
     $this->cat = (new LogCategory('default'))->withAppender((new ConsoleAppender())->withLayout(newinstance(Layout::class, [], ['format' => function (LoggingEvent $event) {
         return implode(' ', $event->getArguments());
     }])));
     $this->stream = Console::$err->getStream();
 }
开发者ID:johannes85,项目名称:core,代码行数:11,代码来源:ConsoleAppenderTest.class.php

示例5: compile

 /**
  * Compile and then run sourcecode
  *
  * @param   string source
  * @return  lang.Runnable
  */
 protected function compile($source)
 {
     $decl = '
 import integrationtests.ArrayExtensions;
 
 class FixturePrimitiveExtensionMethodsIntegrationTest·%d implements Runnable {
   public var run() {
     %s
   }
 }';
     $emitter = new V54Emitter();
     $task = new CompilationTask(new StringSource(sprintf($decl, $this->counter++, $source), self::$syntax, $this->name), new NullDiagnosticListener(), newinstance(FileManager::class, [$this->getClass()->getClassLoader()], '{
     protected $cl;
     
     public function __construct($cl) {
       $this->cl= $cl;
     }
     
     public function findClass($qualified) {
       return new FileSource($this->cl->getResourceAsStream("net/xp_lang/tests/integration/src/".strtr($qualified, ".", "/").".xp"));
     }
     
     public function write($r, File $target) {
       // DEBUG $r->writeTo(Console::$out->getStream());
       $r->executeWith(array());   // Defines the class
     }
   }'), $emitter);
     $type = $task->run();
     return XPClass::forName($type->name())->newInstance();
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:36,代码来源:PrimitiveExtensionMethodsIntegrationTest.class.php

示例6: noTimeout

 public function noTimeout()
 {
     $r = $this->suite->runTest(newinstance(TestCase::class, ['fixture'], ['#[@test, @limit(time= 0.010)] fixture' => function () {
         /* No timeout */
     }]));
     $this->assertEquals(1, $r->successCount());
 }
开发者ID:xp-framework,项目名称:unittest,代码行数:7,代码来源:LimitTest.class.php

示例7: setupRecords

    /**
     * Setup record handlers
     *
     * @see     http://infocenter.sybase.com/help/topic/com.sybase.dc35823_1500/html/uconfig/uconfig111.htm
     * @see     http://infocenter.sybase.com/help/topic/com.sybase.dc38421_1500/html/ntconfig/ntconfig80.htm
     * @return  [:rdbms.tds.TdsRecord] handlers
     */
    protected function setupRecords()
    {
        $records[self::T_NUMERIC] = newinstance('rdbms.tds.TdsRecord', array(), '{
        public function unmarshal($stream, $field) {
          if (-1 === ($len= $stream->getByte()- 1)) return NULL;
          $pos= $stream->getByte();
          $bytes= $stream->read($len);
          if ($i= ($len % 4)) {
            $bytes= str_repeat("\\0", 4 - $i).$bytes;
            $len+= 4 - $i;
          }
          for ($n= 0, $m= $pos ? -1 : 1, $i= $len- 4; $i >= 0; $i-= 4, $m= bcmul($m, "4294967296", 0)) {
            $n= bcadd($n, bcmul(sprintf("%u", current(unpack("N", substr($bytes, $i, 4)))), $m, 0), 0);
          }
          return $this->toNumber($n, $field["scale"], $field["prec"]);
        }
      }');
        $records[self::T_DECIMAL] = $records[self::T_NUMERIC];
        $records[self::T_BINARY] = newinstance('rdbms.tds.TdsRecord', array(), '{
        public function unmarshal($stream, $field) {
          if (0 === ($len= $stream->getByte())) return NULL;
          $string= $stream->read($len);
          return iconv($field["conv"], "iso-8859-1", substr($string, 0, strcspn($string, "\\0")));
        }
      }');
        $records[self::T_IMAGE] = newinstance('rdbms.tds.TdsRecord', array(), '{
        public function unmarshal($stream, $field) {
          $has= $stream->getByte();
          if ($has !== 16) return NULL; // Seems to always be 16 - obsolete?

          $stream->read(24);  // Skip 16 Byte TEXTPTR, 8 Byte TIMESTAMP
          $len= $stream->getLong();
          if (0 === $len) return NULL;

          $r= $stream->read($len);

          // HACK - cannot figure out why UNITEXT is not being returned as such
          // but as IMAGE type with different inside layout!
          return iconv(
            strlen($r) > 1 && "\\0" === $r{1} ? "ucs-2le" : $field["conv"],
            "iso-8859-1",
            $r
          );
        }
      }');
        $records[self::T_VARBINARY] = newinstance('rdbms.tds.TdsRecord', array(), '{
        public function unmarshal($stream, $field) {
          if (0 === ($len= $stream->getByte())) return NULL;

          return iconv($field["conv"], "iso-8859-1", $stream->read($len));
        }
      }');
        $records[self::T_LONGBINARY] = newinstance('rdbms.tds.TdsRecord', array(), '{
        public function unmarshal($stream, $field) {
          $len= $stream->getLong();
          return $stream->getString($len / 2);
        }
      }');
        return $records;
    }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:67,代码来源:TdsV5Protocol.class.php

示例8: newConnection

 protected function newConnection(URL $url)
 {
     return newinstance(Connection::class, [$url], ['response' => '', 'sent' => null, 'in' => null, 'out' => null, '__construct' => function ($url) {
         parent::__construct($url);
         $this->_connect($url);
         // FIXME: Required for unittest
     }, '_connect' => function (URL $url) {
         $this->in = new StringReader(new MemoryInputStream($this->response));
         $this->out = new StringWriter(new MemoryOutputStream());
     }, '_disconnect' => function () {
         $this->sent = $this->out->getStream()->getBytes();
         $this->in = null;
         $this->out = null;
     }, 'setResponseBytes' => function ($s) {
         $this->in = new StringReader(new MemoryInputStream($s));
         $this->response = $s;
     }, 'readSentBytes' => function () {
         // Case of DISCONNECT
         if (null !== $this->sent) {
             $sent = $this->sent;
             $this->sent = null;
             return $sent;
         }
         return $this->out->getStream()->getBytes();
     }, 'clearSentBytes' => function () {
         $this->_connect(new URL());
         $this->sent = null;
     }]);
 }
开发者ID:xp-forge,项目名称:stomp,代码行数:29,代码来源:BaseTest.class.php

示例9: hashCodeCounter

 /** @return lang.Object */
 protected function hashCodeCounter()
 {
     return newinstance(Object::class, [], ['invoked' => 0, 'hashCode' => function () {
         $this->invoked++;
         return parent::hashCode();
     }]);
 }
开发者ID:xp-framework,项目名称:collections,代码行数:8,代码来源:HashTableTest.class.php

示例10: getNameCase

 /**
  * Returns a testcase with getName() as test method
  *
  * @return  unittest.TestCase
  */
 protected function getNameCase()
 {
     return newinstance('unittest.TestCase', ['getName'], '{
   #[@test]
   public function getName($compound= FALSE) { }
 }');
 }
开发者ID:johannes85,项目名称:core,代码行数:12,代码来源:SpecialMethodsTest.class.php

示例11: __static

 static function __static()
 {
     self::$EQUALS = newinstance(__CLASS__, array(1, 'EQUALS', '='), '{
     static function __static() {}
   }');
     self::$NOT_EQUALS = newinstance(__CLASS__, array(1, 'NOT_EQUALS', '!='), '{
     static function __static() {}
   }');
     self::$GREATER_THAN = newinstance(__CLASS__, array(1, 'GREATER_THAN', '>'), '{
     static function __static() {}
   }');
     self::$GREATER_EQUALS = newinstance(__CLASS__, array(1, 'GREATER_EQUALS', '>='), '{
     static function __static() {}
   }');
     self::$LESS_THAN = newinstance(__CLASS__, array(1, 'LESS_THAN', '<'), '{
     static function __static() {}
   }');
     self::$LESS_EQUALS = newinstance(__CLASS__, array(1, 'LESS_EQUALS', '<='), '{
     static function __static() {}
   }');
     self::$IN = newinstance(__CLASS__, array(1, 'IN', 'in'), '{
     static function __static() {}
     function forValue($value) {
       return $this->op." (".implode(", ", (array)$value).")";
     }
   }');
     self::$NOT_IN = newinstance(__CLASS__, array(1, 'NOT_IN', 'not in'), '{
     static function __static() {}
     function forValue($value) {
       return $this->op." (".implode(", ", (array)$value).")";
     }
   }');
 }
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:33,代码来源:JiraQueryOp.class.php

示例12: newinstance

 public function newinstance()
 {
     $runnable = newinstance(Runnable::class, [], ['run' => function () {
         return 'Test';
     }]);
     $this->assertEquals('Test', cast($runnable, Runnable::class)->run());
 }
开发者ID:johannes85,项目名称:core,代码行数:7,代码来源:CastingTest.class.php

示例13: newinstance

 public function newinstance()
 {
     $runnable = newinstance('lang.Runnable', array(), '{
     public function run() { return "RUN"; }
   }');
     $this->assertEquals('RUN', cast($runnable, 'lang.Runnable')->run());
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:7,代码来源:CastingTest.class.php

示例14: baseImpl

    /**
     * Creates underlying base for class loader, e.g. a directory or a .XAR file
     *
     * @return  net.xp_framework.unittest.reflection.ClassFromUriBase
     */
    protected static function baseImpl()
    {
        return newinstance('net.xp_framework.unittest.reflection.ClassFromUriBase', array(), '{
      protected $t= NULL;

      public function create() {
        $this->t= new \\io\\Folder(\\lang\\System::tempDir(), "fsclt");
        $this->t->create();
      }

      public function delete() {
        $this->t->unlink();
      }

      public function newFile($name, $contents) {
        $file= new \\io\\File($this->t, $name);
        $path= new \\io\\Folder($file->getPath());
        $path->exists() || $path->create();

        \\io\\FileUtil::setContents($file, $contents);
      }

      public function path() {
        return rtrim($this->t->getURI(), DIRECTORY_SEPARATOR);
      }
    }');
    }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:32,代码来源:ClassFromFileSystemTest.class.php

示例15: setUp

 /**
  * Sets up test case
  */
 public function setUp()
 {
     $this->fixture = newinstance(ImapStore::class, [], ['connect' => [], '_connect' => function ($mbx, $user, $pass, $flags) {
         $this->connect = ['mbx' => $mbx, 'user' => $user, 'pass' => $pass, 'flags' => $flags];
         return true;
     }]);
 }
开发者ID:xp-framework,项目名称:mail,代码行数:10,代码来源:ImapStoreTest.class.php


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