Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 7... Zeile 7...
7
 
7
 
Zeile 8... Zeile 8...
8
declare(strict_types=1);
8
declare(strict_types=1);
Zeile -... Zeile 9...
-
 
9
 
9
 
10
namespace Nette\Utils;
10
namespace Nette\Utils;
11
 
Zeile 11... Zeile 12...
11
 
12
use JetBrains\PhpStorm\Language;
Zeile 483... Zeile 484...
483
 
484
 
484
	/**
485
	/**
485
	 * Splits a string into array by the regular expression. Parenthesized expression in the delimiter are captured.
486
	 * Splits a string into array by the regular expression. Parenthesized expression in the delimiter are captured.
486
	 * Parameter $flags can be any combination of PREG_SPLIT_NO_EMPTY and PREG_OFFSET_CAPTURE flags.
487
	 * Parameter $flags can be any combination of PREG_SPLIT_NO_EMPTY and PREG_OFFSET_CAPTURE flags.
487
	 */
488
	 */
-
 
489
	public static function split(
-
 
490
		string $subject,
-
 
491
		#[Language('RegExp')]
-
 
492
		string $pattern,
-
 
493
		int $flags = 0
488
	public static function split(string $subject, string $pattern, int $flags = 0): array
494
	): array
489
	{
495
	{
490
		return self::pcre('preg_split', [$pattern, $subject, -1, $flags | PREG_SPLIT_DELIM_CAPTURE]);
496
		return self::pcre('preg_split', [$pattern, $subject, -1, $flags | PREG_SPLIT_DELIM_CAPTURE]);
Zeile 491... Zeile 497...
491
	}
497
	}
492
 
498
 
493
 
499
 
494
	/**
500
	/**
495
	 * Checks if given string matches a regular expression pattern and returns an array with first found match and each subpattern.
501
	 * Checks if given string matches a regular expression pattern and returns an array with first found match and each subpattern.
-
 
502
	 * Parameter $flags can be any combination of PREG_OFFSET_CAPTURE and PREG_UNMATCHED_AS_NULL flags.
-
 
503
	 */
-
 
504
	public static function match(
-
 
505
		string $subject,
-
 
506
		#[Language('RegExp')]
-
 
507
		string $pattern,
496
	 * Parameter $flags can be any combination of PREG_OFFSET_CAPTURE and PREG_UNMATCHED_AS_NULL flags.
508
		int $flags = 0,
497
	 */
509
		int $offset = 0
498
	public static function match(string $subject, string $pattern, int $flags = 0, int $offset = 0): ?array
510
	): ?array
499
	{
511
	{
Zeile 509... Zeile 521...
509
 
521
 
510
	/**
522
	/**
511
	 * Finds all occurrences matching regular expression pattern and returns a two-dimensional array. Result is array of matches (ie uses by default PREG_SET_ORDER).
523
	 * Finds all occurrences matching regular expression pattern and returns a two-dimensional array. Result is array of matches (ie uses by default PREG_SET_ORDER).
512
	 * Parameter $flags can be any combination of PREG_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL and PREG_PATTERN_ORDER flags.
524
	 * Parameter $flags can be any combination of PREG_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL and PREG_PATTERN_ORDER flags.
513
	 */
525
	 */
-
 
526
	public static function matchAll(
-
 
527
		string $subject,
-
 
528
		#[Language('RegExp')]
-
 
529
		string $pattern,
-
 
530
		int $flags = 0,
-
 
531
		int $offset = 0
514
	public static function matchAll(string $subject, string $pattern, int $flags = 0, int $offset = 0): array
532
	): array
515
	{
533
	{
516
		if ($offset > strlen($subject)) {
534
		if ($offset > strlen($subject)) {
517
			return [];
535
			return [];
Zeile 529... Zeile 547...
529
	/**
547
	/**
530
	 * Replaces all occurrences matching regular expression $pattern which can be string or array in the form `pattern => replacement`.
548
	 * Replaces all occurrences matching regular expression $pattern which can be string or array in the form `pattern => replacement`.
531
	 * @param  string|array  $pattern
549
	 * @param  string|array  $pattern
532
	 * @param  string|callable  $replacement
550
	 * @param  string|callable  $replacement
533
	 */
551
	 */
534
	public static function replace(string $subject, $pattern, $replacement = '', int $limit = -1): string
552
	public static function replace(
-
 
553
		string $subject,
-
 
554
		#[Language('RegExp')]
-
 
555
		$pattern,
-
 
556
		$replacement = '',
-
 
557
		int $limit = -1
-
 
558
	): string
535
	{
559
	{
536
		if (is_object($replacement) || is_array($replacement)) {
560
		if (is_object($replacement) || is_array($replacement)) {
537
			if (!is_callable($replacement, false, $textual)) {
561
			if (!is_callable($replacement, false, $textual)) {
538
				throw new Nette\InvalidStateException("Callback '$textual' is not callable.");
562
				throw new Nette\InvalidStateException("Callback '$textual' is not callable.");
539
			}
563
			}