本文整理汇总了PHP中self::push方法的典型用法代码示例。如果您正苦于以下问题:PHP self::push方法的具体用法?PHP self::push怎么用?PHP self::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类self
的用法示例。
在下文中一共展示了self::push方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public static function create(callable $handler = null) : self
{
$stack = new self($handler ?: choose_handler());
$stack->push(Middleware::httpErrors());
$stack->push(Middleware::prepareBody());
return $stack;
}
示例2: create
/**
* Creates a default handler stack that can be used by clients.
*
* The returned handler will wrap the provided handler or use the most
* appropriate default handler for you system. The returned HandlerStack has
* support for cookies, redirects, HTTP error exceptions, and preparing a body
* before sending.
*
* The returned handler stack can be passed to a client in the "handler"
* option.
*
* @param callable $handler HTTP handler function to use with the stack. If no
* handler is provided, the best handler for your
* system will be utilized.
*
* @return HandlerStack
*/
public static function create(callable $handler = null)
{
$stack = new self($handler ?: choose_handler());
$stack->push(Middleware::httpErrors(), 'http_errors');
$stack->push(Middleware::redirect(), 'allow_redirects');
$stack->push(Middleware::cookies(), 'cookies');
$stack->push(Middleware::prepareBody(), 'prepare_body');
return $stack;
}
示例3: range
static function range(date $first, date $last)
{
$week = new self();
$day = $first;
$week->push($day);
do {
$day = $day->tomorrow();
$week->push($day);
} while (!$day->is_equal($last));
return $week;
}
示例4: fromArray
/**
* Only used for tests.
* @param string[] $displayNames
* @return array|CurrentPath
*/
public static function fromArray(array $displayNames)
{
$path = new self();
foreach ($displayNames as $v) {
$path->push(new ResourceField(new ResourceDefinition(null), $v));
}
return $path;
}
示例5: from
/**
* @param Traversable $from
*
* @return Collection
*/
public static function from(Traversable $from)
{
$self = new self();
foreach ($from as $item) {
$self->push($item);
}
return $self;
}
示例6: reduce
public function reduce(callable $callback, $preserveKeys = false)
{
$collection = new self();
foreach ($this->collection as $key => $item) {
if ($callback($item)) {
$collection->push($item, $preserveKeys ? $key : null);
}
}
return $collection;
}
示例7: whereRecip
public function whereRecip($email)
{
$coll = new self();
foreach ($this as $msg) {
if ($msg->recipients->contains('email', $email)) {
$coll->push($msg);
}
}
return $coll;
}
示例8: sequence
/**
* @param int[]|\BitWasp\Bitcoin\Script\Interpreter\Number[]|BufferInterface[] $sequence
* @return $this
*/
public function sequence(array $sequence)
{
$new = new self($this->math, $this->opcodes, null);
foreach ($sequence as $operation) {
if (is_int($operation)) {
if (!$this->opcodes->offsetExists($operation)) {
throw new \RuntimeException('Unknown opcode');
}
$new->script .= chr($operation);
} elseif ($operation instanceof Number) {
$new->push($operation->getBuffer());
} elseif ($operation instanceof BufferInterface) {
$new->push($operation);
} else {
throw new \RuntimeException('Input was neither an opcode or BufferInterfacecc');
}
}
$this->concat($new->getScript());
return $this;
}
示例9: copyFromContext
private function copyFromContext(LinkedNode $context)
{
$list = new self();
for ($n = $context; $n !== $this->tail; $n = $n->next()) {
/**
* @var LinkedDataNode $n
*/
$list->push($n->value());
}
return $list;
}
示例10: unique
/**
* Get all the unique values in the collection.
*
* @param bool $preserveKeys
*
* @return CollectionInterface
*/
public function unique($preserveKeys = true)
{
$values = new self();
$this->each(function ($item) use($values, $preserveKeys) {
if (!$values->contains($item)) {
if ($preserveKeys) {
}
$values->push($item);
}
});
return $values;
}
示例11: diff
public function diff(Delta $other)
{
$delta = new self();
if ($this->getOperations() === $other->getOperations()) {
return $delta;
}
$strings = array_map(function (OperationCollection $operations) use($other) {
return implode(array_map(function (OperationInterface $operation) use($operations, $other) {
if ($operation->getType() === OperationInterface::TYPE_INSERT) {
return is_string($operation->getValue()) ? $operation->getValue() : chr(0);
}
throw new \RuntimeException(sprintf('diff() called %s non-document', $operations === $other->getOperations() ? 'on' : 'with'));
}, $operations->toArray()));
}, [$this->getOperations(), $other->getOperations()]);
$diffResults = FastDiff::diff($strings[0], $strings[1]);
$thisIterator = $this->getOperations()->getIterator();
$otherIterator = $other->getOperations()->getIterator();
foreach ($diffResults as $diffResult) {
$length = mb_strlen($diffResult[1]);
while ($length > 0) {
$operationLength = 0;
switch ($diffResult[0]) {
case FastDiff::DIFF_INSERT:
$operationLength = min($otherIterator->getPeekLength(), $length);
$delta->push($otherIterator->next($operationLength));
break;
case FastDiff::DIFF_DELETE:
$operationLength = min($length, $thisIterator->getPeekLength());
$thisIterator->next($operationLength);
$delta->delete($operationLength);
break;
case FastDiff::DIFF_EQUAL:
$operationLength = min($thisIterator->getPeekLength(), $otherIterator->getPeekLength(), $length);
$thisOperation = $thisIterator->next($operationLength);
$otherOperation = $otherIterator->next($operationLength);
if ($thisOperation->getValue() === $otherOperation->getValue()) {
$delta->retain($operationLength, $this->diffAttributes($thisOperation->getAttributes(), $otherOperation->getAttributes()));
} else {
$delta->push($otherOperation)->delete($operationLength);
}
break;
}
$length -= $operationLength;
}
}
return $delta->chop();
}
示例12: fromSlice
static function fromSlice(array $tokens) : self
{
$ts = new self();
$ts->first = new NodeStart();
$ts->last = new NodeEnd();
self::link($ts->first, $ts->last);
foreach ($tokens as $token) {
$ts->push($token);
}
$ts->reset();
return $ts;
}
示例13: map
public function map($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Invalid (not callable) callback given');
}
$result = new self();
for ($i = 0; $i < $this->count(); $i++) {
$value = $callback($this->storage[$i]);
if (null !== $value) {
$result->push($value);
}
}
return $result;
}
示例14: filter
public function filter($var, $value)
{
$result = new self();
foreach ($this as $e) {
if ($e->{$var} == $value) {
$result->push($e);
}
}
return $result;
}