PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.3.1
Independent Analytics – WordPress Analytics Plugin v2.3.1
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / support / Stringable.php
independent-analytics / vendor / illuminate / support Last commit date
Facades 2 years ago Testing 2 years ago Traits 2 years ago AggregateServiceProvider.php 2 years ago Carbon.php 2 years ago Composer.php 2 years ago ConfigurationUrlParser.php 2 years ago DateFactory.php 2 years ago Env.php 2 years ago Fluent.php 2 years ago HigherOrderTapProxy.php 2 years ago HtmlString.php 2 years ago InteractsWithTime.php 2 years ago Js.php 2 years ago Manager.php 2 years ago MessageBag.php 2 years ago MultipleInstanceManager.php 2 years ago NamespacedItemResolver.php 2 years ago Optional.php 2 years ago Pluralizer.php 2 years ago ProcessUtils.php 2 years ago Reflector.php 2 years ago ServiceProvider.php 2 years ago Str.php 2 years ago Stringable.php 2 years ago Timebox.php 2 years ago ValidatedInput.php 2 years ago ViewErrorBag.php 2 years ago helpers.php 2 years ago
Stringable.php
933 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Support;
4
5 use Closure;
6 use IAWPSCOPED\Illuminate\Support\Traits\Conditionable;
7 use IAWPSCOPED\Illuminate\Support\Traits\Macroable;
8 use IAWPSCOPED\Illuminate\Support\Traits\Tappable;
9 use JsonSerializable;
10 use IAWPSCOPED\Symfony\Component\VarDumper\VarDumper;
11 /** @internal */
12 class Stringable implements JsonSerializable
13 {
14 use Conditionable, Macroable, Tappable;
15 /**
16 * The underlying string value.
17 *
18 * @var string
19 */
20 protected $value;
21 /**
22 * Create a new instance of the class.
23 *
24 * @param string $value
25 * @return void
26 */
27 public function __construct($value = '')
28 {
29 $this->value = (string) $value;
30 }
31 /**
32 * Return the remainder of a string after the first occurrence of a given value.
33 *
34 * @param string $search
35 * @return static
36 */
37 public function after($search)
38 {
39 return new static(Str::after($this->value, $search));
40 }
41 /**
42 * Return the remainder of a string after the last occurrence of a given value.
43 *
44 * @param string $search
45 * @return static
46 */
47 public function afterLast($search)
48 {
49 return new static(Str::afterLast($this->value, $search));
50 }
51 /**
52 * Append the given values to the string.
53 *
54 * @param array $values
55 * @return static
56 */
57 public function append(...$values)
58 {
59 return new static($this->value . \implode('', $values));
60 }
61 /**
62 * Transliterate a UTF-8 value to ASCII.
63 *
64 * @param string $language
65 * @return static
66 */
67 public function ascii($language = 'en')
68 {
69 return new static(Str::ascii($this->value, $language));
70 }
71 /**
72 * Get the trailing name component of the path.
73 *
74 * @param string $suffix
75 * @return static
76 */
77 public function basename($suffix = '')
78 {
79 return new static(\basename($this->value, $suffix));
80 }
81 /**
82 * Get the basename of the class path.
83 *
84 * @return static
85 */
86 public function classBasename()
87 {
88 return new static(class_basename($this->value));
89 }
90 /**
91 * Get the portion of a string before the first occurrence of a given value.
92 *
93 * @param string $search
94 * @return static
95 */
96 public function before($search)
97 {
98 return new static(Str::before($this->value, $search));
99 }
100 /**
101 * Get the portion of a string before the last occurrence of a given value.
102 *
103 * @param string $search
104 * @return static
105 */
106 public function beforeLast($search)
107 {
108 return new static(Str::beforeLast($this->value, $search));
109 }
110 /**
111 * Get the portion of a string between two given values.
112 *
113 * @param string $from
114 * @param string $to
115 * @return static
116 */
117 public function between($from, $to)
118 {
119 return new static(Str::between($this->value, $from, $to));
120 }
121 /**
122 * Convert a value to camel case.
123 *
124 * @return static
125 */
126 public function camel()
127 {
128 return new static(Str::camel($this->value));
129 }
130 /**
131 * Determine if a given string contains a given substring.
132 *
133 * @param string|array $needles
134 * @return bool
135 */
136 public function contains($needles)
137 {
138 return Str::contains($this->value, $needles);
139 }
140 /**
141 * Determine if a given string contains all array values.
142 *
143 * @param array $needles
144 * @return bool
145 */
146 public function containsAll(array $needles)
147 {
148 return Str::containsAll($this->value, $needles);
149 }
150 /**
151 * Get the parent directory's path.
152 *
153 * @param int $levels
154 * @return static
155 */
156 public function dirname($levels = 1)
157 {
158 return new static(\dirname($this->value, $levels));
159 }
160 /**
161 * Determine if a given string ends with a given substring.
162 *
163 * @param string|array $needles
164 * @return bool
165 */
166 public function endsWith($needles)
167 {
168 return Str::endsWith($this->value, $needles);
169 }
170 /**
171 * Determine if the string is an exact match with the given value.
172 *
173 * @param string $value
174 * @return bool
175 */
176 public function exactly($value)
177 {
178 return $this->value === $value;
179 }
180 /**
181 * Explode the string into an array.
182 *
183 * @param string $delimiter
184 * @param int $limit
185 * @return \Illuminate\Support\Collection
186 */
187 public function explode($delimiter, $limit = \PHP_INT_MAX)
188 {
189 return \IAWPSCOPED\collect(\explode($delimiter, $this->value, $limit));
190 }
191 /**
192 * Split a string using a regular expression or by length.
193 *
194 * @param string|int $pattern
195 * @param int $limit
196 * @param int $flags
197 * @return \Illuminate\Support\Collection
198 */
199 public function split($pattern, $limit = -1, $flags = 0)
200 {
201 if (\filter_var($pattern, \FILTER_VALIDATE_INT) !== \false) {
202 return \IAWPSCOPED\collect(\mb_str_split($this->value, $pattern));
203 }
204 $segments = \preg_split($pattern, $this->value, $limit, $flags);
205 return !empty($segments) ? \IAWPSCOPED\collect($segments) : \IAWPSCOPED\collect();
206 }
207 /**
208 * Cap a string with a single instance of a given value.
209 *
210 * @param string $cap
211 * @return static
212 */
213 public function finish($cap)
214 {
215 return new static(Str::finish($this->value, $cap));
216 }
217 /**
218 * Determine if a given string matches a given pattern.
219 *
220 * @param string|array $pattern
221 * @return bool
222 */
223 public function is($pattern)
224 {
225 return Str::is($pattern, $this->value);
226 }
227 /**
228 * Determine if a given string is 7 bit ASCII.
229 *
230 * @return bool
231 */
232 public function isAscii()
233 {
234 return Str::isAscii($this->value);
235 }
236 /**
237 * Determine if a given string is a valid UUID.
238 *
239 * @return bool
240 */
241 public function isUuid()
242 {
243 return Str::isUuid($this->value);
244 }
245 /**
246 * Determine if the given string is empty.
247 *
248 * @return bool
249 */
250 public function isEmpty()
251 {
252 return $this->value === '';
253 }
254 /**
255 * Determine if the given string is not empty.
256 *
257 * @return bool
258 */
259 public function isNotEmpty()
260 {
261 return !$this->isEmpty();
262 }
263 /**
264 * Convert a string to kebab case.
265 *
266 * @return static
267 */
268 public function kebab()
269 {
270 return new static(Str::kebab($this->value));
271 }
272 /**
273 * Return the length of the given string.
274 *
275 * @param string $encoding
276 * @return int
277 */
278 public function length($encoding = null)
279 {
280 return Str::length($this->value, $encoding);
281 }
282 /**
283 * Limit the number of characters in a string.
284 *
285 * @param int $limit
286 * @param string $end
287 * @return static
288 */
289 public function limit($limit = 100, $end = '...')
290 {
291 return new static(Str::limit($this->value, $limit, $end));
292 }
293 /**
294 * Convert the given string to lower-case.
295 *
296 * @return static
297 */
298 public function lower()
299 {
300 return new static(Str::lower($this->value));
301 }
302 /**
303 * Convert GitHub flavored Markdown into HTML.
304 *
305 * @param array $options
306 * @return static
307 */
308 public function markdown(array $options = [])
309 {
310 return new static(Str::markdown($this->value, $options));
311 }
312 /**
313 * Masks a portion of a string with a repeated character.
314 *
315 * @param string $character
316 * @param int $index
317 * @param int|null $length
318 * @param string $encoding
319 * @return static
320 */
321 public function mask($character, $index, $length = null, $encoding = 'UTF-8')
322 {
323 return new static(Str::mask($this->value, $character, $index, $length, $encoding));
324 }
325 /**
326 * Get the string matching the given pattern.
327 *
328 * @param string $pattern
329 * @return static
330 */
331 public function match($pattern)
332 {
333 return new static(Str::match($pattern, $this->value));
334 }
335 /**
336 * Get the string matching the given pattern.
337 *
338 * @param string $pattern
339 * @return \Illuminate\Support\Collection
340 */
341 public function matchAll($pattern)
342 {
343 return Str::matchAll($pattern, $this->value);
344 }
345 /**
346 * Determine if the string matches the given pattern.
347 *
348 * @param string $pattern
349 * @return bool
350 */
351 public function test($pattern)
352 {
353 return $this->match($pattern)->isNotEmpty();
354 }
355 /**
356 * Pad both sides of the string with another.
357 *
358 * @param int $length
359 * @param string $pad
360 * @return static
361 */
362 public function padBoth($length, $pad = ' ')
363 {
364 return new static(Str::padBoth($this->value, $length, $pad));
365 }
366 /**
367 * Pad the left side of the string with another.
368 *
369 * @param int $length
370 * @param string $pad
371 * @return static
372 */
373 public function padLeft($length, $pad = ' ')
374 {
375 return new static(Str::padLeft($this->value, $length, $pad));
376 }
377 /**
378 * Pad the right side of the string with another.
379 *
380 * @param int $length
381 * @param string $pad
382 * @return static
383 */
384 public function padRight($length, $pad = ' ')
385 {
386 return new static(Str::padRight($this->value, $length, $pad));
387 }
388 /**
389 * Parse a Class@method style callback into class and method.
390 *
391 * @param string|null $default
392 * @return array
393 */
394 public function parseCallback($default = null)
395 {
396 return Str::parseCallback($this->value, $default);
397 }
398 /**
399 * Call the given callback and return a new string.
400 *
401 * @param callable $callback
402 * @return static
403 */
404 public function pipe(callable $callback)
405 {
406 return new static(\call_user_func($callback, $this));
407 }
408 /**
409 * Get the plural form of an English word.
410 *
411 * @param int $count
412 * @return static
413 */
414 public function plural($count = 2)
415 {
416 return new static(Str::plural($this->value, $count));
417 }
418 /**
419 * Pluralize the last word of an English, studly caps case string.
420 *
421 * @param int $count
422 * @return static
423 */
424 public function pluralStudly($count = 2)
425 {
426 return new static(Str::pluralStudly($this->value, $count));
427 }
428 /**
429 * Prepend the given values to the string.
430 *
431 * @param array $values
432 * @return static
433 */
434 public function prepend(...$values)
435 {
436 return new static(\implode('', $values) . $this->value);
437 }
438 /**
439 * Remove any occurrence of the given string in the subject.
440 *
441 * @param string|array<string> $search
442 * @param bool $caseSensitive
443 * @return static
444 */
445 public function remove($search, $caseSensitive = \true)
446 {
447 return new static(Str::remove($search, $this->value, $caseSensitive));
448 }
449 /**
450 * Reverse the string.
451 *
452 * @return static
453 */
454 public function reverse()
455 {
456 return new static(Str::reverse($this->value));
457 }
458 /**
459 * Repeat the string.
460 *
461 * @param int $times
462 * @return static
463 */
464 public function repeat(int $times)
465 {
466 return new static(Str::repeat($this->value, $times));
467 }
468 /**
469 * Replace the given value in the given string.
470 *
471 * @param string|string[] $search
472 * @param string|string[] $replace
473 * @return static
474 */
475 public function replace($search, $replace)
476 {
477 return new static(Str::replace($search, $replace, $this->value));
478 }
479 /**
480 * Replace a given value in the string sequentially with an array.
481 *
482 * @param string $search
483 * @param array $replace
484 * @return static
485 */
486 public function replaceArray($search, array $replace)
487 {
488 return new static(Str::replaceArray($search, $replace, $this->value));
489 }
490 /**
491 * Replace the first occurrence of a given value in the string.
492 *
493 * @param string $search
494 * @param string $replace
495 * @return static
496 */
497 public function replaceFirst($search, $replace)
498 {
499 return new static(Str::replaceFirst($search, $replace, $this->value));
500 }
501 /**
502 * Replace the last occurrence of a given value in the string.
503 *
504 * @param string $search
505 * @param string $replace
506 * @return static
507 */
508 public function replaceLast($search, $replace)
509 {
510 return new static(Str::replaceLast($search, $replace, $this->value));
511 }
512 /**
513 * Replace the patterns matching the given regular expression.
514 *
515 * @param string $pattern
516 * @param \Closure|string $replace
517 * @param int $limit
518 * @return static
519 */
520 public function replaceMatches($pattern, $replace, $limit = -1)
521 {
522 if ($replace instanceof Closure) {
523 return new static(\preg_replace_callback($pattern, $replace, $this->value, $limit));
524 }
525 return new static(\preg_replace($pattern, $replace, $this->value, $limit));
526 }
527 /**
528 * Parse input from a string to a collection, according to a format.
529 *
530 * @param string $format
531 * @return \Illuminate\Support\Collection
532 */
533 public function scan($format)
534 {
535 return \IAWPSCOPED\collect(\sscanf($this->value, $format));
536 }
537 /**
538 * Begin a string with a single instance of a given value.
539 *
540 * @param string $prefix
541 * @return static
542 */
543 public function start($prefix)
544 {
545 return new static(Str::start($this->value, $prefix));
546 }
547 /**
548 * Strip HTML and PHP tags from the given string.
549 *
550 * @param string $allowedTags
551 * @return static
552 */
553 public function stripTags($allowedTags = null)
554 {
555 return new static(\strip_tags($this->value, $allowedTags));
556 }
557 /**
558 * Convert the given string to upper-case.
559 *
560 * @return static
561 */
562 public function upper()
563 {
564 return new static(Str::upper($this->value));
565 }
566 /**
567 * Convert the given string to title case.
568 *
569 * @return static
570 */
571 public function title()
572 {
573 return new static(Str::title($this->value));
574 }
575 /**
576 * Convert the given string to title case for each word.
577 *
578 * @return static
579 */
580 public function headline()
581 {
582 return new static(Str::headline($this->value));
583 }
584 /**
585 * Get the singular form of an English word.
586 *
587 * @return static
588 */
589 public function singular()
590 {
591 return new static(Str::singular($this->value));
592 }
593 /**
594 * Generate a URL friendly "slug" from a given string.
595 *
596 * @param string $separator
597 * @param string|null $language
598 * @return static
599 */
600 public function slug($separator = '-', $language = 'en')
601 {
602 return new static(Str::slug($this->value, $separator, $language));
603 }
604 /**
605 * Convert a string to snake case.
606 *
607 * @param string $delimiter
608 * @return static
609 */
610 public function snake($delimiter = '_')
611 {
612 return new static(Str::snake($this->value, $delimiter));
613 }
614 /**
615 * Determine if a given string starts with a given substring.
616 *
617 * @param string|array $needles
618 * @return bool
619 */
620 public function startsWith($needles)
621 {
622 return Str::startsWith($this->value, $needles);
623 }
624 /**
625 * Convert a value to studly caps case.
626 *
627 * @return static
628 */
629 public function studly()
630 {
631 return new static(Str::studly($this->value));
632 }
633 /**
634 * Returns the portion of the string specified by the start and length parameters.
635 *
636 * @param int $start
637 * @param int|null $length
638 * @return static
639 */
640 public function substr($start, $length = null)
641 {
642 return new static(Str::substr($this->value, $start, $length));
643 }
644 /**
645 * Returns the number of substring occurrences.
646 *
647 * @param string $needle
648 * @param int|null $offset
649 * @param int|null $length
650 * @return int
651 */
652 public function substrCount($needle, $offset = null, $length = null)
653 {
654 return Str::substrCount($this->value, $needle, $offset ?? 0, $length);
655 }
656 /**
657 * Replace text within a portion of a string.
658 *
659 * @param string|array $replace
660 * @param array|int $offset
661 * @param array|int|null $length
662 * @return static
663 */
664 public function substrReplace($replace, $offset = 0, $length = null)
665 {
666 return new static(Str::substrReplace($this->value, $replace, $offset, $length));
667 }
668 /**
669 * Swap multiple keywords in a string with other keywords.
670 *
671 * @param array $map
672 * @return static
673 */
674 public function swap(array $map)
675 {
676 return new static(\strtr($this->value, $map));
677 }
678 /**
679 * Trim the string of the given characters.
680 *
681 * @param string $characters
682 * @return static
683 */
684 public function trim($characters = null)
685 {
686 return new static(\trim(...\array_merge([$this->value], \func_get_args())));
687 }
688 /**
689 * Left trim the string of the given characters.
690 *
691 * @param string $characters
692 * @return static
693 */
694 public function ltrim($characters = null)
695 {
696 return new static(\ltrim(...\array_merge([$this->value], \func_get_args())));
697 }
698 /**
699 * Right trim the string of the given characters.
700 *
701 * @param string $characters
702 * @return static
703 */
704 public function rtrim($characters = null)
705 {
706 return new static(\rtrim(...\array_merge([$this->value], \func_get_args())));
707 }
708 /**
709 * Make a string's first character uppercase.
710 *
711 * @return static
712 */
713 public function ucfirst()
714 {
715 return new static(Str::ucfirst($this->value));
716 }
717 /**
718 * Split a string by uppercase characters.
719 *
720 * @return \Illuminate\Support\Collection
721 */
722 public function ucsplit()
723 {
724 return \IAWPSCOPED\collect(Str::ucsplit($this->value));
725 }
726 /**
727 * Execute the given callback if the string contains a given substring.
728 *
729 * @param string|array $needles
730 * @param callable $callback
731 * @param callable|null $default
732 * @return static
733 */
734 public function whenContains($needles, $callback, $default = null)
735 {
736 return $this->when($this->contains($needles), $callback, $default);
737 }
738 /**
739 * Execute the given callback if the string contains all array values.
740 *
741 * @param array $needles
742 * @param callable $callback
743 * @param callable|null $default
744 * @return static
745 */
746 public function whenContainsAll(array $needles, $callback, $default = null)
747 {
748 return $this->when($this->containsAll($needles), $callback, $default);
749 }
750 /**
751 * Execute the given callback if the string is empty.
752 *
753 * @param callable $callback
754 * @param callable|null $default
755 * @return static
756 */
757 public function whenEmpty($callback, $default = null)
758 {
759 return $this->when($this->isEmpty(), $callback, $default);
760 }
761 /**
762 * Execute the given callback if the string is not empty.
763 *
764 * @param callable $callback
765 * @param callable|null $default
766 * @return static
767 */
768 public function whenNotEmpty($callback, $default = null)
769 {
770 return $this->when($this->isNotEmpty(), $callback, $default);
771 }
772 /**
773 * Execute the given callback if the string ends with a given substring.
774 *
775 * @param string|array $needles
776 * @param callable $callback
777 * @param callable|null $default
778 * @return static
779 */
780 public function whenEndsWith($needles, $callback, $default = null)
781 {
782 return $this->when($this->endsWith($needles), $callback, $default);
783 }
784 /**
785 * Execute the given callback if the string is an exact match with the given value.
786 *
787 * @param string $value
788 * @param callable $callback
789 * @param callable|null $default
790 * @return static
791 */
792 public function whenExactly($value, $callback, $default = null)
793 {
794 return $this->when($this->exactly($value), $callback, $default);
795 }
796 /**
797 * Execute the given callback if the string matches a given pattern.
798 *
799 * @param string|array $pattern
800 * @param callable $callback
801 * @param callable|null $default
802 * @return static
803 */
804 public function whenIs($pattern, $callback, $default = null)
805 {
806 return $this->when($this->is($pattern), $callback, $default);
807 }
808 /**
809 * Execute the given callback if the string is 7 bit ASCII.
810 *
811 * @param callable $callback
812 * @param callable|null $default
813 * @return static
814 */
815 public function whenIsAscii($callback, $default = null)
816 {
817 return $this->when($this->isAscii(), $callback, $default);
818 }
819 /**
820 * Execute the given callback if the string is a valid UUID.
821 *
822 * @param callable $callback
823 * @param callable|null $default
824 * @return static
825 */
826 public function whenIsUuid($callback, $default = null)
827 {
828 return $this->when($this->isUuid(), $callback, $default);
829 }
830 /**
831 * Execute the given callback if the string starts with a given substring.
832 *
833 * @param string|array $needles
834 * @param callable $callback
835 * @param callable|null $default
836 * @return static
837 */
838 public function whenStartsWith($needles, $callback, $default = null)
839 {
840 return $this->when($this->startsWith($needles), $callback, $default);
841 }
842 /**
843 * Execute the given callback if the string matches the given pattern.
844 *
845 * @param string $pattern
846 * @param callable $callback
847 * @param callable|null $default
848 * @return static
849 */
850 public function whenTest($pattern, $callback, $default = null)
851 {
852 return $this->when($this->test($pattern), $callback, $default);
853 }
854 /**
855 * Limit the number of words in a string.
856 *
857 * @param int $words
858 * @param string $end
859 * @return static
860 */
861 public function words($words = 100, $end = '...')
862 {
863 return new static(Str::words($this->value, $words, $end));
864 }
865 /**
866 * Get the number of words a string contains.
867 *
868 * @return int
869 */
870 public function wordCount()
871 {
872 return \str_word_count($this->value);
873 }
874 /**
875 * Convert the string into a `HtmlString` instance.
876 *
877 * @return \Illuminate\Support\HtmlString
878 */
879 public function toHtmlString()
880 {
881 return new HtmlString($this->value);
882 }
883 /**
884 * Dump the string.
885 *
886 * @return $this
887 */
888 public function dump()
889 {
890 VarDumper::dump($this->value);
891 return $this;
892 }
893 /**
894 * Dump the string and end the script.
895 *
896 * @return never
897 */
898 public function dd()
899 {
900 $this->dump();
901 exit(1);
902 }
903 /**
904 * Convert the object to a string when JSON encoded.
905 *
906 * @return string
907 */
908 #[\ReturnTypeWillChange]
909 public function jsonSerialize()
910 {
911 return $this->__toString();
912 }
913 /**
914 * Proxy dynamic properties onto methods.
915 *
916 * @param string $key
917 * @return mixed
918 */
919 public function __get($key)
920 {
921 return $this->{$key}();
922 }
923 /**
924 * Get the raw string value.
925 *
926 * @return string
927 */
928 public function __toString()
929 {
930 return (string) $this->value;
931 }
932 }
933