code
stringlengths
17
247k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public static function contains($haystack, $needles, $ignoreCase = false) { if ($ignoreCase) { $haystack = mb_strtolower($haystack); } if (! is_iterable($needles)) { $needles = (array) $needles; } foreach ($needles as $needle) { if ($ignoreCase) { $needle = mb_strtolower($needle); } if ($needle !== '' && str_contains($haystack, $needle)) { return true; } } return false; }
Determine if a given string contains a given substring. @param string $haystack @param string|iterable<string> $needles @param bool $ignoreCase @return bool
contains
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function containsAll($haystack, $needles, $ignoreCase = false) { foreach ($needles as $needle) { if (! static::contains($haystack, $needle, $ignoreCase)) { return false; } } return true; }
Determine if a given string contains all array values. @param string $haystack @param iterable<string> $needles @param bool $ignoreCase @return bool
containsAll
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function doesntContain($haystack, $needles, $ignoreCase = false) { return ! static::contains($haystack, $needles, $ignoreCase); }
Determine if a given string doesn't contain a given substring. @param string $haystack @param string|iterable<string> $needles @param bool $ignoreCase @return bool
doesntContain
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function deduplicate(string $string, string $character = ' ') { return preg_replace('/'.preg_quote($character, '/').'+/u', $character, $string); }
Replace consecutive instances of a given character with a single character in the given string. @param string $string @param string $character @return string
deduplicate
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function endsWith($haystack, $needles) { if (! is_iterable($needles)) { $needles = (array) $needles; } if (is_null($haystack)) { return false; } foreach ($needles as $needle) { if ((string) $needle !== '' && str_ends_with($haystack, $needle)) { return true; } } return false; }
Determine if a given string ends with a given substring. @param string $haystack @param string|iterable<string> $needles @return bool
endsWith
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function excerpt($text, $phrase = '', $options = []) { $radius = $options['radius'] ?? 100; $omission = $options['omission'] ?? '...'; preg_match('/^(.*?)('.preg_quote((string) $phrase, '/').')(.*)$/iu', (string) $text, $matches); if (empty($matches)) { return null; } $start = ltrim($matches[1]); $start = Str::of(mb_substr($start, max(mb_strlen($start, 'UTF-8') - $radius, 0), $radius, 'UTF-8'))->ltrim()->unless( fn ($startWithRadius) => $startWithRadius->exactly($start), fn ($startWithRadius) => $startWithRadius->prepend($omission), ); $end = rtrim($matches[3]); $end = Str::of(mb_substr($end, 0, $radius, 'UTF-8'))->rtrim()->unless( fn ($endWithRadius) => $endWithRadius->exactly($end), fn ($endWithRadius) => $endWithRadius->append($omission), ); return $start->append($matches[2], $end)->toString(); }
Extracts an excerpt from text that matches the first instance of a phrase. @param string $text @param string $phrase @param array $options @return string|null
excerpt
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function unwrap($value, $before, $after = null) { if (static::startsWith($value, $before)) { $value = static::substr($value, static::length($before)); } if (static::endsWith($value, $after ??= $before)) { $value = static::substr($value, 0, -static::length($after)); } return $value; }
Unwrap the string with the given strings. @param string $value @param string $before @param string|null $after @return string
unwrap
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function isAscii($value) { return ASCII::is_ascii((string) $value); }
Determine if a given string is 7 bit ASCII. @param string $value @return bool
isAscii
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function isJson($value) { if (! is_string($value)) { return false; } if (function_exists('json_validate')) { return json_validate($value, 512); } try { json_decode($value, true, 512, JSON_THROW_ON_ERROR); } catch (JsonException) { return false; } return true; }
Determine if a given value is valid JSON. @param mixed $value @return bool
isJson
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function isUrl($value, array $protocols = []) { if (! is_string($value)) { return false; } $protocolList = empty($protocols) ? 'aaa|aaas|about|acap|acct|acd|acr|adiumxtra|adt|afp|afs|aim|amss|android|appdata|apt|ark|attachment|aw|barion|beshare|bitcoin|bitcoincash|blob|bolo|browserext|calculator|callto|cap|cast|casts|chrome|chrome-extension|cid|coap|coap\+tcp|coap\+ws|coaps|coaps\+tcp|coaps\+ws|com-eventbrite-attendee|content|conti|crid|cvs|dab|data|dav|diaspora|dict|did|dis|dlna-playcontainer|dlna-playsingle|dns|dntp|dpp|drm|drop|dtn|dvb|ed2k|elsi|example|facetime|fax|feed|feedready|file|filesystem|finger|first-run-pen-experience|fish|fm|ftp|fuchsia-pkg|geo|gg|git|gizmoproject|go|gopher|graph|gtalk|h323|ham|hcap|hcp|http|https|hxxp|hxxps|hydrazone|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris\.beep|iris\.lwz|iris\.xpc|iris\.xpcs|isostore|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|leaptofrogans|lorawan|lvlt|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|mongodb|moz|ms-access|ms-browser-extension|ms-calculator|ms-drive-to|ms-enrollment|ms-excel|ms-eyecontrolspeech|ms-gamebarservices|ms-gamingoverlay|ms-getoffice|ms-help|ms-infopath|ms-inputapp|ms-lockscreencomponent-config|ms-media-stream-id|ms-mixedrealitycapture|ms-mobileplans|ms-officeapp|ms-people|ms-project|ms-powerpoint|ms-publisher|ms-restoretabcompanion|ms-screenclip|ms-screensketch|ms-search|ms-search-repair|ms-secondary-screen-controller|ms-secondary-screen-setup|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-connectabledevices|ms-settings-displays-topology|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|ms-spd|ms-sttoverlay|ms-transit-to|ms-useractivityset|ms-virtualtouchpad|ms-visio|ms-walk-to|ms-whiteboard|ms-whiteboard-cmd|ms-word|msnim|msrp|msrps|mss|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|ocf|oid|onenote|onenote-cmd|opaquelocktoken|openpgp4fpr|pack|palm|paparazzi|payto|pkcs11|platform|pop|pres|prospero|proxy|pwid|psyc|pttp|qb|query|redis|rediss|reload|res|resource|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|s3|secondlife|service|session|sftp|sgn|shttp|sieve|simpleledger|sip|sips|skype|smb|sms|smtp|snews|snmp|soap\.beep|soap\.beeps|soldat|spiffe|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|tg|things|thismessage|tip|tn3270|tool|ts3server|turn|turns|tv|udp|unreal|urn|ut2004|v-event|vemmi|ventrilo|videotex|vnc|view-source|wais|webcal|wpid|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\.beep|xmlrpc\.beeps|xmpp|xri|ymsgr|z39\.50|z39\.50r|z39\.50s' : implode('|', $protocols); /* * This pattern is derived from Symfony\Component\Validator\Constraints\UrlValidator (5.0.7). * * (c) Fabien Potencier <[email protected]> http://symfony.com */ $pattern = '~^ (LARAVEL_PROTOCOLS):// # protocol (((?:[\_\.\pL\pN-]|%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%[0-9A-Fa-f]{2})+)@)? # basic auth ( ([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name | # or \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address | # or \[ (?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::)))) \] # an IPv6 address ) (:[0-9]+)? # a port (optional) (?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%[0-9A-Fa-f]{2})* )* # a path (?:\? (?:[\pL\pN\-._\~!$&\'\[\]()*+,;=:@/?]|%[0-9A-Fa-f]{2})* )? # a query (optional) (?:\# (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%[0-9A-Fa-f]{2})* )? # a fragment (optional) $~ixu'; return preg_match(str_replace('LARAVEL_PROTOCOLS', $protocolList, $pattern), $value) > 0; }
Determine if a given value is a valid URL. @param mixed $value @param array $protocols @return bool
isUrl
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function isUuid($value, $version = null) { if (! is_string($value)) { return false; } if ($version === null) { return preg_match('/^[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}$/D', $value) > 0; } $factory = new UuidFactory; try { $factoryUuid = $factory->fromString($value); } catch (InvalidUuidStringException) { return false; } $fields = $factoryUuid->getFields(); if (! ($fields instanceof FieldsInterface)) { return false; } if ($version === 0 || $version === 'nil') { return $fields->isNil(); } if ($version === 'max') { return $fields->isMax(); } return $fields->getVersion() === $version; }
Determine if a given value is a valid UUID. @param mixed $value @param int<0, 8>|'max'|null $version @return bool
isUuid
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function isUlid($value) { if (! is_string($value)) { return false; } return Ulid::isValid($value); }
Determine if a given value is a valid ULID. @param mixed $value @return bool
isUlid
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function length($value, $encoding = null) { return mb_strlen($value, $encoding); }
Return the length of the given string. @param string $value @param string|null $encoding @return int
length
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function limit($value, $limit = 100, $end = '...', $preserveWords = false) { if (mb_strwidth($value, 'UTF-8') <= $limit) { return $value; } if (! $preserveWords) { return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; } $value = trim(preg_replace('/[\n\r]+/', ' ', strip_tags($value))); $trimmed = rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')); if (mb_substr($value, $limit, 1, 'UTF-8') === ' ') { return $trimmed.$end; } return preg_replace("/(.*)\s.*/", '$1', $trimmed).$end; }
Limit the number of characters in a string. @param string $value @param int $limit @param string $end @param bool $preserveWords @return string
limit
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function words($value, $words = 100, $end = '...') { preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { return $value; } return rtrim($matches[0]).$end; }
Limit the number of words in a string. @param string $value @param int $words @param string $end @return string
words
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function mask($string, $character, $index, $length = null, $encoding = 'UTF-8') { if ($character === '') { return $string; } $segment = mb_substr($string, $index, $length, $encoding); if ($segment === '') { return $string; } $strlen = mb_strlen($string, $encoding); $startIndex = $index; if ($index < 0) { $startIndex = $index < -$strlen ? 0 : $strlen + $index; } $start = mb_substr($string, 0, $startIndex, $encoding); $segmentLen = mb_strlen($segment, $encoding); $end = mb_substr($string, $startIndex + $segmentLen); return $start.str_repeat(mb_substr($character, 0, 1, $encoding), $segmentLen).$end; }
Masks a portion of a string with a repeated character. @param string $string @param string $character @param int $index @param int|null $length @param string $encoding @return string
mask
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function matchAll($pattern, $subject) { preg_match_all($pattern, $subject, $matches); if (empty($matches[0])) { return new Collection; } return new Collection($matches[1] ?? $matches[0]); }
Get the string matching the given pattern. @param string $pattern @param string $subject @return \Illuminate\Support\Collection
matchAll
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function numbers($value) { return preg_replace('/[^0-9]/', '', $value); }
Remove all non-numeric characters from a string. @param string $value @return string
numbers
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function padBoth($value, $length, $pad = ' ') { if (function_exists('mb_str_pad')) { return mb_str_pad($value, $length, $pad, STR_PAD_BOTH); } $short = max(0, $length - mb_strlen($value)); $shortLeft = floor($short / 2); $shortRight = ceil($short / 2); return mb_substr(str_repeat($pad, $shortLeft), 0, $shortLeft). $value. mb_substr(str_repeat($pad, $shortRight), 0, $shortRight); }
Pad both sides of a string with another. @param string $value @param int $length @param string $pad @return string
padBoth
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function padLeft($value, $length, $pad = ' ') { if (function_exists('mb_str_pad')) { return mb_str_pad($value, $length, $pad, STR_PAD_LEFT); } $short = max(0, $length - mb_strlen($value)); return mb_substr(str_repeat($pad, $short), 0, $short).$value; }
Pad the left side of a string with another. @param string $value @param int $length @param string $pad @return string
padLeft
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function padRight($value, $length, $pad = ' ') { if (function_exists('mb_str_pad')) { return mb_str_pad($value, $length, $pad, STR_PAD_RIGHT); } $short = max(0, $length - mb_strlen($value)); return $value.mb_substr(str_repeat($pad, $short), 0, $short); }
Pad the right side of a string with another. @param string $value @param int $length @param string $pad @return string
padRight
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function parseCallback($callback, $default = null) { if (static::contains($callback, "@anonymous\0")) { if (static::substrCount($callback, '@') > 1) { return [ static::beforeLast($callback, '@'), static::afterLast($callback, '@'), ]; } return [$callback, $default]; } return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; }
Parse a Class[@]method style callback into class and method. @param string $callback @param string|null $default @return array<int, string|null>
parseCallback
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function pluralStudly($value, $count = 2) { $parts = preg_split('/(.)(?=[A-Z])/u', $value, -1, PREG_SPLIT_DELIM_CAPTURE); $lastWord = array_pop($parts); return implode('', $parts).self::plural($lastWord, $count); }
Pluralize the last word of an English, studly caps case string. @param string $value @param int|array|\Countable $count @return string
pluralStudly
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function pluralPascal($value, $count = 2) { return static::pluralStudly($value, $count); }
Pluralize the last word of an English, Pascal caps case string. @param string $value @param int|array|\Countable $count @return string
pluralPascal
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function password($length = 32, $letters = true, $numbers = true, $symbols = true, $spaces = false) { $password = new Collection(); $options = (new Collection([ 'letters' => $letters === true ? [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ] : null, 'numbers' => $numbers === true ? [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ] : null, 'symbols' => $symbols === true ? [ '~', '!', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '.', ',', '<', '>', '?', '/', '\\', '{', '}', '[', ']', '|', ':', ';', ] : null, 'spaces' => $spaces === true ? [' '] : null, ])) ->filter() ->each(fn ($c) => $password->push($c[random_int(0, count($c) - 1)])) ->flatten(); $length = $length - $password->count(); return $password->merge($options->pipe( fn ($c) => Collection::times($length, fn () => $c[random_int(0, $c->count() - 1)]) ))->shuffle()->implode(''); }
Generate a random, secure password. @param int $length @param bool $letters @param bool $numbers @param bool $symbols @param bool $spaces @return string
password
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function position($haystack, $needle, $offset = 0, $encoding = null) { return mb_strpos($haystack, (string) $needle, $offset, $encoding); }
Find the multi-byte safe position of the first occurrence of a given substring in a string. @param string $haystack @param string $needle @param int $offset @param string|null $encoding @return int|false
position
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function createRandomStringsUsing(?callable $factory = null) { static::$randomStringFactory = $factory; }
Set the callable that will be used to generate random strings. @param callable|null $factory @return void
createRandomStringsUsing
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function createRandomStringsNormally() { static::$randomStringFactory = null; }
Indicate that random strings should be created normally and not using a custom factory. @return void
createRandomStringsNormally
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
private static function toStringOr($value, $fallback) { try { return (string) $value; } catch (Throwable $e) { return $fallback; } }
Convert the given value to a string or return the given fallback on failure. @param mixed $value @param string $fallback @return string
toStringOr
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function replace($search, $replace, $subject, $caseSensitive = true) { if ($search instanceof Traversable) { $search = (new Collection($search))->all(); } if ($replace instanceof Traversable) { $replace = (new Collection($replace))->all(); } if ($subject instanceof Traversable) { $subject = (new Collection($subject))->all(); } return $caseSensitive ? str_replace($search, $replace, $subject) : str_ireplace($search, $replace, $subject); }
Replace the given value in the given string. @param string|iterable<string> $search @param string|iterable<string> $replace @param string|iterable<string> $subject @param bool $caseSensitive @return string|string[]
replace
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function remove($search, $subject, $caseSensitive = true) { if ($search instanceof Traversable) { $search = (new Collection($search))->all(); } return $caseSensitive ? str_replace($search, '', $subject) : str_ireplace($search, '', $subject); }
Remove any occurrence of the given string in the subject. @param string|iterable<string> $search @param string|iterable<string> $subject @param bool $caseSensitive @return string
remove
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function headline($value) { $parts = explode(' ', $value); $parts = count($parts) > 1 ? array_map(static::title(...), $parts) : array_map(static::title(...), static::ucsplit(implode('_', $parts))); $collapsed = static::replace(['-', '_', ' '], '_', implode('_', $parts)); return implode(' ', array_filter(explode('_', $collapsed))); }
Convert the given string to proper case for each word. @param string $value @return string
headline
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function slug($title, $separator = '-', $language = 'en', $dictionary = ['@' => 'at']) { $title = $language ? static::ascii($title, $language) : $title; // Convert all dashes/underscores into separator $flip = $separator === '-' ? '_' : '-'; $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); // Replace dictionary words foreach ($dictionary as $key => $value) { $dictionary[$key] = $separator.$value.$separator; } $title = str_replace(array_keys($dictionary), array_values($dictionary), $title); // Remove all characters that are not the separator, letters, numbers, or whitespace $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', static::lower($title)); // Replace all separator characters and whitespace by a single separator $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); return trim($title, $separator); }
Generate a URL friendly "slug" from a given string. @param string $title @param string $separator @param string|null $language @param array<string, string> $dictionary @return string
slug
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function trim($value, $charlist = null) { if ($charlist === null) { $trimDefaultCharacters = " \n\r\t\v\0"; return preg_replace('~^[\s\x{FEFF}\x{200B}\x{200E}'.$trimDefaultCharacters.']+|[\s\x{FEFF}\x{200B}\x{200E}'.$trimDefaultCharacters.']+$~u', '', $value) ?? trim($value); } return trim($value, $charlist); }
Remove all whitespace from both ends of a string. @param string $value @param string|null $charlist @return string
trim
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function ltrim($value, $charlist = null) { if ($charlist === null) { $ltrimDefaultCharacters = " \n\r\t\v\0"; return preg_replace('~^[\s\x{FEFF}\x{200B}\x{200E}'.$ltrimDefaultCharacters.']+~u', '', $value) ?? ltrim($value); } return ltrim($value, $charlist); }
Remove all whitespace from the beginning of a string. @param string $value @param string|null $charlist @return string
ltrim
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function rtrim($value, $charlist = null) { if ($charlist === null) { $rtrimDefaultCharacters = " \n\r\t\v\0"; return preg_replace('~[\s\x{FEFF}\x{200B}\x{200E}'.$rtrimDefaultCharacters.']+$~u', '', $value) ?? rtrim($value); } return rtrim($value, $charlist); }
Remove all whitespace from the end of a string. @param string $value @param string|null $charlist @return string
rtrim
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function squish($value) { return preg_replace('~(\s|\x{3164}|\x{1160})+~u', ' ', static::trim($value)); }
Remove all "extra" blank space from the given string. @param string $value @return string
squish
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function startsWith($haystack, $needles) { if (! is_iterable($needles)) { $needles = [$needles]; } if (is_null($haystack)) { return false; } foreach ($needles as $needle) { if ((string) $needle !== '' && str_starts_with($haystack, $needle)) { return true; } } return false; }
Determine if a given string starts with a given substring. @param string $haystack @param string|iterable<string> $needles @return bool
startsWith
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function pascal($value) { return static::studly($value); }
Convert a value to Pascal case. @param string $value @return string
pascal
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function substr($string, $start, $length = null, $encoding = 'UTF-8') { return mb_substr($string, $start, $length, $encoding); }
Returns the portion of the string specified by the start and length parameters. @param string $string @param int $start @param int|null $length @param string $encoding @return string
substr
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function substrCount($haystack, $needle, $offset = 0, $length = null) { if (! is_null($length)) { return substr_count($haystack, $needle, $offset, $length); } return substr_count($haystack, $needle, $offset); }
Returns the number of substring occurrences. @param string $haystack @param string $needle @param int $offset @param int|null $length @return int
substrCount
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function substrReplace($string, $replace, $offset = 0, $length = null) { if ($length === null) { $length = strlen($string); } return substr_replace($string, $replace, $offset, $length); }
Replace text within a portion of a string. @param string|string[] $string @param string|string[] $replace @param int|int[] $offset @param int|int[]|null $length @return string|string[]
substrReplace
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function swap(array $map, $subject) { return strtr($subject, $map); }
Swap multiple keywords in a string with other keywords. @param array $map @param string $subject @return string
swap
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function fromBase64($string, $strict = false) { return base64_decode($string, $strict); }
Decode the given Base64 encoded string. @param string $string @param bool $strict @return string|false
fromBase64
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function lcfirst($string) { return static::lower(static::substr($string, 0, 1)).static::substr($string, 1); }
Make a string's first character lowercase. @param string $string @return string
lcfirst
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function ucsplit($string) { return preg_split('/(?=\p{Lu})/u', $string, -1, PREG_SPLIT_NO_EMPTY); }
Split a string into pieces by uppercase characters. @param string $string @return string[]
ucsplit
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function wordCount($string, $characters = null) { return str_word_count($string, 0, $characters); }
Get the number of words a string contains. @param string $string @param string|null $characters @return int
wordCount
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function wordWrap($string, $characters = 75, $break = "\n", $cutLongWords = false) { return wordwrap($string, $characters, $break, $cutLongWords); }
Wrap a string to a given number of characters. @param string $string @param int $characters @param string $break @param bool $cutLongWords @return string
wordWrap
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function createUuidsUsing(?callable $factory = null) { static::$uuidFactory = $factory; }
Set the callable that will be used to generate UUIDs. @param callable|null $factory @return void
createUuidsUsing
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function createUuidsNormally() { static::$uuidFactory = null; }
Indicate that UUIDs should be created normally and not using a custom factory. @return void
createUuidsNormally
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function createUlidsNormally() { static::$ulidFactory = null; }
Indicate that ULIDs should be created normally and not using a custom factory. @return void
createUlidsNormally
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function createUlidsUsing(?callable $factory = null) { static::$ulidFactory = $factory; }
Set the callable that will be used to generate ULIDs. @param callable|null $factory @return void
createUlidsUsing
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function flushCache() { static::$snakeCache = []; static::$camelCache = []; static::$studlyCache = []; }
Remove all strings from the casing caches. @return void
flushCache
php
laravel/framework
src/Illuminate/Support/Str.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php
MIT
public static function useDefault() { static::$dateClass = null; static::$callable = null; static::$factory = null; }
Use the default date class when generating dates. @return void
useDefault
php
laravel/framework
src/Illuminate/Support/DateFactory.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/DateFactory.php
MIT
public static function useCallable(callable $callable) { static::$callable = $callable; static::$dateClass = null; static::$factory = null; }
Execute the given callable on each date creation. @param callable $callable @return void
useCallable
php
laravel/framework
src/Illuminate/Support/DateFactory.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/DateFactory.php
MIT
public static function useClass($dateClass) { static::$dateClass = $dateClass; static::$factory = null; static::$callable = null; }
Use the given date type (class) when generating dates. @param string $dateClass @return void
useClass
php
laravel/framework
src/Illuminate/Support/DateFactory.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/DateFactory.php
MIT
public static function useFactory($factory) { static::$factory = $factory; static::$dateClass = null; static::$callable = null; }
Use the given Carbon factory when generating dates. @param object $factory @return void
useFactory
php
laravel/framework
src/Illuminate/Support/DateFactory.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/DateFactory.php
MIT
public function __call($method, $parameters) { $defaultClassName = static::DEFAULT_CLASS_NAME; // Using callable to generate dates... if (static::$callable) { return call_user_func(static::$callable, $defaultClassName::$method(...$parameters)); } // Using Carbon factory to generate dates... if (static::$factory) { return static::$factory->$method(...$parameters); } $dateClass = static::$dateClass ?: $defaultClassName; // Check if the date can be created using the public class method... if (method_exists($dateClass, $method) || method_exists($dateClass, 'hasMacro') && $dateClass::hasMacro($method)) { return $dateClass::$method(...$parameters); } // If that fails, create the date with the default class... $date = $defaultClassName::$method(...$parameters); // If the configured class has an "instance" method, we'll try to pass our date into there... if (method_exists($dateClass, 'instance')) { return $dateClass::instance($date); } // Otherwise, assume the configured class has a DateTime compatible constructor... return new $dateClass($date->format('Y-m-d H:i:s.u'), $date->getTimezone()); }
Handle dynamic calls to generate dates. @param string $method @param array $parameters @return mixed @throws \RuntimeException
__call
php
laravel/framework
src/Illuminate/Support/DateFactory.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/DateFactory.php
MIT
public function while(Closure $callback) { $this->while = $callback; return $this; }
Sleep while a given callback returns "true". @param \Closure $callback @return $this
while
php
laravel/framework
src/Illuminate/Support/Sleep.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Sleep.php
MIT
public function then(callable $then) { $this->goodnight(); $this->alreadySlept = true; return $then(); }
Specify a callback that should be executed after sleeping. @param callable $then @return mixed
then
php
laravel/framework
src/Illuminate/Support/Sleep.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Sleep.php
MIT
public function getBag($key) { return Arr::get($this->bags, $key) ?: new MessageBag; }
Get a MessageBag instance from the bags. @param string $key @return \Illuminate\Contracts\Support\MessageBag
getBag
php
laravel/framework
src/Illuminate/Support/ViewErrorBag.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ViewErrorBag.php
MIT
public function put($key, MessageBagContract $bag) { $this->bags[$key] = $bag; return $this; }
Add a new MessageBag instance to the bags. @param string $key @param \Illuminate\Contracts\Support\MessageBag $bag @return $this
put
php
laravel/framework
src/Illuminate/Support/ViewErrorBag.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ViewErrorBag.php
MIT
public function __call($method, $parameters) { return $this->getBag('default')->$method(...$parameters); }
Dynamically call methods on the default bag. @param string $method @param array $parameters @return mixed
__call
php
laravel/framework
src/Illuminate/Support/ViewErrorBag.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ViewErrorBag.php
MIT
public function __toString() { return (string) $this->getBag('default'); }
Convert the default bag to its string representation. @return string
__toString
php
laravel/framework
src/Illuminate/Support/ViewErrorBag.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ViewErrorBag.php
MIT
public function get($key, $default = null) { return data_get($this->attributes, $key, $default); }
Get an attribute from the fluent instance using "dot" notation. @template TGetDefault @param TKey $key @param TGetDefault|(\Closure(): TGetDefault) $default @return TValue|TGetDefault
get
php
laravel/framework
src/Illuminate/Support/Fluent.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Fluent.php
MIT
public function set($key, $value) { data_set($this->attributes, $key, $value); return $this; }
Set an attribute on the fluent instance using "dot" notation. @param TKey $key @param TValue $value @return $this
set
php
laravel/framework
src/Illuminate/Support/Fluent.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Fluent.php
MIT
public function fill($attributes) { foreach ($attributes as $key => $value) { $this->attributes[$key] = $value; } return $this; }
Fill the fluent instance with an array of attributes. @param iterable<TKey, TValue> $attributes @return $this
fill
php
laravel/framework
src/Illuminate/Support/Fluent.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Fluent.php
MIT
public function value($key, $default = null) { if (array_key_exists($key, $this->attributes)) { return $this->attributes[$key]; } return value($default); }
Get an attribute from the fluent instance. @param string $key @param mixed $default @return mixed
value
php
laravel/framework
src/Illuminate/Support/Fluent.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Fluent.php
MIT
public function scope($key, $default = null) { return new static( (array) $this->get($key, $default) ); }
Get the value of the given key as a new Fluent instance. @param string $key @param mixed $default @return static
scope
php
laravel/framework
src/Illuminate/Support/Fluent.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Fluent.php
MIT
protected function runTimeForHumans($startTime, $endTime = null) { $endTime ??= microtime(true); $runTime = ($endTime - $startTime) * 1000; return $runTime > 1000 ? CarbonInterval::milliseconds($runTime)->cascade()->forHumans(short: true) : number_format($runTime, 2).'ms'; }
Given a start time, format the total run time for human readability. @param float $startTime @param float $endTime @return string
runTimeForHumans
php
laravel/framework
src/Illuminate/Support/InteractsWithTime.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/InteractsWithTime.php
MIT
public function getMessages() { return $this->messages(); }
Get the raw messages in the message bag. @return array<string, array<string>>
getMessages
php
laravel/framework
src/Illuminate/Support/MessageBag.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/MessageBag.php
MIT
public function __construct(Container $container) { $this->container = $container; $this->config = $container->make('config'); }
Create a new manager instance. @param \Illuminate\Contracts\Container\Container $container
__construct
php
laravel/framework
src/Illuminate/Support/Manager.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Manager.php
MIT
public function __construct( public string $hash, public ?object $object, public $callable, ) { // }
Create a new onceable instance. @param string $hash @param object|null $object @param callable $callable
__construct
php
laravel/framework
src/Illuminate/Support/Onceable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Onceable.php
MIT
public static function tryFromTrace(array $trace, callable $callable) { if (! is_null($hash = static::hashFromTrace($trace, $callable))) { $object = static::objectFromTrace($trace); return new static($hash, $object, $callable); } }
Tries to create a new onceable instance from the given trace. @param array<int, array<string, mixed>> $trace @return static|null
tryFromTrace
php
laravel/framework
src/Illuminate/Support/Onceable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Onceable.php
MIT
protected static function hashFromTrace(array $trace, callable $callable) { if (str_contains($trace[0]['file'] ?? '', 'eval()\'d code')) { return null; } $uses = array_map( fn (mixed $argument) => is_object($argument) ? spl_object_hash($argument) : $argument, $callable instanceof Closure ? (new ReflectionClosure($callable))->getClosureUsedVariables() : [], ); $class = $callable instanceof Closure ? (new ReflectionClosure($callable))->getClosureCalledClass()?->getName() : null; $class ??= isset($trace[1]['class']) ? $trace[1]['class'] : null; return hash('xxh128', sprintf( '%s@%s%s:%s (%s)', $trace[0]['file'], $class ? $class.'@' : '', $trace[1]['function'], $trace[0]['line'], serialize($uses), )); }
Computes the hash of the onceable from the given trace. @param array<int, array<string, mixed>> $trace @return string|null
hashFromTrace
php
laravel/framework
src/Illuminate/Support/Onceable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Onceable.php
MIT
public function __construct(UriInterface|Stringable|string $uri = '') { $this->uri = $uri instanceof UriInterface ? $uri : LeagueUri::new((string) $uri); }
Create a new parsed URI instance.
__construct
php
laravel/framework
src/Illuminate/Support/Uri.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Uri.php
MIT
public function dump(...$args) { dump($this->value(), ...$args); return $this; }
Dump the string representation of the URI. @param mixed ...$args @return $this
dump
php
laravel/framework
src/Illuminate/Support/Uri.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Uri.php
MIT
public static function isCallable($var, $syntaxOnly = false) { if (! is_array($var)) { return is_callable($var, $syntaxOnly); } if (! isset($var[0], $var[1]) || ! is_string($var[1] ?? null)) { return false; } if ($syntaxOnly && (is_string($var[0]) || is_object($var[0])) && is_string($var[1])) { return true; } $class = is_object($var[0]) ? get_class($var[0]) : $var[0]; $method = $var[1]; if (! class_exists($class)) { return false; } if (method_exists($class, $method)) { return (new ReflectionMethod($class, $method))->isPublic(); } if (is_object($var[0]) && method_exists($class, '__call')) { return (new ReflectionMethod($class, '__call'))->isPublic(); } if (! is_object($var[0]) && method_exists($class, '__callStatic')) { return (new ReflectionMethod($class, '__callStatic'))->isPublic(); } return false; }
This is a PHP 7.4 compatible implementation of is_callable. @param mixed $var @param bool $syntaxOnly @return bool
isCallable
php
laravel/framework
src/Illuminate/Support/Reflector.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Reflector.php
MIT
public static function getParameterClassName($parameter) { $type = $parameter->getType(); if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) { return; } return static::getTypeName($parameter, $type); }
Get the class name of the given parameter's type, if possible. @param \ReflectionParameter $parameter @return string|null
getParameterClassName
php
laravel/framework
src/Illuminate/Support/Reflector.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Reflector.php
MIT
protected static function getTypeName($parameter, $type) { $name = $type->getName(); if (! is_null($class = $parameter->getDeclaringClass())) { if ($name === 'self') { return $class->getName(); } if ($name === 'parent' && $parent = $class->getParentClass()) { return $parent->getName(); } } return $name; }
Get the given type's class name. @param \ReflectionParameter $parameter @param \ReflectionNamedType $type @return string
getTypeName
php
laravel/framework
src/Illuminate/Support/Reflector.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Reflector.php
MIT
public static function isParameterSubclassOf($parameter, $className) { $paramClassName = static::getParameterClassName($parameter); return $paramClassName && (class_exists($paramClassName) || interface_exists($paramClassName)) && (new ReflectionClass($paramClassName))->isSubclassOf($className); }
Determine if the parameter's type is a subclass of the given type. @param \ReflectionParameter $parameter @param string $className @return bool
isParameterSubclassOf
php
laravel/framework
src/Illuminate/Support/Reflector.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Reflector.php
MIT
public static function isParameterBackedEnumWithStringBackingType($parameter) { if (! $parameter->getType() instanceof ReflectionNamedType) { return false; } $backedEnumClass = $parameter->getType()?->getName(); if (is_null($backedEnumClass)) { return false; } if (enum_exists($backedEnumClass)) { $reflectionBackedEnum = new ReflectionEnum($backedEnumClass); return $reflectionBackedEnum->isBacked() && $reflectionBackedEnum->getBackingType()->getName() == 'string'; } return false; }
Determine if the parameter's type is a Backed Enum with a string backing type. @param \ReflectionParameter $parameter @return bool
isParameterBackedEnumWithStringBackingType
php
laravel/framework
src/Illuminate/Support/Reflector.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Reflector.php
MIT
protected function parseBasicSegments(array $segments) { // The first segment in a basic array will always be the group, so we can go // ahead and grab that segment. If there is only one total segment we are // just pulling an entire group out of the array and not a single item. $group = $segments[0]; // If there is more than one segment in this group, it means we are pulling // a specific item out of a group and will need to return this item name // as well as the group so we know which item to pull from the arrays. $item = count($segments) === 1 ? null : implode('.', array_slice($segments, 1)); return [null, $group, $item]; }
Parse an array of basic segments. @param array $segments @return array
parseBasicSegments
php
laravel/framework
src/Illuminate/Support/NamespacedItemResolver.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/NamespacedItemResolver.php
MIT
protected function parseNamespacedSegments($key) { [$namespace, $item] = explode('::', $key); // First we'll just explode the first segment to get the namespace and group // since the item should be in the remaining segments. Once we have these // two pieces of data we can proceed with parsing out the item's value. $itemSegments = explode('.', $item); $groupAndItem = array_slice( $this->parseBasicSegments($itemSegments), 1 ); return array_merge([$namespace], $groupAndItem); }
Parse an array of namespaced segments. @param string $key @return array
parseNamespacedSegments
php
laravel/framework
src/Illuminate/Support/NamespacedItemResolver.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/NamespacedItemResolver.php
MIT
public function setParsedKey($key, $parsed) { $this->parsed[$key] = $parsed; }
Set the parsed value of a key. @param string $key @param array $parsed @return void
setParsedKey
php
laravel/framework
src/Illuminate/Support/NamespacedItemResolver.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/NamespacedItemResolver.php
MIT
public function flushParsedKeys() { $this->parsed = []; }
Flush the cache of parsed keys. @return void
flushParsedKeys
php
laravel/framework
src/Illuminate/Support/NamespacedItemResolver.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/NamespacedItemResolver.php
MIT
public function append(...$values) { return new static($this->value.implode('', $values)); }
Append the given values to the string. @param array|string ...$values @return static
append
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function newLine($count = 1) { return $this->append(str_repeat(PHP_EOL, $count)); }
Append a new line to the string. @param int $count @return $this
newLine
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function betweenFirst($from, $to) { return new static(Str::betweenFirst($this->value, $from, $to)); }
Get the smallest possible portion of a string between two given values. @param string $from @param string $to @return static
betweenFirst
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function contains($needles, $ignoreCase = false) { return Str::contains($this->value, $needles, $ignoreCase); }
Determine if a given string contains a given substring. @param string|iterable<string> $needles @param bool $ignoreCase @return bool
contains
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function containsAll($needles, $ignoreCase = false) { return Str::containsAll($this->value, $needles, $ignoreCase); }
Determine if a given string contains all array values. @param iterable<string> $needles @param bool $ignoreCase @return bool
containsAll
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function deduplicate(string $character = ' ') { return new static(Str::deduplicate($this->value, $character)); }
Replace consecutive instances of a given character with a single character. @param string $character @return static
deduplicate
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function exactly($value) { if ($value instanceof Stringable) { $value = $value->toString(); } return $this->value === $value; }
Determine if the string is an exact match with the given value. @param \Illuminate\Support\Stringable|string $value @return bool
exactly
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function excerpt($phrase = '', $options = []) { return Str::excerpt($this->value, $phrase, $options); }
Extracts an excerpt from text that matches the first instance of a phrase. @param string $phrase @param array $options @return string|null
excerpt
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function explode($delimiter, $limit = PHP_INT_MAX) { return new Collection(explode($delimiter, $this->value, $limit)); }
Explode the string into a collection. @param string $delimiter @param int $limit @return \Illuminate\Support\Collection<int, string>
explode
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function split($pattern, $limit = -1, $flags = 0) { if (filter_var($pattern, FILTER_VALIDATE_INT) !== false) { return new Collection(mb_str_split($this->value, $pattern)); } $segments = preg_split($pattern, $this->value, $limit, $flags); return ! empty($segments) ? new Collection($segments) : new Collection; }
Split a string using a regular expression or by length. @param string|int $pattern @param int $limit @param int $flags @return \Illuminate\Support\Collection<int, string>
split
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function isJson() { return Str::isJson($this->value); }
Determine if a given string is valid JSON. @return bool
isJson
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function isUrl() { return Str::isUrl($this->value); }
Determine if a given value is a valid URL. @return bool
isUrl
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function isUuid() { return Str::isUuid($this->value); }
Determine if a given string is a valid UUID. @return bool
isUuid
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT
public function isUlid() { return Str::isUlid($this->value); }
Determine if a given string is a valid ULID. @return bool
isUlid
php
laravel/framework
src/Illuminate/Support/Stringable.php
https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Stringable.php
MIT