master

laravel/framework

Last updated at: 29/12/2023 09:24

ProcessPoolResults.php

TLDR

The ProcessPoolResults class in the Illuminate\Process namespace is a representation of a set of results from a process pool. It allows accessing and manipulating the results as an array or a collection.

Methods

collect()

This method returns the results as a collection of Illuminate\Support\Collection.

Classes

ProcessPoolResults

This class represents a set of process pool results. It implements the ArrayAccess interface, allowing the results to be accessed and manipulated as an array. The class has the following methods:

  • __construct(array $results): Constructs a new instance of ProcessPoolResults with the given array of results.
  • offsetExists(int $offset): bool: Determines if the given array offset exists in the results.
  • offsetGet(int $offset): mixed: Retrieves the result at the given offset in the results.
  • offsetSet(int $offset, mixed $value): void: Sets the result at the given offset in the results.
  • offsetUnset(int $offset): void: Unsets the result at the given offset in the results.
<?php

namespace Illuminate\Process;

use ArrayAccess;
use Illuminate\Support\Collection;

class ProcessPoolResults implements ArrayAccess
{
    /**
     * The results of the processes.
     *
     * @var array
     */
    protected $results = [];

    /**
     * Create a new process pool result set.
     *
     * @param  array  $results
     * @return void
     */
    public function __construct(array $results)
    {
        $this->results = $results;
    }

    /**
     * Get the results as a collection.
     *
     * @return \Illuminate\Support\Collection
     */
    public function collect()
    {
        return new Collection($this->results);
    }

    /**
     * Determine if the given array offset exists.
     *
     * @param  int  $offset
     * @return bool
     */
    public function offsetExists($offset): bool
    {
        return isset($this->results[$offset]);
    }

    /**
     * Get the result at the given offset.
     *
     * @param  int  $offset
     * @return mixed
     */
    public function offsetGet($offset): mixed
    {
        return $this->results[$offset];
    }

    /**
     * Set the result at the given offset.
     *
     * @param  int  $offset
     * @param  mixed  $value
     * @return void
     */
    public function offsetSet($offset, $value): void
    {
        $this->results[$offset] = $value;
    }

    /**
     * Unset the result at the given offset.
     *
     * @param  int  $offset
     * @return void
     */
    public function offsetUnset($offset): void
    {
        unset($this->results[$offset]);
    }
}