Source of file LikeMatcher.php
Size: 1,300 Bytes - Last Modified: 2021-12-23T10:02:17+00:00
/var/www/docs.ssmods.com/process/src/code/Heuristics/LikeMatcher.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 | <?php namespace Seeder\Heuristics; /** * Class LikeMatcher * @package Seeder\Heuristics */ class LikeMatcher implements Matcher { /** * @var string */ private $like; /** * @var bool */ private $matchStart = true; /** * @var bool */ private $matchEnd = true; /** * @param $like */ public function __construct($like) { if (strpos($like, '%') === 0) { $this->matchStart = false; $like = substr($like, 1); } if (strpos(strrev($like), '%') === 0) { $this->matchEnd = false; $like = substr($like, 0, strlen($like) - 1); } $this->like = strtolower($like); } /** * @param $value * @return bool */ public function match($value) { if (!is_string($value)) { return false; } $value = strtolower($value); if ($this->matchStart && $this->matchEnd) { return $this->like == $value; } elseif ($this->matchStart) { return strpos($value, $this->like) === 0; } elseif ($this->matchEnd) { return strpos(strrev($value), strrev($this->like)) === 0; } return strpos($value, $this->like) !== false; } } |