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


PHP Generator类代码示例

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


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

示例1: getString

 /**
  * Covert File to HTML string
  */
 function getString()
 {
     $input = new Generator();
     $name = $this->getNameAttributeString();
     $value = $this->getValue();
     return $input->newInput('file', $name, $value, $this->getAttributes())->getString();
 }
开发者ID:typerocket,项目名称:laravel,代码行数:10,代码来源:File.php

示例2: execute

 private function execute(\Generator $generator)
 {
     $stack = [];
     //This is basically a simple iterative in-order tree traversal algorithm
     $yielded = $generator->current();
     //This is a depth-first traversal
     while ($yielded instanceof \Generator) {
         //... push it to the stack
         $stack[] = $generator;
         $generator = $yielded;
         $yielded = $generator->current();
     }
     while (!empty($stack)) {
         //We've reached the end of the branch, let's step back on the stack
         $generator = array_pop($stack);
         //step the generator
         $yielded = $generator->send($yielded);
         //Depth-first traversal
         while ($yielded instanceof \Generator) {
             //... push it to the stack
             $stack[] = $generator;
             $generator = $yielded;
             $yielded = $generator->current();
         }
     }
     return $yielded;
 }
开发者ID:bugadani,项目名称:Recursor,代码行数:27,代码来源:Recursor.php

示例3: __construct

 /**
  * @param Generator $generator
  * @param           $addPid
  */
 public function __construct(Generator $generator, $addPid)
 {
     $this->requestId = $generator->getRequestId();
     if ($addPid) {
         $this->pid = getmypid();
     }
 }
开发者ID:mhor,项目名称:SoclozMonitoringBundle,代码行数:11,代码来源:RequestId.php

示例4: generateSql

 public function generateSql()
 {
     $namespace = \Zule\Tools\Config::zc()->framework->application_namespace;
     $system = 'Zule';
     $tables = $this->settings->getTables();
     foreach ($tables as $table) {
         $s = new \Smarty();
         $tableName = $table->getName();
         // generate model
         $s->assign('model_name', $_POST["class_{$tableName}"]);
         $s->assign('namespace', $namespace);
         $s->assign('system', $system);
         $s->assign('class_name', $_POST["class_{$tableName}"]);
         $s->assign('extend_path', '\\Zule\\Models\\Model');
         $s->assign('impl_date', date('Y-m-d H:i:s'));
         $s->assign('use_unsafe_setters', 0);
         $s->assign('table_name', $tableName);
         $columns = $table->getColumns();
         $s->assign('columns', $columns);
         $s->assign('primary_key', $table->getPrimaryKey());
         $gen = new Generator("../models/" . $_POST["class_{$tableName}"] . '.php');
         $gen->generate($s, 'model_sql');
         $gen = new Generator("../models/Data/" . $_POST["class_{$tableName}"] . '.php');
         $gen->generate($s, 'gateway_sql');
     }
 }
开发者ID:ryanknu,项目名称:zule-framework,代码行数:26,代码来源:model_generator.php

示例5: stackedCoroutine

 /**
  * Resolves yield calls tree
  * and gives a return value if outcome of yield is CoroutineReturnValue instance
  *
  * @param \Generator $coroutine nested coroutine tree
  * @return \Generator
  */
 private static function stackedCoroutine(\Generator $coroutine)
 {
     $stack = new \SplStack();
     while (true) {
         $value = $coroutine->current();
         // nested generator/coroutine
         if ($value instanceof \Generator) {
             $stack->push($coroutine);
             $coroutine = $value;
             continue;
         }
         // coroutine end or value is a value object instance
         if (!$coroutine->valid() || $value instanceof CoroutineReturnValue) {
             // if till this point, there are no coroutines in a stack thatn stop here
             if ($stack->isEmpty()) {
                 return;
             }
             $coroutine = $stack->pop();
             $value = $value instanceof CoroutineReturnValue ? $value->getValue() : null;
             $coroutine->send($value);
             continue;
         }
         $coroutine->send((yield $coroutine->key() => $value));
     }
 }
开发者ID:zavalit,项目名称:corouser,代码行数:32,代码来源:StackedCoroutineTrait.php

示例6: buildUser

 public function buildUser(Request $request, Generator $generator)
 {
     if (empty($request->userName)) {
         throw new \InvalidArgumentException();
     }
     $password = $request->password ?: $generator->generatePassword();
     $hashedPassword = md5(self::SALT . $password);
     return new User($request->userName, $password, $hashedPassword);
 }
开发者ID:JayLeeroy,项目名称:kata-base-php,代码行数:9,代码来源:UserBuilder.php

