Alexander Makarov
11 years ago
26 changed files with 411 additions and 223 deletions
@ -0,0 +1,40 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matchers; |
||||
|
||||
use yii\base\Component; |
||||
|
||||
/** |
||||
* Base class for matchers that are used in a filter. |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
abstract class Base extends Component implements MatcherInterface |
||||
{ |
||||
/** |
||||
* @var mixed base value to check |
||||
*/ |
||||
protected $baseValue; |
||||
|
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function setValue($value) |
||||
{ |
||||
$this->baseValue = $value; |
||||
} |
||||
|
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function hasValue() |
||||
{ |
||||
return !empty($this->baseValue) || $this->baseValue === 0; |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matchers; |
||||
|
||||
/** |
||||
* Checks if the given value is greater than the base one. |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
class GreaterThan extends Base |
||||
{ |
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function match($value) |
||||
{ |
||||
return ($value > $this->baseValue); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matchers; |
||||
|
||||
/** |
||||
* Checks if the given value is lower than the base one. |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
class LowerThan extends Base |
||||
{ |
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function match($value) |
||||
{ |
||||
return ($value < $this->baseValue); |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matchers; |
||||
|
||||
/** |
||||
* MatcherInterface should be implemented by all matchers that are used in a filter. |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
interface MatcherInterface |
||||
{ |
||||
/** |
||||
* Checks if the value passed matches base value. |
||||
* |
||||
* @param mixed $value value to be matched |
||||
* @return boolean if there is a match |
||||
*/ |
||||
public function match($value); |
||||
|
||||
/** |
||||
* Sets base value to match against |
||||
* |
||||
* @param mixed $value |
||||
*/ |
||||
public function setValue($value); |
||||
|
||||
/** |
||||
* Checks if base value is set |
||||
* |
||||
* @return boolean if base value is set |
||||
*/ |
||||
public function hasValue(); |
||||
} |
@ -0,0 +1,34 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matchers; |
||||
|
||||
/** |
||||
* Checks if the given value is exactly or partially same as the base one. |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
class SameAs extends Base |
||||
{ |
||||
/** |
||||
* @var boolean if partial match should be used. |
||||
*/ |
||||
public $partial = false; |
||||
|
||||
/** |
||||
* @inheritdoc |
||||
*/ |
||||
public function match($value) |
||||
{ |
||||
if (!$this->partial) { |
||||
return (mb_strtolower($this->baseValue, 'utf8') == mb_strtolower($value, 'utf8')); |
||||
} else { |
||||
return (mb_strpos(mb_strtolower($value, 'utf8'), mb_strtolower($this->baseValue, 'utf8')) !== false); |
||||
} |
||||
} |
||||
} |
@ -1,26 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matches; |
||||
|
||||
use yii\base\Component; |
||||
|
||||
/** |
||||
* Base mathcer class for all matchers that will be used with filter. |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
abstract class Base extends Component implements MatcherInterface |
||||
{ |
||||
|
||||
/** |
||||
* @var mixed current value to check for the matcher |
||||
*/ |
||||
public $value; |
||||
|
||||
} |
@ -1,36 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matches; |
||||
|
||||
/** |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
class Exact extends Base |
||||
{ |
||||
|
||||
/** |
||||
* @var boolean if current matcher should consider partial match of given value. |
||||
*/ |
||||
public $partial = false; |
||||
|
||||
/** |
||||
* Checks if the given value is the same as base one or has partial match with base one. |
||||
* @param mixed $value |
||||
*/ |
||||
public function check($value) |
||||
{ |
||||
if (!$this->partial) { |
||||
return (mb_strtolower($this->value, 'utf8') == mb_strtolower($value, 'utf8')); |
||||
} else { |
||||
return (mb_strpos(mb_strtolower($value, 'utf8'), mb_strtolower($this->value,'utf8')) !== false); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,27 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matches; |
||||
|
||||
/** |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
class Greater extends Base |
||||
{ |
||||
|
||||
/** |
||||
* Checks if the given value is the same as base one or has partial match with base one. |
||||
* @param mixed $value |
||||
*/ |
||||
public function check($value) |
||||
{ |
||||
return ($value > $this->value); |
||||
} |
||||
|
||||
} |
@ -1,27 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matches; |
||||
|
||||
/** |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
class Lower extends Base |
||||
{ |
||||
|
||||
/** |
||||
* Checks if the given value is the same as base one or has partial match with base one. |
||||
* @param mixed $value |
||||
*/ |
||||
public function check($value) |
||||
{ |
||||
return ($value < $this->value); |
||||
} |
||||
|
||||
} |
@ -1,25 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\components\search\matches; |
||||
|
||||
/** |
||||
* MatcherInterface is the interface that should be implemented by all matchers that will be used in filter. |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
interface MatcherInterface |
||||
{ |
||||
|
||||
/** |
||||
* Check if the value is correct according current matcher. |
||||
* @param mixed $value |
||||
*/ |
||||
public function check($value); |
||||
|
||||
} |
@ -1,37 +1,44 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\debug\models\search; |
||||
|
||||
use yii\base\Model; |
||||
use yii\debug\components\search\Filter; |
||||
use yii\debug\components\search\matches; |
||||
|
||||
use yii\debug\components\search\matchers; |
||||
|
||||
/** |
||||
* Base search model |
||||
* |
||||
* @author Mark Jebri <mark.github@yandex.ru> |
||||
* @since 2.0 |
||||
*/ |
||||
class Base extends Model |
||||
{ |
||||
|
||||
/** |
||||
* @param Filter $filter |
||||
* @param string $attribute |
||||
* @param boolean $partial |
||||
* Adds filtering condition for a given attribute |
||||
* |
||||
* @param Filter $filter filter instance |
||||
* @param string $attribute attribute to filter |
||||
* @param boolean $partial if partial match should be used |
||||
*/ |
||||
public function addCondition($filter, $attribute, $partial = false) |
||||
public function addCondition(Filter $filter, $attribute, $partial = false) |
||||
{ |
||||
$value = $this->$attribute; |
||||
|
||||
if (mb_strpos($value, '>') !== false) { |
||||
|
||||
$value = intval(str_replace('>', '', $value)); |
||||
$filter->addMatch($attribute, new matches\Greater(['value' => $value])); |
||||
$filter->addMatcher($attribute, new matchers\GreaterThan(['value' => $value])); |
||||
|
||||
} elseif (mb_strpos($value, '<') !== false) { |
||||
|
||||
$value = intval(str_replace('<', '', $value)); |
||||
$filter->addMatch($attribute, new matches\Lower(['value' => $value])); |
||||
|
||||
$filter->addMatcher($attribute, new matchers\LowerThan(['value' => $value])); |
||||
} else { |
||||
$filter->addMatch($attribute, new matches\Exact(['value' => $value, 'partial' => $partial])); |
||||
$filter->addMatcher($attribute, new matchers\SameAs(['value' => $value, 'partial' => $partial])); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue