本文整理汇总了PHP中Generator类的典型用法代码示例。如果您正苦于以下问题:PHP Generator类的具体用法?PHP Generator怎么用?PHP Generator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Generator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: __construct
/**
* @param \Generator $generator
* @param string $prefix
*/
public function __construct(\Generator $generator, string $prefix)
{
$yielded = $generator->current();
$prefix .= \sprintf("; %s yielded at key %s", \is_object($yielded) ? \get_class($yielded) : \gettype($yielded), $generator->key());
if (!$generator->valid()) {
parent::__construct($prefix);
return;
}
$reflGen = new \ReflectionGenerator($generator);
$exeGen = $reflGen->getExecutingGenerator();
if ($isSubgenerator = $exeGen !== $generator) {
$reflGen = new \ReflectionGenerator($exeGen);
}
parent::__construct(\sprintf("%s on line %s in %s", $prefix, $reflGen->getExecutingLine(), $reflGen->getExecutingFile()));
}
开发者ID:amphp,项目名称:amp,代码行数:19,代码来源:InvalidYieldError.php
示例13: save
/**
* Store url to db
*
* @param $url
*/
protected function save($url)
{
$shortLink = Generator::getRandomString();
$item = array('created' => new \MongoDate(), 'key' => $shortLink, 'target' => $url);
$this->getCollection(self::MONGO_COLLECTION)->insert($item);
$this->set("link", 'http://' . $_SERVER['SERVER_NAME'] . '/' . $shortLink);
}
开发者ID:alebon,项目名称:url-shortener-php,代码行数:12,代码来源:LinkController.php
示例14: getReplacements
/**
* Get array replacements.
*
* @return array
*/
public function getReplacements()
{
$modelGenerator = new ModelGenerator(['name' => $this->name]);
$model = $modelGenerator->getRootNamespace() . '\\' . $modelGenerator->getName();
$model = str_replace(["\\", '/'], '\\', $model);
return array_merge(parent::getReplacements(), ['model' => $model]);
}
开发者ID:eaglesistemas,项目名称:eaglerepository,代码行数:12,代码来源:TransformerGenerator.php
示例15: uniqueRid
public static function uniqueRid()
{
do {
$rid = Generator::rid();
} while (Db::isRidExist($rid));
return $rid;
}
开发者ID:jDek-Mikhail,项目名称:proverid,代码行数:7,代码来源:generator.php
示例16: testLengthGenerator
/**
* Ensure generator is creating string with the correct length
*/
public function testLengthGenerator()
{
$lengthDefault = Generator::getRandomString();
$lengthTwenty = Generator::getRandomString(20);
$this->assertEquals(10, strlen($lengthDefault));
$this->assertEquals(20, strlen($lengthTwenty));
}
开发者ID:alebon,项目名称:url-shortener-php,代码行数:10,代码来源:GeneratorTest.php
示例17: htm
/**
* Generador de Reportes
*
* @category Kumbia
* @package Report
* @copyright Copyright (c) 2005-2007 Andres Felipe Gutierrez (andresfelipe at vagoogle.net)
* @license http://www.kumbia.org/license.txt GNU/GPL
*
*/
function htm($result, $sumArray, $title, $weighArray, $headerArray)
{
$config = Config::read('config');
$active_app = Router::get_application();
$file = md5(uniqid());
$content = "\n<html>\n <head>\n <title>REPORTE DE " . strtoupper($title) . "</title>\n </head>\n <body bgcolor='white'>\n <div style='font-size:20px;font-family:Verdana;color:#000000'>" . strtoupper($config->{$active_app}->name) . "</div>\n\n <div style='font-size:18px;font-family:Verdana;color:#000000'>REPORTE DE " . strtoupper($title) . "</div>\n\n <div style='font-size:18px;font-family:Verdana;color:#000000'>" . date("Y-m-d") . "</div>\n\n <br/>\n <table cellspacing='0' border=1 style='border:1px solid #969696'>\n ";
$content .= "<tr bgcolor='#F2F2F2'>\n";
for ($i = 0; $i <= count($headerArray) - 1; $i++) {
$content .= "<th style='font-family:Verdana;font-size:12px'>" . $headerArray[$i] . "</th>\n";
}
$content .= "</tr>\n";
$l = 5;
foreach ($result as $row) {
$content .= "<tr bgcolor='white'>\n";
for ($i = 0; $i <= count($row) - 1; $i++) {
if (is_numeric($row[$i])) {
$content .= "<td style='font-family:Verdana;font-size:12px' align='center'>{$row[$i]}</td>";
} else {
$content .= "<td style='font-family:Verdana;font-size:12px'>{$row[$i]} </td>";
}
}
$content .= "</tr>\n";
$l++;
}
file_put_contents("public/temp/{$file}.html", $content);
if (isset($raw_output)) {
print "<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".html', null); </script>";
} else {
Generator::forms_print("<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".html', null); </script>");
}
}
开发者ID:raalveco,项目名称:Escuela,代码行数:40,代码来源:htm.php
示例18: generate
/**
* Generates XML code
* @throws FeedGeneratorException
*/
public function generate()
{
if (!$this->_generator instanceof Generator) {
throw new FeedGeneratorException('There has been no generator strategy set.');
}
$this->generated = $this->_generator->generate($this->_channel);
}
开发者ID:carriercomm,项目名称:yaketystats,代码行数:11,代码来源:FeedGenerator.php
示例19: generateClass
/**
* Implements the loading of the class object
* @throws Exception if the class is already generated(not null)
*/
protected function generateClass()
{
if ($this->class != null) {
throw new Exception("The class has already been generated");
}
$config = Generator::getInstance()->getConfig();
$this->class = new PhpClass($this->phpIdentifier, $config->getClassExists());
$first = true;
foreach ($this->values as $value) {
try {
$name = Validator::validateNamingConvention($value);
} catch (ValidationException $e) {
$name = 'constant' . $name;
}
try {
$name = Validator::validateType($name);
} catch (ValidationException $e) {
$name .= 'Custom';
}
if ($first) {
$this->class->addConstant($name, '__default');
$first = false;
}
$this->class->addConstant($value, $name);
}
}
开发者ID:davenorthcreek,项目名称:stratum,代码行数:30,代码来源:Enum.php
示例20: next
/**
* Examines the value yielded from the generator and prepares the next step in interation.
*
* @param mixed $yielded
*/
private function next($yielded)
{
if (!$this->generator->valid()) {
$result = $this->generator->getReturn();
if ($result instanceof Awaitable) {
$this->reject(new AwaitableReturnedError($result));
return;
}
if ($result instanceof Generator) {
$this->reject(new GeneratorReturnedError($result));
return;
}
$this->resolve($result);
return;
}
$this->busy = true;
if ($yielded instanceof Generator) {
$yielded = new self($yielded);
}
$this->current = $yielded;
if ($yielded instanceof Awaitable) {
$yielded->done($this->send, $this->capture);
} else {
Loop\queue($this->send, $yielded);
}
$this->busy = false;
}
开发者ID:icicleio,项目名称:icicle,代码行数:32,代码来源:Coroutine.php
注:本文中的Generator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论