code
stringlengths
31
707k
docstring
stringlengths
23
14.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 close(Message $msg): void { $data = $msg->getData(); /** @var Connection $conn */ $conn = Session::current(); $fd = is_numeric($data) ? (int)$data : $conn->getFd(); $conn->push("hi, will close conn $fd"); // disconnect $conn->getServer()->disconnect($fd); }
Message command is: 'test.index' @param Message $msg @return void @MessageMapping("close")
close
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function injectRequest(Request $req): void { $fd = $req->getFd(); Session::current()->push("(your FD: $fd)message data: " . json_encode($req->getMessage()->toArray())); }
Message command is: 'test.req' @param Request $req @return void @MessageMapping("req")
injectRequest
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function injectMessage(Message $msg): void { Session::current()->push('message data: ' . json_encode($msg->toArray())); }
Message command is: 'test.msg' @param Message $msg @return void @MessageMapping("msg")
injectMessage
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function echo(string $data): void { Session::current()->push('(echo)Recv: ' . $data); }
Message command is: 'echo' @param string $data @MessageMapping(root=true)
echo
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function hi(Request $req, Response $res): void { $fd = $req->getFd(); $ufd = (int)$req->getMessage()->getData(); if ($ufd < 1) { Session::current()->push('data must be an integer'); return; } $res->setFd($ufd)->setContent("Hi #{$ufd}, I am #{$fd}"); }
Message command is: 'echo' @param Request $req @param Response $res @MessageMapping(root=true)
hi
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function binary(string $data): string { // Session::current()->push('Binary: ' . $data, \WEBSOCKET_OPCODE_BINARY); return 'Binary: ' . $data; }
Message command is: 'bin' @MessageMapping("bin", root=true, opcode=2) @param string $data @return string
binary
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function pong(): void { Session::current()->push('pong!', WEBSOCKET_OPCODE_PONG); }
Message command is: 'ping' @MessageMapping("ping", root=true)
pong
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function testDie(): void { $wid = \server()->getPid('workerId'); \vdump($wid); \server()->stopWorker($wid); }
Message command is: 'test.ar' @MessageMapping("stop-worker")
testDie
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0
public function getPrefixDirs(): array { return [ __NAMESPACE__ => __DIR__, ]; }
Get namespace and dirs @return array
getPrefixDirs
php
swoft-cloud/swoft
test/testing/AutoLoader.php
https://github.com/swoft-cloud/swoft/blob/master/test/testing/AutoLoader.php
Apache-2.0
public static function new(string $basePath, array $config = []): SwoftApplication { return new static($basePath, $config); }
@param string $basePath @param array $config @return SwoftApplication
new
php
swoft-cloud/swoft
test/testing/TestApplication.php
https://github.com/swoft-cloud/swoft/blob/master/test/testing/TestApplication.php
Apache-2.0
public function __construct(string $basePath, array $config = []) { // RUN_SERVER_TEST=ws,tcp,http if (!defined('RUN_SERVER_TEST')) { define('RUN_SERVER_TEST', (string)getenv('RUN_SERVER_TEST')); } if (RUN_SERVER_TEST) { printf("ENV RUN_SERVER_TEST=%s\n", RUN_SERVER_TEST); } // tests: disable run console application $this->setStartConsole(false); $config = array_merge([ 'basePath' => $basePath, 'beanFile' => $basePath . '/app/bean.php', 'disabledAutoLoaders' => [ // \App\AutoLoader::class => 1, ], ], $config); parent::__construct($config); }
Class constructor. @param string $basePath @param array $config
__construct
php
swoft-cloud/swoft
test/testing/TestApplication.php
https://github.com/swoft-cloud/swoft/blob/master/test/testing/TestApplication.php
Apache-2.0
public function testChrOrd() { foreach (self::$utf8ValidityMap as $u => $t) { if ($t) { $this->assertSame($u, u::chr(u::ord($u))); } } }
@covers Patchwork\Utf8::chr @covers Patchwork\Utf8::ord
testChrOrd
php
tchwork/utf8
tests/Utf8Test.php
https://github.com/tchwork/utf8/blob/master/tests/Utf8Test.php
Apache-2.0
public function testIconvGetEncoding() { $a = array( 'input_encoding' => 'UTF-8', 'output_encoding' => 'UTF-8', 'internal_encoding' => 'UTF-8', ); foreach ($a as $t => $e) { $this->assertTrue(p::iconv_set_encoding($t, $e)); $this->assertSame($e, p::iconv_get_encoding($t)); } $this->assertSame($a, p::iconv_get_encoding('all')); $this->assertFalse(p::iconv_set_encoding('foo', 'UTF-8')); }
@covers Patchwork\PHP\Shim\Iconv::iconv_get_encoding @covers Patchwork\PHP\Shim\Iconv::iconv_set_encoding
testIconvGetEncoding
php
tchwork/utf8
tests/PHP/Shim/IconvTest.php
https://github.com/tchwork/utf8/blob/master/tests/PHP/Shim/IconvTest.php
Apache-2.0
public function testmb_stubs() { $this->assertFalse(p::mb_substitute_character('?')); $this->assertSame('none', p::mb_substitute_character()); $this->assertContains('UTF-8', p::mb_list_encodings()); $this->assertTrue(p::mb_internal_encoding('utf8')); $this->assertFalse(p::mb_internal_encoding('no-no')); $this->assertSame('UTF-8', p::mb_internal_encoding()); p::mb_encode_mimeheader(''); $this->assertFalse(true, 'mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead'); }
@covers Patchwork\PHP\Shim\Mbstring::mb_internal_encoding @covers Patchwork\PHP\Shim\Mbstring::mb_list_encodings @covers Patchwork\PHP\Shim\Mbstring::mb_substitute_character @expectedException PHPUnit\Framework\Error\Warning
testmb_stubs
php
tchwork/utf8
tests/PHP/Shim/MbstringTest.php
https://github.com/tchwork/utf8/blob/master/tests/PHP/Shim/MbstringTest.php
Apache-2.0
public function testmb_strpos_empty_delimiter() { try { mb_strpos('abc', ''); $this->assertFalse(true, 'The previous line should trigger a warning (Empty delimiter)'); } catch (\PHPUnit\Framework\Error\Warning $e) { p::mb_strpos('abc', ''); $this->assertFalse(true, 'The previous line should trigger a warning (Empty delimiter)'); } }
@covers Patchwork\PHP\Shim\Mbstring::mb_strpos @expectedException PHPUnit\Framework\Error\Warning
testmb_strpos_empty_delimiter
php
tchwork/utf8
tests/PHP/Shim/MbstringTest.php
https://github.com/tchwork/utf8/blob/master/tests/PHP/Shim/MbstringTest.php
Apache-2.0
public function testNormalizeConformance() { $t = file(__DIR__.'/NormalizationTest.'.$this->unicodeVersion.'.txt'); $c = array(); foreach ($t as $s) { $t = explode('#', $s); $t = explode(';', $t[0]); if (6 === count($t)) { foreach ($t as $k => $s) { $t = explode(' ', $s); $t = array_map('hexdec', $t); $t = array_map('Patchwork\Utf8::chr', $t); $c[$k] = implode('', $t); } $this->assertSame($c[1], pn::normalize($c[0], pn::NFC)); $this->assertSame($c[1], pn::normalize($c[1], pn::NFC)); $this->assertSame($c[1], pn::normalize($c[2], pn::NFC)); $this->assertSame($c[3], pn::normalize($c[3], pn::NFC)); $this->assertSame($c[3], pn::normalize($c[4], pn::NFC)); $this->assertSame($c[2], pn::normalize($c[0], pn::NFD)); $this->assertSame($c[2], pn::normalize($c[1], pn::NFD)); $this->assertSame($c[2], pn::normalize($c[2], pn::NFD)); $this->assertSame($c[4], pn::normalize($c[3], pn::NFD)); $this->assertSame($c[4], pn::normalize($c[4], pn::NFD)); $this->assertSame($c[3], pn::normalize($c[0], pn::NFKC)); $this->assertSame($c[3], pn::normalize($c[1], pn::NFKC)); $this->assertSame($c[3], pn::normalize($c[2], pn::NFKC)); $this->assertSame($c[3], pn::normalize($c[3], pn::NFKC)); $this->assertSame($c[3], pn::normalize($c[4], pn::NFKC)); $this->assertSame($c[4], pn::normalize($c[0], pn::NFKD)); $this->assertSame($c[4], pn::normalize($c[1], pn::NFKD)); $this->assertSame($c[4], pn::normalize($c[2], pn::NFKD)); $this->assertSame($c[4], pn::normalize($c[3], pn::NFKD)); $this->assertSame($c[4], pn::normalize($c[4], pn::NFKD)); } } }
@covers Patchwork\PHP\Shim\Normalizer::normalize @group unicode
testNormalizeConformance
php
tchwork/utf8
tests/PHP/Shim/NormalizerTest.php
https://github.com/tchwork/utf8/blob/master/tests/PHP/Shim/NormalizerTest.php
Apache-2.0
public static function create(array $elements = []) { return new static($elements); }
Create a new instance. @param array $elements @return AbstractArray Returns created instance
create
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public static function createFromJson($json, $options = 0, $depth = 512) { return new static(json_decode($json, true, $depth, $options)); }
Decode a JSON string to new instance. @param string $json The JSON string being decoded @param int $options Bitmask of JSON decode options @param int $depth Specified recursion depth @return AbstractArray The created array
createFromJson
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public static function createFromObject(ArrayAccess $elements) { $array = new static(); foreach ($elements as $key => $value) { $array[$key] = $value; } return $array; }
Create a new instance filled with values from an object implementing ArrayAccess. @param ArrayAccess $elements Object that implements ArrayAccess @return AbstractArray Returns created instance
createFromObject
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public static function createFromString($string, $separator) { return new static(explode($separator, $string)); }
Explode a string to new instance by specified separator. @param string $string Converted string @param string $separator Element's separator @return AbstractArray The created array
createFromString
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public static function createWithRange($low, $high, $step = 1) { return new static(range($low, $high, $step)); }
Create a new instance containing a range of elements. @param mixed $low First value of the sequence @param mixed $high The sequence is ended upon reaching the end value @param int $step Used as the increment between elements in the sequence @return AbstractArray The created array
createWithRange
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function contains($element) { return in_array($element, $this->elements, true); }
Check if the given value exists in the array. @param mixed $element Value to search for @return bool Returns true if the given value exists in the array, false otherwise
contains
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function containsKey($key) { return array_key_exists($key, $this->elements); }
Check if the given key/index exists in the array. @param mixed $key Key/index to search for @return bool Returns true if the given key/index exists in the array, false otherwise
containsKey
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function createClone() { return clone $this; }
Clone current instance to new instance. @deprecated Should be removed @return AbstractArray Shallow copy of $this
createClone
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function except(array $keys) { return new static(array_diff_key($this->elements, array_flip($keys))); }
Return slice of an array except given keys. @param array $keys List of keys to exclude @return AbstractArray The created array
except
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function exists(callable $func) { $isExists = false; foreach ($this->elements as $key => $value) { if ($func($key, $value)) { $isExists = true; break; } } return $isExists; }
Find the given value in An array using a closure @param callable $func @return bool Returns true if the given value is found, false otherwise
exists
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function find(callable $func) { $found = null; foreach ($this->elements as $key => $value) { if($func($value, $key)) { $found = $value; break; } } return $found; }
Returns the first occurrence of a value that satisfies the predicate $func. @param callable $func @return mixed The first occurrence found
find
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function getIterator() { return new ArrayIterator($this->elements); }
Create an iterator over this array. @link http://php.net/manual/en/iteratoraggregate.getiterator.php @return Traversable An instance of an object implementing <b>Iterator</b>
getIterator
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function getKeys() { return array_keys($this->elements); }
Return an array all the keys of this array. @return array An array of all keys
getKeys
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function getRandom() { return $this->offsetGet($this->getRandomKey()); }
Pick a random value out of this array. @return mixed Random value of array @throws \RangeException If array is empty
getRandom
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function getRandomKey() { return $this->getRandomKeys(1); }
Pick a random key/index from the keys of this array. @return mixed Random key/index of array @throws \RangeException If array is empty
getRandomKey
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function getRandomKeys($number) { $number = (int) $number; $count = $this->count(); if ($number === 0 || $number > $count) { throw new \RangeException(sprintf( 'Number of requested keys (%s) must be equal or lower than number of elements in this array (%s)', $number, $count )); } return array_rand($this->elements, $number); }
Pick a given number of random keys/indexes out of this array. @param int $number The number of keys/indexes (should be <= $this->count()) @return mixed Random keys or key of array @throws \RangeException
getRandomKeys
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function getRandomValues($number) { $values = []; $keys = $number > 1 ? $this->getRandomKeys($number) : [$this->getRandomKeys($number)]; foreach ($keys as $key) { $values[] = $this->offsetGet($key); } return $values; }
Pick a given number of random values with non-duplicate indexes out of the array. @param int $number The number of values (should be > 1 and < $this->count()) @return array Random values of array @throws \RangeException
getRandomValues
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function getValues() { return array_values($this->elements); }
Return an array of all values from this array numerically indexed. @return mixed An array of all values
getValues
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function indexOf($element) { return $this->search($element); }
Alias of search() method. 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
indexOf
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function isAssoc() { $isAssoc = false; if (!$this->isEmpty()) { $isAssoc = $this->checkType('string'); } return $isAssoc; }
Check whether array is associative or not. @return bool Returns true if associative, false otherwise
isAssoc
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function isEmpty() { return !$this->elements; }
Check whether the array is empty or not. @return bool Returns true if empty, false otherwise
isEmpty
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
private function checkType($type) { $isInType = true; foreach ($this->getKeys() as $key) { if (gettype($key) !== $type) { $isInType = false; break; } } return $isInType; }
Check if an array keys are in a given variable type. @param string $type @return bool
checkType
php
bocharsky-bw/Arrayzy
src/AbstractArray.php
https://github.com/bocharsky-bw/Arrayzy/blob/master/src/AbstractArray.php
MIT
public function isNumeric() { $isNumeric = false; if (!$this->isEmpty()) { $isNumeric = $this->checkType('integer'); } return $isNumeric; }
Check whether array is numeric or not. @return bool Returns true if numeric, false otherwise
isNumeric
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 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 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 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
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