示例7: testGeneratingUuidShouldReturnDifferentResultEveryTime

 /**
  * Generating UUID should return different results every time
  *
  * @covers Mixpanel\Uuid\Generator::generate
  * @covers Mixpanel\Uuid\Generator::ticksEntropy
  * @covers Mixpanel\Uuid\Generator::uaEntropy
  * @covers Mixpanel\Uuid\Generator::randomEntropy
  * @covers Mixpanel\Uuid\Generator::ipEntropy
  */
 public function testGeneratingUuidShouldReturnDifferentResultEveryTime()
 {
     $uuids = array();
     for ($i = 0; $i < 100; $i++) {
         $uuid = $this->generator->generate('user-agent', '127.0.0.1');
         $this->assertNotContains($uuid, $uuids);
         $uuids[] = $uuid;
     }
 }
开发者ID:wpfw,项目名称:mixpanel-php,代码行数:18,代码来源:GeneratorTest.php

示例8: create

 public static function create($locale = self::DEFAULT_LOCALE)
 {
     $generator = new Generator();
     foreach (static::$defaultProviders as $provider) {
         $providerClassName = self::getProviderClassname($provider, $locale);
         $generator->addProvider(new $providerClassName($generator));
     }
     return $generator;
 }
开发者ID:nbremont,项目名称:Faker,代码行数:9,代码来源:Factory.php

示例9: run

 /**
  * [run 协程调度]
  * @param \Generator $gen
  * @throws \Exception
  */
 public function run(\Generator $gen)
 {
     while (true) {
         try {
             /* 异常处理 */
             if ($this->exception) {
                 $gen->throw($this->exception);
                 $this->exception = null;
                 continue;
             }
             $value = $gen->current();
             //                Logger::write(__METHOD__ . " value === " . var_export($value, true), Logger::INFO);
             /* 中断内嵌 继续入栈 */
             if ($value instanceof \Generator) {
                 $this->corStack->push($gen);
                 //                    Logger::write(__METHOD__ . " corStack push ", Logger::INFO);
                 $gen = $value;
                 continue;
             }
             /* if value is null and stack is not empty pop and send continue */
             if (is_null($value) && !$this->corStack->isEmpty()) {
                 //                    Logger::write(__METHOD__ . " values is null stack pop and send ", Logger::INFO);
                 $gen = $this->corStack->pop();
                 $gen->send($this->callbackData);
                 continue;
             }
             if ($value instanceof ReturnValue) {
                 $gen = $this->corStack->pop();
                 $gen->send($value->getValue());
                 // end yeild
                 //                    Logger::write(__METHOD__ . " yield end words == " . var_export($value, true), Logger::INFO);
                 continue;
             }
             /* 中断内容为异步IO 发包 返回 */
             if ($value instanceof \Swoole\Client\IBase) {
                 //async send push gen to stack
                 $this->corStack->push($gen);
                 $value->send(array($this, 'callback'));
                 return;
             }
             /* 出栈,回射数据 */
             if ($this->corStack->isEmpty()) {
                 return;
             }
             //                Logger::write(__METHOD__ . " corStack pop ", Logger::INFO);
             $gen = $this->corStack->pop();
             $gen->send($value);
         } catch (EasyWorkException $e) {
             if ($this->corStack->isEmpty()) {
                 throw $e;
             }
             $gen = $this->corStack->pop();
             $this->exception = $e;
         }
     }
 }
开发者ID:vzina,项目名称:esaywork,代码行数:61,代码来源:Task.php

示例10: checkResult

 private function checkResult(\Generator $generator, Channel $channel)
 {
     if (!$generator->valid()) {
         foreach ($this->actions as list(, $gen, , $undo)) {
             if ($gen && $gen !== $generator) {
                 $undo($gen->current());
             }
         }
         return [$generator->getReturn(), $channel];
     }
     return false;
 }
开发者ID:crystalplanet,项目名称:redshift,代码行数:12,代码来源:ChannelSelector.php

示例11: reduce

 /**
  * When you need to return Result from your function, and it also depends on another
  * functions returning Results, you can make it a generator function and yield
  * values from dependant functions, this pattern makes code less bloated with
  * statements like this:
  * $res = something();
  * if ($res instanceof Ok) {
  *     $something = $res->unwrap();
  * } else {
  *     return $res;
  * }
  *
  * Instead you can write:
  * $something = (yield something());
  *
  * @see /example.php
  *
  * @param \Generator $resultsGenerator Generator that produces Result instances
  * @return Result
  */
 public static function reduce(\Generator $resultsGenerator)
 {
     /** @var Result $result */
     $result = $resultsGenerator->current();
     while ($resultsGenerator->valid()) {
         if ($result instanceof Err) {
             return $result;
         }
         $tmpResult = $resultsGenerator->send($result->unwrap());
         if ($resultsGenerator->valid()) {
             $result = $tmpResult;
         }
     }
     return $result;
 }
