code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function offsetExists($offset) { return isset($this->elements[$offset]); }
Whether an offset exists. @param mixed $offset An offset to check for. @link http://php.net/manual/en/arrayaccess.offsetexists.php @return boolean true on success or false on failure.
offsetExists
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function offsetGet($offset) { return isset($this->elements[$offset]) ? $this->elements[$offset] : null ; }
Retrieve the current offset or null. @param mixed $offset The offset to retrieve. @link http://php.net/manual/en/arrayaccess.offsetget.php @return mixed Can return all value types.
offsetGet
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function offsetSet($offset, $value) { if (isset($offset)) { $this->elements[$offset] = $value; } else { $this->elements[] = $value; } return $this; }
Set an offset for this array. @param mixed $offset The offset to assign the value to. @param mixed $value The value to set. @link http://php.net/manual/en/arrayaccess.offsetset.php @return $this
offsetSet
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function offsetUnset($offset) { unset($this->elements[$offset]); return $this; }
Remove a present offset. @param mixed $offset The offset to unset. @link http://php.net/manual/en/arrayaccess.offsetunset.php @return $this
offsetUnset
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function only(array $keys) { return new static(array_intersect_key($this->elements, array_flip($keys))); }
Return slice of an array with just a given keys. @param array $keys List of keys to return @return AbstractArray The created array
only
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function reduce(callable $func, $initial = null) { return array_reduce($this->elements, $func, $initial); }
Reduce the array to a single value iteratively combining all values using $func. @param callable $func callback ($carry, $item) -> next $carry @param mixed|null $initial starting value of the $carry @return mixed Final value of $carry
reduce
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function search($element) { return array_search($element, $this->elements, true); }
Search for a given element and return the index of its first occurrence. @param mixed $element Value to search for @return mixed The corresponding key/index
search
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function __toString() { return $this->toString(); }
Convert the current array to a string with default separator. @return string A string representation of the current array
__toString
php
bocharsky-bw/Arrayzy
src/Traits/ConvertibleTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/ConvertibleTrait.php
MIT
public function toArray() { return $this->elements; }
Convert the current array to a native PHP array. @return array A native PHP array
toArray
php
bocharsky-bw/Arrayzy
src/Traits/ConvertibleTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/ConvertibleTrait.php
MIT
public function toReadableString($separator = AbstractArray::DEFAULT_SEPARATOR, $conjunction = ' and ') { $elements = $this->elements; $lastElement = array_pop($elements); $string = implode($separator, $elements) . (count($elements) ? $conjunction : '') . $lastElement; unset($elements, $lastElement); return $string; }
Implode the current array to a readable string with specified separator. @param string $separator The element's separator @param string $conjunction The last element conjunction @return string A readable string representation of the current array @link http://php.net/manual/en/function.implode.php
toReadableString
php
bocharsky-bw/Arrayzy
src/Traits/ConvertibleTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/ConvertibleTrait.php
MIT
public function toString($separator = AbstractArray::DEFAULT_SEPARATOR) { return implode($separator, $this->elements); }
Implode the current array to a string with specified separator. @param string $separator The element's separator @return string A string representation of the current array @link http://php.net/manual/en/function.implode.php
toString
php
bocharsky-bw/Arrayzy
src/Traits/ConvertibleTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/ConvertibleTrait.php
MIT
public function toJson($options = 0, $depth = 512) { $params = [ $this->elements, $options, ]; if (version_compare(PHP_VERSION, '5.5.0', '>=')) { $params[] = $depth; } // use call_user_func_array() here to fully cover this method in test return call_user_func_array('json_encode', $params); }
Encode the current array to a JSON string. @param int $options The bitmask @param int $depth The maximum depth (must be greater than zero) @return string A JSON string representation of the current array @link http://php.net/manual/en/function.json-encode.php
toJson
php
bocharsky-bw/Arrayzy
src/Traits/ConvertibleTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/ConvertibleTrait.php
MIT
public function debug($return = false) { if ($return) { return print_r($this->elements, true); } print_r($this->elements, false); return $this; }
Outputs/returns printed array for debug. @param bool $return Whether return or output directly @return $this|string
debug
php
bocharsky-bw/Arrayzy
src/Traits/DebuggableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/DebuggableTrait.php
MIT
public function export($return = false) { if ($return) { return var_export($this->elements, true); } var_export($this->elements, false); return $this; }
Exports array for using in PHP scripts. @param bool $return Whether return or output directly @return $this|string @link http://php.net/manual/en/function.var-export.php
export
php
bocharsky-bw/Arrayzy
src/Traits/DebuggableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/DebuggableTrait.php
MIT
public function pop() { return array_pop($this->elements); }
Pop a specified value off the end of array. @return mixed The popped element
pop
php
bocharsky-bw/Arrayzy
src/Traits/DoubleEndedQueueTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/DoubleEndedQueueTrait.php
MIT
public function push(/* variadic arguments allowed */) { if (func_num_args()) { $args = array_merge([&$this->elements], func_get_args()); call_user_func_array('array_push', $args); } return $this; }
Push one or more values onto the end of array at once. @return $this The current array with pushed elements to the end of array
push
php
bocharsky-bw/Arrayzy
src/Traits/DoubleEndedQueueTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/DoubleEndedQueueTrait.php
MIT
public function shift() { return array_shift($this->elements); }
Shifts a specified value off the beginning of array. @return mixed A shifted element
shift
php
bocharsky-bw/Arrayzy
src/Traits/DoubleEndedQueueTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/DoubleEndedQueueTrait.php
MIT
public function unshift(/* variadic arguments allowed */) { if (func_num_args()) { $args = array_merge([&$this->elements], func_get_args()); call_user_func_array('array_unshift', $args); } return $this; }
Prepends one or more values to the beginning of array at once. @return $this The current array with prepended elements to the beginning of array
unshift
php
bocharsky-bw/Arrayzy
src/Traits/DoubleEndedQueueTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/DoubleEndedQueueTrait.php
MIT
public function customSort(callable $func) { usort($this->elements, $func); return $this; }
{@inheritdoc} @link http://php.net/manual/en/function.usort.php
customSort
php
bocharsky-bw/Arrayzy
src/Traits/SortableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/SortableTrait.php
MIT
public function customSortKeys(callable $func) { uksort($this->elements, $func); return $this; }
{@inheritdoc} @link http://php.net/manual/en/function.uksort.php
customSortKeys
php
bocharsky-bw/Arrayzy
src/Traits/SortableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/SortableTrait.php
MIT
public function sort($order = SORT_ASC, $strategy = SORT_REGULAR, $preserveKeys = false) { $this->sorting($this->elements, $order, $strategy, $preserveKeys); return $this; }
{@inheritdoc} @link http://php.net/manual/en/function.arsort.php @link http://php.net/manual/en/function.sort.php @link http://php.net/manual/en/function.asort.php @link http://php.net/manual/en/function.rsort.php
sort
php
bocharsky-bw/Arrayzy
src/Traits/SortableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/SortableTrait.php
MIT
public function sortKeys($order = SORT_ASC, $strategy = SORT_REGULAR) { $this->sortingKeys($this->elements, $order, $strategy); return $this; }
{@inheritdoc} @link http://php.net/manual/en/function.ksort.php @link http://php.net/manual/en/function.krsort.php
sortKeys
php
bocharsky-bw/Arrayzy
src/Traits/SortableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/SortableTrait.php
MIT
protected function sorting(array &$elements, $order = SORT_ASC, $strategy = SORT_REGULAR, $preserveKeys = false) { switch ($order) { case SORT_DESC: if ($preserveKeys) { arsort($elements, $strategy); } else { rsort($elements, $strategy); } break; case SORT_ASC: default: if ($preserveKeys) { asort($elements, $strategy); } else { sort($elements, $strategy); } } }
@param array &$elements @param int $order @param int $strategy @param bool $preserveKeys
sorting
php
bocharsky-bw/Arrayzy
src/Traits/SortableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/SortableTrait.php
MIT
protected function sortingKeys(array &$elements, $order = SORT_ASC, $strategy = SORT_REGULAR) { switch ($order) { case SORT_DESC: krsort($elements, $strategy); break; case SORT_ASC: default: ksort($elements, $strategy); } }
@param array &$elements @param int $order @param int $strategy
sortingKeys
php
bocharsky-bw/Arrayzy
src/Traits/SortableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/SortableTrait.php
MIT
public function reset() { return reset($this->elements); }
Sets the internal pointer of an array to its first element. @return mixed The value of the first array element, or false if the array is empty. @link http://php.net/manual/en/function.reset.php
reset
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function first() { return $this->reset(); }
Alias of reset() method. Sets the internal pointer of an array to its first element. @return mixed The value of the first array element, or false if the array is empty. @link http://php.net/manual/en/function.reset.php
first
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function end() { return end($this->elements); }
Sets the internal pointer of an array to its last element. @return mixed The value of the last array element, or false if the array is empty. @link http://php.net/manual/en/function.end.php
end
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function last() { return $this->end(); }
Alias of end() method. Sets the internal pointer of an array to its last element. @return mixed The value of the last array element, or false if the array is empty. @link http://php.net/manual/en/function.end.php
last
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function next() { return next($this->elements); }
Advances the internal array pointer of an array. @return mixed The array value in the next place that's pointed to by the internal array pointer, or false if there are no more elements. @link http://php.net/manual/en/function.next.php
next
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function previous() { return prev($this->elements); }
Rewinds the internal array pointer. @return mixed The array value in the previous place that's pointed to by the internal array pointer, or false if there are no more elements. @link http://php.net/manual/en/function.prev.php
previous
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function key() { return key($this->elements); }
Fetch a key from an array. @return mixed The key function simply returns the key of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, key returns null. @link http://php.net/manual/en/function.key.php
key
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function current() { return current($this->elements); }
Returns the current element in an array. @return mixed The current function simply returns the value of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, current returns false. @link http://php.net/manual/en/function.current.php
current
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
public function each() { return each($this->elements); }
Returns the current key and value pair from an array and advance the array cursor. @return array The current key and value pair from the array array. This pair is returned in a four-element array, with the keys 0, 1, key, and value. Elements 0 and key contain the key name of the array element, and 1 and value contain the data. If the internal pointer for the array points past the end of the array contents, each returns false. @link http://php.net/manual/en/function.each.php
each
php
bocharsky-bw/Arrayzy
src/Traits/TraversableTrait.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/Traits/TraversableTrait.php
MIT
protected function assertImmutable(A $arrayzy, A $resultArrayzy, array $array, array $resultArray) { $this->assertNotSame($arrayzy, $resultArrayzy); $this->assertSame($array, $arrayzy->toArray()); $this->assertSame($resultArray, $resultArrayzy->toArray()); }
@param A $arrayzy @param A $resultArrayzy @param array $array @param array $resultArray
assertImmutable
php
bocharsky-bw/Arrayzy
tests/AbstractArrayTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/AbstractArrayTest.php
MIT
protected function assertMutable(A $arrayzy, A $resultArrayzy, array $resultArray) { $this->assertSame($arrayzy, $resultArrayzy); $this->assertSame($resultArray, $arrayzy->toArray()); $this->assertSame($resultArray, $resultArrayzy->toArray()); }
@param A $arrayzy @param A $resultArrayzy @param array $resultArray
assertMutable
php
bocharsky-bw/Arrayzy
tests/AbstractArrayTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/AbstractArrayTest.php
MIT
public function testExcept(array $array, $type = null) { if ($type !== self::TYPE_EMPTY) { $arrayzy = $this->createArrayzy($array); $arrayzy2 = clone $arrayzy; $randomKeys = $arrayzy->getRandomKeys(2); foreach ($randomKeys as $key) { $arrayzy->offsetUnset($key); } $this->assertSame($arrayzy2->except($randomKeys)->toArray(), $arrayzy->toArray()); } }
@dataProvider simpleArrayProvider @param array $array @param string $type
testExcept
php
bocharsky-bw/Arrayzy
tests/AbstractArrayTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/AbstractArrayTest.php
MIT
public function testIsAssoc(array $array, $type = null) { $arrayzy = $this->createArrayzy($array); $isAssoc = static::TYPE_ASSOC === $type; $this->assertSame($isAssoc, $arrayzy->isAssoc()); }
@dataProvider simpleArrayProvider @param array $array @param string $type
testIsAssoc
php
bocharsky-bw/Arrayzy
tests/AbstractArrayTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/AbstractArrayTest.php
MIT
public function testIsNumeric(array $array, $type = null) { $arrayzy = $this->createArrayzy($array); $isNumeric = static::TYPE_NUMERIC === $type; $this->assertSame($isNumeric, $arrayzy->isNumeric()); }
@dataProvider simpleArrayProvider @param array $array @param string $type
testIsNumeric
php
bocharsky-bw/Arrayzy
tests/AbstractArrayTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/AbstractArrayTest.php
MIT
public function testOnly(array $array, $type = null) { if ($type !== self::TYPE_EMPTY) { $arrayzy = $this->createArrayzy($array); $arrayzy2 = clone $arrayzy; $randomKeys = $arrayzy->getRandomKeys(2); foreach ($arrayzy as $key => $value) { if (!in_array($key, $randomKeys)) { $arrayzy->offsetUnset($key); } } $this->assertSame($arrayzy2->only($randomKeys)->toArray(), $arrayzy->toArray()); } }
@dataProvider simpleArrayProvider @param array $array @param string $type
testOnly
php
bocharsky-bw/Arrayzy
tests/AbstractArrayTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/AbstractArrayTest.php
MIT
public function testToString($string, $separator) { $array = explode($separator, $string); $arrayzy = $this->createArrayzy($array); $resultString = implode(', ', $array); $this->assertSame($resultString, (string)$arrayzy); $this->assertSame($string, $arrayzy->toString($separator)); }
@dataProvider stringWithSeparatorProvider @param string $string @param string $separator
testToString
php
bocharsky-bw/Arrayzy
tests/AbstractArrayTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/AbstractArrayTest.php
MIT
public function testCreateFromString($string, $separator) { $array = explode($separator, $string); $arrayzy = new A($array); $resultArrayzy = $arrayzy->createFromString($string, $separator); $this->assertImmutable($arrayzy, $resultArrayzy, $array, $array); }
@dataProvider stringWithSeparatorProvider @param string $string @param string $separator
testCreateFromString
php
bocharsky-bw/Arrayzy
tests/ArrayImitatorTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/ArrayImitatorTest.php
MIT
public function testStaticCreateFromString($string, $separator) { $array = explode($separator, $string); $arrayzy = A::create($array); $resultArrayzy = A::createFromString($string, $separator); $this->assertImmutable($arrayzy, $resultArrayzy, $array, $array); }
@dataProvider stringWithSeparatorProvider @param string $string @param string $separator
testStaticCreateFromString
php
bocharsky-bw/Arrayzy
tests/ArrayImitatorTest.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/tests/ArrayImitatorTest.php
MIT
public function register() { $this->mergeConfigFrom( __DIR__.'/../config/haystack.php', 'haystack' ); }
Register any application services. @return void
register
php
Sammyjo20/laravel-haystack
src/HaystackServiceProvider.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/HaystackServiceProvider.php
MIT
protected function publishConfigAndMigrations(): static { $this->publishes([ __DIR__.'/../config/haystack.php' => config_path('haystack.php'), ], 'haystack-config'); $this->publishes([ __DIR__.'/../database/migrations/create_haystacks_table.php.stub' => database_path('migrations/'.now()->format('Y_m_d_His').'_create_haystacks_table.php'), __DIR__.'/../database/migrations/create_haystack_bales_table.php.stub' => database_path('migrations/'.now()->addSeconds(1)->format('Y_m_d_His').'_create_haystack_bales_table.php'), __DIR__.'/../database/migrations/create_haystack_data_table.php.stub' => database_path('migrations/'.now()->addSeconds(2)->format('Y_m_d_His').'_create_haystack_data_table.php'), ], 'haystack-migrations'); return $this; }
Public the config file and migrations @return $this
publishConfigAndMigrations
php
Sammyjo20/laravel-haystack
src/HaystackServiceProvider.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/HaystackServiceProvider.php
MIT
public function registerQueueListeners(): static { if (config('haystack.process_automatically') !== true) { return $this; } Queue::createPayloadUsing(fn ($connection, $queue, $payload) => JobEventListener::make()->createPayloadUsing($connection, $queue, $payload)); Queue::after(fn (JobProcessed $event) => JobEventListener::make()->handleJobProcessed($event)); Queue::failing(fn (JobFailed $event) => JobEventListener::make()->handleFailedJob($event)); return $this; }
Listen to the queue events. @return $this
registerQueueListeners
php
Sammyjo20/laravel-haystack
src/HaystackServiceProvider.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/HaystackServiceProvider.php
MIT
public static function make(): static { return new static(); }
Static make helper to create class.
make
php
Sammyjo20/laravel-haystack
src/JobEventListener.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/JobEventListener.php
MIT
private function unserializeJobFromPayload(array $payload): ?object { if (! isset($payload['data']['command'])) { return null; } return SerializationHelper::unserialize($payload['data']['command'], ['allowed_classes' => true]); }
Unserialize the job from the job payload.
unserializeJobFromPayload
php
Sammyjo20/laravel-haystack
src/JobEventListener.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/JobEventListener.php
MIT
private function getHaystackFromPayload(array $payload): ?Haystack { $haystackId = $payload['data']['haystack_id'] ?? null; if (blank($haystackId)) { return null; } return Haystack::find($haystackId); }
Attempt to find the haystack model from the job payload.
getHaystackFromPayload
php
Sammyjo20/laravel-haystack
src/JobEventListener.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/JobEventListener.php
MIT
public function withName(string $name): static { $this->name = $name; return $this; }
Specify a name for the haystack. @return $this
withName
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function then(Closure|callable $closure): static { $this->callbacks->addThen($closure); return $this; }
Provide a closure that will run when the haystack is complete. @return $this @throws PhpVersionNotSupportedException
then
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function catch(Closure|callable $closure): static { $this->callbacks->addCatch($closure); return $this; }
Provide a closure that will run when the haystack fails. @return $this @throws PhpVersionNotSupportedException
catch
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function finally(Closure|callable $closure): static { $this->callbacks->addFinally($closure); return $this; }
Provide a closure that will run when the haystack finishes. @return $this @throws PhpVersionNotSupportedException
finally
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function paused(Closure|callable $closure): static { $this->callbacks->addPaused($closure); return $this; }
Provide a closure that will run when the haystack is paused. @return $this @throws PhpVersionNotSupportedException
paused
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addJob(StackableJob $job, int $delayInSeconds = 0, ?string $queue = null, ?string $connection = null): static { $pendingHaystackRow = new PendingHaystackBale($job, $delayInSeconds, $queue, $connection); $this->jobs->add($pendingHaystackRow); return $this; }
Add a job to the haystack. @return $this
addJob
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addJobWhen(bool $condition, ...$arguments): static { return $condition === true ? $this->addJob(...$arguments) : $this; }
Add a job when a condition is true. @return $this
addJobWhen
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addJobUnless(bool $condition, ...$arguments): static { return $this->addJobWhen(! $condition, ...$arguments); }
Add a job when a condition is false. @return $this
addJobUnless
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addJobs(Collection|array $jobs, int $delayInSeconds = 0, ?string $queue = null, ?string $connection = null): static { if (is_array($jobs)) { $jobs = collect($jobs); } $jobs = $jobs->filter(fn ($job) => $job instanceof StackableJob); foreach ($jobs as $job) { $this->addJob($job, $delayInSeconds, $queue, $connection); } return $this; }
Add multiple jobs to the haystack at a time. @return $this
addJobs
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addJobsWhen(bool $condition, ...$arguments): static { return $condition === true ? $this->addJobs(...$arguments) : $this; }
Add jobs when a condition is true. @return $this
addJobsWhen
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addJobsUnless(bool $condition, ...$arguments): static { return $this->addJobsWhen(! $condition, ...$arguments); }
Add jobs when a condition is false. @return $this
addJobsUnless
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addBale(StackableJob $job, int $delayInSeconds = 0, ?string $queue = null, ?string $connection = null): static { return $this->addJob($job, $delayInSeconds, $queue, $connection); }
Add a bale onto the haystack. Yee-haw! @alias addJob() @return $this
addBale
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addBales(Collection|array $jobs, int $delayInSeconds = 0, ?string $queue = null, ?string $connection = null): static { return $this->addJobs($jobs, $delayInSeconds, $queue, $connection); }
Add multiple bales onto the haystack. Yee-haw! @alias addJobs() @return $this
addBales
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function withDelay(int $seconds): static { $this->globalDelayInSeconds = $seconds; return $this; }
Set a global delay on the jobs. @return $this
withDelay
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function onQueue(string $queue): static { $this->globalQueue = $queue; return $this; }
Set a global queue for the jobs. @return $this
onQueue
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function onConnection(string $connection): static { $this->globalConnection = $connection; return $this; }
Set a global connection for the jobs. @return $this
onConnection
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function addMiddleware(Closure|callable|array $value): static { $this->middleware->add($value); return $this; }
Add some middleware to be merged in with every job @return $this @throws PhpVersionNotSupportedException
addMiddleware
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function withData(string $key, mixed $value, ?string $cast = null): static { DataValidator::validateCast($value, $cast); $this->initialData->put($key, new PendingData($key, $value, $cast)); return $this; }
Provide data before the haystack is created. @return $this
withData
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function withModel(Model $model, ?string $key = null): static { $key = DataHelper::getModelKey($model, $key); if ($this->initialData->has($key)) { throw new HaystackModelExists($key); } $this->initialData->put($key, new PendingData($key, $model, SerializedModel::class)); return $this; }
Store a model to be shared across all haystack jobs. @return $this @throws HaystackModelExists
withModel
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
protected function prepareJobsForInsert(Haystack $haystack): array { $now = Carbon::now(); $timestamps = [ 'created_at' => $now, 'updated_at' => $now, ]; return $this->jobs->map(function (PendingHaystackBale $pendingJob) use ($haystack, $timestamps) { $hasDelay = isset($pendingJob->delayInSeconds) && $pendingJob->delayInSeconds > 0; // We'll create a dummy Haystack bale model for each row // and convert it into its attributes just for the casting. $baseAttributes = $haystack->bales()->make([ 'job' => $pendingJob->job, 'delay' => $hasDelay ? $pendingJob->delayInSeconds : $this->globalDelayInSeconds, 'on_queue' => $pendingJob->queue ?? $this->globalQueue, 'on_connection' => $pendingJob->connection ?? $this->globalConnection, ])->getAttributes(); // Next we'll merge in the timestamps return array_merge($timestamps, $baseAttributes); })->toArray(); }
Map the jobs to be ready for inserting.
prepareJobsForInsert
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
protected function prepareDataForInsert(Haystack $haystack): array { return $this->initialData->map(function (PendingData $pendingData) use ($haystack) { // We'll create a dummy Haystack data model for each row // and convert it into its attributes just for the casting. return $haystack->data()->make([ 'key' => $pendingData->key, 'cast' => $pendingData->cast, 'value' => $pendingData->value, ])->getAttributes(); })->toArray(); }
Map the initial data to be ready for inserting.
prepareDataForInsert
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function dontReturnData(): static { $this->options->returnDataOnFinish = false; return $this; }
Specify if you do not want haystack to return the data. @return $this
dontReturnData
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function allowFailures(): static { $this->options->allowFailures = true; return $this; }
Allow failures on the Haystack @return $this
allowFailures
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function getJobs(): Collection { return $this->jobs; }
Get all the jobs in the builder.
getJobs
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function getGlobalDelayInSeconds(): int { return $this->globalDelayInSeconds; }
Get the time for the "withDelay".
getGlobalDelayInSeconds
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function getMiddleware(): MiddlewareCollection { return $this->middleware; }
Get the closure for the global middleware.
getMiddleware
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function beforeSave(Closure $closure): static { $this->beforeSave = $closure; return $this; }
Specify a closure to run before saving the Haystack @return $this
beforeSave
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function setOption(string $option, mixed $value): static { $this->options->$option = $value; return $this; }
Set an option on the Haystack Options. @return $this
setOption
php
Sammyjo20/laravel-haystack
src/Builders/HaystackBuilder.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Builders/HaystackBuilder.php
MIT
public function set($model, string $key, $value, array $attributes) { if (blank($value)) { return null; } if (! $value instanceof CallbackCollection) { throw new InvalidArgumentException(sprintf('Value provided must be an instance of %s.', CallbackCollection::class)); } return SerializationHelper::serialize($value); }
Serialize a job. @return mixed|string|null
set
php
Sammyjo20/laravel-haystack
src/Casts/CallbackCollectionCast.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Casts/CallbackCollectionCast.php
MIT
public function set($model, string $key, $value, array $attributes) { if (blank($value)) { return null; } if (! $value instanceof MiddlewareCollection) { throw new InvalidArgumentException(sprintf('Value provided must be an instance of %s.', MiddlewareCollection::class)); } return SerializationHelper::serialize($value); }
Serialize a job. @return mixed|string|null
set
php
Sammyjo20/laravel-haystack
src/Casts/MiddlewareCollectionCast.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Casts/MiddlewareCollectionCast.php
MIT
public function set($model, string $key, $value, array $attributes): ?string { if (blank($value)) { return null; } if ($value instanceof Closure === false && is_callable($value) === false) { throw new InvalidArgumentException('Value provided must be a closure or an invokable class.'); } $closure = ClosureHelper::fromCallable($value); return SerializationHelper::serialize(new SerializableClosure($closure)); }
Serialize a closure. @return mixed|string|null @throws \Laravel\SerializableClosure\Exceptions\PhpVersionNotSupportedException
set
php
Sammyjo20/laravel-haystack
src/Casts/SerializeClosure.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Casts/SerializeClosure.php
MIT
public function set($model, string $key, $value, array $attributes) { if (blank($value)) { return null; } return SerializationHelper::serialize($value); }
Serialize a job. @return mixed|string|null
set
php
Sammyjo20/laravel-haystack
src/Casts/Serialized.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Casts/Serialized.php
MIT
public function set($model, string $key, $value, array $attributes) { if (blank($value)) { return null; } if (! $value instanceof Model) { throw new InvalidArgumentException('The provided value must be a model.'); } return SerializationHelper::serialize(new SerializedModelData($value)); }
Serialize a model. @return mixed|string|null
set
php
Sammyjo20/laravel-haystack
src/Casts/SerializedModel.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Casts/SerializedModel.php
MIT
public function getNextJobRow(): ?HaystackBale { return $this->bales()->first(); }
Get the next job row in the Haystack.
getNextJobRow
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function getNextJob(): ?NextJob { $jobRow = $this->getNextJobRow(); if (! $jobRow instanceof HaystackBale) { return null; } // We'll retrieve the configured job which will have // the delay, queue and connection all set up. $job = $jobRow->configuredJob(); // We'll now set the Haystack model on the job. $job->setHaystack($this) ->setHaystackBaleId($jobRow->getKey()) ->setHaystackBaleAttempts($jobRow->attempts) ->setHaystackBaleRetryUntil($jobRow->retry_until); // We'll now apply any global middleware if it was provided to us // while building the Haystack. if ($this->middleware instanceof MiddlewareCollection) { $job->middleware = array_merge($job->middleware, $this->middleware->toMiddlewareArray()); } // Apply default middleware. We'll need to make sure that // the job middleware is added to the top of the array. $defaultMiddleware = [ new CheckFinished, new CheckAttempts, new IncrementAttempts, ]; $job->middleware = array_merge($defaultMiddleware, $job->middleware); // Return the NextJob DTO which contains the job and the row! return new NextJob($job, $jobRow); }
Get the next job from the Haystack.
getNextJob
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function dispatchNextJob(?StackableJob $currentJob = null, int|CarbonInterface|null $delayInSecondsOrCarbon = null): void { // If the resume_at has been set, and the date is in the future, we're not allowed to process // the next job, so we stop. if ($this->resume_at instanceof CarbonInterface && $this->resume_at->isFuture()) { return; } if (is_null($currentJob) && $this->started === false) { $this->start(); return; } // If the job has been provided, we will delete the haystack bale to prevent // the same bale being retrieved on the next job. if (isset($currentJob)) { HaystackBale::query()->whereKey($currentJob->getHaystackBaleId())->delete(); } // If the delay in seconds has been provided, we need to pause the haystack by the // delay. if (isset($delayInSecondsOrCarbon)) { $this->pause(CarbonHelper::createFromSecondsOrCarbon($delayInSecondsOrCarbon)); return; } // Now we'll query the next bale. $nextJob = $this->getNextJob(); // If no next job was found, we'll stop. if (! $nextJob instanceof NextJob) { $this->finish(); return; } dispatch($nextJob->job); }
Dispatch the next job. @throws PhpVersionNotSupportedException
dispatchNextJob
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function addJobs(StackableJob|Collection|array $jobs, int $delayInSeconds = 0, ?string $queue = null, ?string $connection = null, bool $prepend = false): void { if ($jobs instanceof StackableJob) { $jobs = [$jobs]; } if ($jobs instanceof Collection) { $jobs = $jobs->all(); } $pendingJobs = []; foreach ($jobs as $job) { $pendingJobs[] = new PendingHaystackBale($job, $delayInSeconds, $queue, $connection, $prepend); } $this->addPendingJobs($pendingJobs); }
Add new jobs to the haystack.
addJobs
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function addPendingJobs(array $pendingJobs): void { $pendingJobRows = collect($pendingJobs) ->filter(fn ($pendingJob) => $pendingJob instanceof PendingHaystackBale) ->map(fn (PendingHaystackBale $pendingJob) => $pendingJob->toDatabaseRow($this)) ->all(); if (empty($pendingJobRows)) { return; } $this->bales()->insert($pendingJobRows); }
Add pending jobs to the haystack.
addPendingJobs
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
protected function invokeCallbacks(?array $closures, ?Collection $data = null): void { collect($closures)->each(function (SerializableClosure $closure) use ($data) { $closure($data); }); }
Execute the closures. @param array<SerializableClosure> $closures @throws PhpVersionNotSupportedException
invokeCallbacks
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function setData(string $key, mixed $value, ?string $cast = null): self { DataValidator::validateCast($value, $cast); $this->data()->updateOrCreate(['key' => $key], [ 'cast' => $cast, 'value' => $value, ]); return $this; }
Store data on the Haystack. @return ManagesBales|\Sammyjo20\LaravelHaystack\Models\Haystack
setData
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function getData(string $key, mixed $default = null): mixed { $data = $this->data()->where('key', $key)->first(); return $data instanceof HaystackData ? $data->value : $default; }
Retrieve data by a key from the Haystack.
getData
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function setModel(Model $model, ?string $key = null): static { $key = DataHelper::getModelKey($model, $key); if ($this->data()->where('key', $key)->exists()) { throw new HaystackModelExists($key); } return $this->setData($key, $model, SerializedModel::class); }
Set a model on a Haystack @return $this @throws HaystackModelExists
setModel
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function allData(bool $includeModels = false): Collection { $data = $this->data() ->when($includeModels === false, fn ($query) => $query->where('key', 'NOT LIKE', 'model:%')) ->orderBy('id')->get(); return $data->mapWithKeys(function ($value, $key) { return [$value->key => $value->value]; }); }
Retrieve all the data from the Haystack.
allData
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
protected function conditionallyGetAllData(): ?Collection { $returnAllData = config('haystack.return_all_haystack_data_when_finished', false); return $this->options->returnDataOnFinish === true && $returnAllData === true ? $this->allData() : null; }
Conditionally retrieve all the data from the Haystack depending on if we are able to return the data.
conditionallyGetAllData
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function setBaleRetryUntil(StackableJob $job, int $retryUntil): void { HaystackBale::query()->whereKey($job->getHaystackBaleId())->update(['retry_until' => $retryUntil]); }
Set the retry-until on the job.
setBaleRetryUntil
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function getCallbacks(): CallbackCollection { return $this->callbacks ?? new CallbackCollection; }
Get the callbacks on the Haystack.
getCallbacks
php
Sammyjo20/laravel-haystack
src/Concerns/ManagesBales.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/ManagesBales.php
MIT
public function setHaystack(Haystack $haystack): static { $this->haystack = $haystack; return $this; }
Set the Haystack onto the job. @return $this
setHaystack
php
Sammyjo20/laravel-haystack
src/Concerns/Stackable.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/Stackable.php
MIT
public function nextJob(int|CarbonInterface|null $delayInSecondsOrCarbon = null): static { if (config('haystack.process_automatically', false) === true) { throw new StackableException('The "nextJob" method is unavailable when "haystack.process_automatically" is enabled.'); } $this->haystack->dispatchNextJob($this, $delayInSecondsOrCarbon); return $this; }
Dispatch the next job in the Haystack. @return $this @throws StackableException
nextJob
php
Sammyjo20/laravel-haystack
src/Concerns/Stackable.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/Stackable.php
MIT
public function nextBale(int|CarbonInterface|null $delayInSecondsOrCarbon = null): static { return $this->nextJob($delayInSecondsOrCarbon); }
Dispatch the next bale in the haystack. Yee-haw! @return $this @throws StackableException
nextBale
php
Sammyjo20/laravel-haystack
src/Concerns/Stackable.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/Stackable.php
MIT
public function longRelease(int|CarbonInterface $delayInSecondsOrCarbon): static { $resumeAt = CarbonHelper::createFromSecondsOrCarbon($delayInSecondsOrCarbon); $this->haystack->pause($resumeAt); return $this; }
Release the job for haystack to process later. @return $this
longRelease
php
Sammyjo20/laravel-haystack
src/Concerns/Stackable.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/Stackable.php
MIT
public function failHaystack(): static { $this->haystack->finish(FinishStatus::Failure); return $this; }
Fail the job stack. @return $this
failHaystack
php
Sammyjo20/laravel-haystack
src/Concerns/Stackable.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/Stackable.php
MIT
public function appendToHaystack(StackableJob|Collection|array $jobs, int $delayInSeconds = 0, ?string $queue = null, ?string $connection = null): static { $this->haystack->addJobs($jobs, $delayInSeconds, $queue, $connection, false); return $this; }
Append jobs to the haystack. @return $this
appendToHaystack
php
Sammyjo20/laravel-haystack
src/Concerns/Stackable.php
https://github.com/Sammyjo20/laravel-haystack/blob/master/src/Concerns/Stackable.php
MIT