Row adding, some webpack tweaks
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Tables;
|
||||
|
||||
|
||||
abstract class BaseNumerator
|
||||
{
|
||||
/** @var int */
|
||||
protected $next;
|
||||
|
||||
/** @var int */
|
||||
protected $last;
|
||||
|
||||
/**
|
||||
* BaseNumerator constructor.
|
||||
*
|
||||
* @param int|int[] $first - first index, or [first, last]
|
||||
* @param int|null $last - last index, or null
|
||||
*/
|
||||
public function __construct($first, $last = null)
|
||||
{
|
||||
if (is_array($first) && $last === null) {
|
||||
list($first, $last) = $first;
|
||||
}
|
||||
|
||||
$this->next = $first;
|
||||
$this->last = $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next key, incrementing the internal state
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
if (!$this->hasMore())
|
||||
throw new \OutOfBoundsException("Column numerator has run out of allocated GCID slots");
|
||||
|
||||
$key = $this->getKey($this->next);
|
||||
$this->next++;
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert numeric index to a key
|
||||
*
|
||||
* @param int $index
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getKey($index)
|
||||
{
|
||||
return $index; // simple default
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool - true iof there are more keys available
|
||||
*/
|
||||
protected function hasMore()
|
||||
{
|
||||
return $this->next <= $this->last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate all keys
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
while ($this->hasMore()) {
|
||||
yield $this->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user