开发者ID:nikita2206,项目名称:result,代码行数:35,代码来源:Result.php

示例12: createUserWithGeneratedPassword

 /**
  * Create user with generated password.
  *
  * @param $username
  *
  * @return User
  */
 public function createUserWithGeneratedPassword($username, $hashCost = 10, $salt = '')
 {
     $randomPassword = $this->generator->generateRandomPassword($this->minPasswordLength, $this->maxPasswordLength);
     $hashedPassword = $this->hashPassword($randomPassword, PASSWORD_DEFAULT, $hashCost, $salt);
     $user = new User($username, $randomPassword, $hashedPassword);
     return $user;
 }
开发者ID:mwnn,项目名称:kata-base-php,代码行数:14,代码来源:UserBuilder.php

示例13: testSetData

 public function testSetData()
 {
     /**
      *  ['merchantID'] string This is the merchantID assigned by PayCo.
      *  ['storeID'] string This is the store ID of a merchant.
      *  ['logEnabled'] string Should logging be enabled
      *  ['logLevel'] int Log level
      *  ['logLocationMain'] string Main log Location
      *  ['logLocationRequest'] string Log location for API requests
      *  ['logLocationMNS'] string Log for MNS asynchronous callbacks
      *  ['logLocationCallbacks'] string Log location for synchronous callbacks
      *  ['defaultRiskClass'] string Default risk class
      */
     $config = array('merchantID' => $this->faker->randomNumber(8), 'storeID' => $this->faker->word, 'logEnabled' => $this->faker->boolean, 'logLevel' => Config::LOG_LEVEL_ERROR, 'logLocationMain' => $this->faker->word, 'logLocationRequest' => $this->faker->word, 'logLocationMNS' => $this->faker->word, 'logLocationCallbacks' => $this->faker->word, 'defaultRiskClass' => 2, 'defaultLocale' => strtoupper($this->faker->languageCode));
     $configObject = new Config();
     $configObject->setData($config);
     $this->assertEquals($config['merchantID'], $configObject->getMerchantID(), "Merchant ID was set incorrectly");
     $this->assertEquals($config['storeID'], $configObject->getStoreID(), "Store ID was set incorrectly");
     $this->assertEquals($config['logEnabled'], $configObject->getLogEnabled(), "Log Enabled was set incorrectly");
     $this->assertEquals($config['logLevel'], $configObject->getLogLevel(), "Log Level was set incorrectly");
     $this->assertEquals($config['logLocationMain'], $configObject->getLogLocationMain(), "Main Log location was set incorrectly");
     $this->assertEquals($config['logLocationRequest'], $configObject->getLogLocationRequest(), "Request Log location was set incorrectly");
     $this->assertEquals($config['logLocationMNS'], $configObject->getLogLocationMNS(), "MNS Log location was set incorrectly");
     $this->assertEquals($config['logLocationCallbacks'], $configObject->getLogLocationCallbacks(), "Callback Log location was set incorrectly");
     $this->assertEquals($config['defaultRiskClass'], $configObject->getDefaultRiskClass(), "Default Risk was set incorrectly");
     $this->assertEquals($config['defaultLocale'], $configObject->getDefaultLocale(), "Default was set incorrectly");
 }
开发者ID:vmrose,项目名称:clientlibrary,代码行数:27,代码来源:ConfigTest.php

示例14: loadClass

 /**
  * @param string $className
  */
 public function loadClass(string $className)
 {
     if ($filename = $this->generator->checkClass($className)) {
         includeFile($filename);
         return true;
     }
 }
开发者ID:djmattyg007,项目名称:autocodeloader,代码行数:10,代码来源:Autoloader.php

示例15: run

 /**
  * Run ZMQ interface for generator
  * 
  * Req-rep pattern; msgs are commands:
  * 
  * GEN    = Generate ID
  * STATUS = Get status string
  */
 public function run()
 {
     $context = new \ZMQContext();
     $receiver = new \ZMQSocket($context, \ZMQ::SOCKET_REP);
     $bindTo = 'tcp://*:' . $this->port;
     echo "Binding to {$bindTo}\n";
     $receiver->bind($bindTo);
     while (TRUE) {
         $msg = $receiver->recv();
         switch ($msg) {
             case 'GEN':
                 try {
                     $response = $this->generator->generate();
                 } catch (\Exception $e) {
                     $response = "ERROR";
                 }
                 break;
             case 'STATUS':
                 $response = json_encode($this->generator->status());
                 break;
             default:
                 $response = 'UNKNOWN COMMAND';
                 break;
         }
         $receiver->send($response);
     }
 }
开发者ID:Minds,项目名称:cruftflake,代码行数:35,代码来源:ZeroMq.php


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