Browse Source
			
			
			
			
				
		* upstream: (35 commits) Fixes #1691: added “viewport” meta tag to layout views. Fixed the issue that query cache returns the same data for the same SQL but different query methods moved section subsection added typo [skip ci] docs about response Fixes #1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default docs improved csrf docs added Fixes #1685: UrlManager::showScriptName should be set true for tests. Fixes #1688: ActiveForm is creating duplicated messages in error summary change back the visibility of findTableNames to protected. Typo fix. Fixes #1681: Added support for automatically adjusting the "for" attribute of label generated by `ActiveField::label()` Simplified tests. Fixes #1631: Charset is now explicitly set to UTF-8 when serving JSON Fixed typo added html layout for mail component in basic app CS fixes. Merge branch 'debug_module_improvements' of github.com:Ragazzo/yii2 into Ragazzo-debug_module_improvements ...tags/2.0.0-beta
				 66 changed files with 847 additions and 381 deletions
			
			
		| @ -1,11 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| // configuration adjustments for codeception acceptance tests. Will be merged with web.php config. | ||||
| 
 | ||||
| return [ | ||||
| 	'components' => [ | ||||
| 		'db' => [ | ||||
| 			'dsn' => 'mysql:host=localhost;dbname=yii2basic_acceptance', | ||||
| 		], | ||||
| 	], | ||||
| ]; | ||||
| @ -1,17 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| // configuration adjustments for codeception functional tests. Will be merged with web.php config. | ||||
| 
 | ||||
| return [ | ||||
| 	'components' => [ | ||||
| 		'db' => [ | ||||
| 			'dsn' => 'mysql:host=localhost;dbname=yii2basic_functional', | ||||
| 		], | ||||
| 		'request' => [ | ||||
| 			'enableCsrfValidation' => false, | ||||
| 		], | ||||
| 		'urlManager' => [ | ||||
| 			'baseUrl' => '/web/index.php', | ||||
| 		], | ||||
| 	], | ||||
| ]; | ||||
| @ -1,15 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| // configuration adjustments for codeception unit tests. Will be merged with web.php config. | ||||
| 
 | ||||
| return [ | ||||
| 	'components' => [ | ||||
| 		'fixture'	=>	[ | ||||
| 			'class'		=>	'yii\test\DbFixtureManager', | ||||
| 			'basePath'	=>	'@tests/unit/fixtures', | ||||
| 		], | ||||
| 		'db' => [ | ||||
| 			'dsn' => 'mysql:host=localhost;dbname=yii2basic_unit', | ||||
| 		], | ||||
| 	], | ||||
| ]; | ||||
| @ -0,0 +1,24 @@ | ||||
| <?php | ||||
| use yii\helpers\Html; | ||||
| use yii\mail\BaseMessage; | ||||
| 
 | ||||
| /** | ||||
|  * @var \yii\web\View $this | ||||
|  * @var BaseMessage $content | ||||
|  */ | ||||
| ?> | ||||
| <?php $this->beginPage() ?> | ||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||||
| <html xmlns="http://www.w3.org/1999/xhtml"> | ||||
| <head> | ||||
| 	<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
 | ||||
| 	<title><?= Html::encode($this->title) ?></title>
 | ||||
| 	<?php $this->head() ?> | ||||
| </head> | ||||
| <body> | ||||
| 	<?php $this->beginBody() ?> | ||||
| 	<?= $content ?> | ||||
| 	<?php $this->endBody() ?> | ||||
| </body> | ||||
| </html> | ||||
| <?php $this->endPage() ?> | ||||
| @ -1,35 +1,28 @@ | ||||
| This folder contains various tests for the basic application. | ||||
| These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/). | ||||
| 
 | ||||
| To run the tests, follow these steps: | ||||
| After creating the basic application, follow these steps to prepare for the tests: | ||||
| 
 | ||||
| 1. Download Codeception([Quickstart step 1](http://codeception.com/quickstart)) and put the codeception.phar in the | ||||
|    application base directory (not in this `tests` directory!). | ||||
| 2. Adjust the test configuration files based on your environment: | ||||
|    - Configure the URL for [acceptance tests](http://codeception.com/docs/04-AcceptanceTests) in `acceptance.suite.yml`. | ||||
|      The URL should point to the `index-test-acceptance.php` file that is located under the `web` directory of the application. | ||||
|    - `functional.suite.yml` for [functional testing](http://codeception.com/docs/05-FunctionalTests) and | ||||
|      `unit.suite.yml` for [unit testing](http://codeception.com/docs/06-UnitTests) should already work out of the box | ||||
|      and should not need to be adjusted. | ||||
|    - If you want to run acceptance tests, you need to download [selenium standalone](http://www.seleniumhq.org/download/) | ||||
|      and start it with command `java -jar {selenium-standalone-name}.jar`. | ||||
|      After that you can use `WebDriver` codeception module that will connect to selenium and launch browser. | ||||
|      This also allows you to use [Xvfb](https://en.wikipedia.org/wiki/Xvfb) in your tests which allows you to run tests | ||||
|      without showing the running browser on the screen. There is codeception [blog post](http://codeception.com/05-24-2013/jenkins-ci-practice.html) | ||||
|      that explains how it works. | ||||
| 1. In the file `_bootstrap.php`, modify the definition of the constant `TEST_ENTRY_URL` so | ||||
|    that it points to the correct entry script URL. | ||||
| 2. Go to the application base directory and build the test suites: | ||||
| 
 | ||||
| 3. Go to the application base directory and build the test suites: | ||||
|    ``` | ||||
|    php codecept.phar build    // rebuild test scripts, only need to be run once | ||||
|    ``` | ||||
| 4. Run the tests: | ||||
|    ``` | ||||
|    php codecept.phar run      // run all available tests | ||||
|    // you can also run a test suite alone: | ||||
|    php codecept.phar run acceptance | ||||
|    php codecept.phar run functional | ||||
|    php codecept.phar run unit | ||||
|    vendor/bin/codecept build | ||||
|    ``` | ||||
| 
 | ||||
| Now you can run the tests with the following commands: | ||||
| 
 | ||||
| ``` | ||||
| # run all available tests | ||||
| vendor/bin/codecept run | ||||
| # run acceptance tests | ||||
| vendor/bin/codecept run acceptance | ||||
| # run functional tests | ||||
| vendor/bin/codecept run functional | ||||
| # run unit tests | ||||
| vendor/bin/codecept run unit | ||||
| ``` | ||||
| 
 | ||||
| Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for | ||||
| more details about writing acceptance, functional and unit tests. | ||||
| more details about writing and running acceptance, functional and unit tests. | ||||
|  | ||||
| @ -1,9 +1,22 @@ | ||||
| <?php | ||||
| 
 | ||||
| // the entry script URL (without host info) for functional and acceptance tests | ||||
| // PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL | ||||
| defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/yii2-basic/web/index-test.php'); | ||||
| 
 | ||||
| // the entry script file path for functional and acceptance tests | ||||
| defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(__DIR__) . '/web/index-test.php'); | ||||
| 
 | ||||
| defined('YII_DEBUG') or define('YII_DEBUG', true); | ||||
| 
 | ||||
| defined('YII_ENV') or define('YII_ENV', 'test'); | ||||
| 
 | ||||
| require_once(__DIR__ . '/../vendor/autoload.php'); | ||||
| 
 | ||||
| require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); | ||||
| 
 | ||||
| // set correct script paths | ||||
| $_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE; | ||||
| $_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL; | ||||
| 
 | ||||
| Yii::setAlias('@tests', __DIR__); | ||||
|  | ||||
| @ -1,8 +1,3 @@ | ||||
| <?php | ||||
| 
 | ||||
| $config = yii\helpers\ArrayHelper::merge( | ||||
| 	require(__DIR__ . '/../../config/web.php'), | ||||
| 	require(__DIR__ . '/../../config/codeception/acceptance.php') | ||||
| ); | ||||
| 
 | ||||
| $application = new yii\web\Application($config); | ||||
| new yii\web\Application(require(__DIR__ . '/_config.php')); | ||||
|  | ||||
| @ -0,0 +1,16 @@ | ||||
| <?php | ||||
| 
 | ||||
| use yii\helpers\ArrayHelper; | ||||
| 
 | ||||
| $config = require(__DIR__ . '/../../config/web.php'); | ||||
| 
 | ||||
| return ArrayHelper::merge($config, [ | ||||
| 	'components' => [ | ||||
| 		'db' => [ | ||||
| 			'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', | ||||
| 		], | ||||
| 		'urlManager' => [ | ||||
| 			'showScriptName' => true, | ||||
| 		], | ||||
| 	], | ||||
| ]); | ||||
| @ -1,4 +1,3 @@ | ||||
| <?php | ||||
| 
 | ||||
| // create an application instance to support URL creation before running any test | ||||
| Yii::createObject(require(__DIR__ . '/../../web/index-test-functional.php')); | ||||
| new yii\web\Application(require(__DIR__ . '/_config.php')); | ||||
|  | ||||
| @ -0,0 +1,20 @@ | ||||
| <?php | ||||
| 
 | ||||
| use yii\helpers\ArrayHelper; | ||||
| 
 | ||||
| // set correct script paths | ||||
| $_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE; | ||||
| $_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL; | ||||
| 
 | ||||
| $config = require(__DIR__ . '/../../config/web.php'); | ||||
| 
 | ||||
| return ArrayHelper::merge($config, [ | ||||
| 	'components' => [ | ||||
| 		'db' => [ | ||||
| 			'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', | ||||
| 		], | ||||
| 		'urlManager' => [ | ||||
| 			'showScriptName' => true, | ||||
| 		], | ||||
| 	], | ||||
| ]); | ||||
| @ -1,51 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace tests\functional\_pages; | ||||
| 
 | ||||
| class ContactPage extends \tests\_pages\ContactPage | ||||
| { | ||||
| 	/** | ||||
| 	 * contact form name text field locator | ||||
| 	 * @var string  | ||||
| 	 */ | ||||
| 	public $name = 'ContactForm[name]'; | ||||
| 	/** | ||||
| 	 * contact form email text field locator | ||||
| 	 * @var string | ||||
| 	 */ | ||||
| 	public $email = 'ContactForm[email]'; | ||||
| 	/** | ||||
| 	 * contact form subject text field locator | ||||
| 	 * @var string | ||||
| 	 */ | ||||
| 	public $subject = 'ContactForm[subject]'; | ||||
| 	/** | ||||
| 	 * contact form body textarea locator | ||||
| 	 * @var string | ||||
| 	 */ | ||||
| 	public $body = 'ContactForm[body]'; | ||||
| 	/** | ||||
| 	 * contact form verification code text field locator | ||||
| 	 * @var string | ||||
| 	 */ | ||||
| 	public $verifyCode = 'ContactForm[verifyCode]'; | ||||
| 
 | ||||
| 	/** | ||||
| 	 *  | ||||
| 	 * @param array $contactData | ||||
| 	 */ | ||||
| 	public function submit(array $contactData) | ||||
| 	{ | ||||
| 		if (empty($contactData)) { | ||||
| 			$this->guy->submitForm('#contact-form', []); | ||||
| 		} else { | ||||
| 			$this->guy->submitForm('#contact-form', [ | ||||
| 				$this->name			=>	$contactData['name'], | ||||
| 				$this->email		=>	$contactData['email'], | ||||
| 				$this->subject		=>	$contactData['subject'], | ||||
| 				$this->body			=>	$contactData['body'], | ||||
| 				$this->verifyCode	=>	$contactData['verifyCode'], | ||||
| 			]); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -1,30 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace tests\functional\_pages; | ||||
| 
 | ||||
| class LoginPage extends \tests\_pages\LoginPage | ||||
| { | ||||
| 	/** | ||||
| 	 * login form username text field locator | ||||
| 	 * @var string | ||||
| 	 */ | ||||
| 	public $username = 'LoginForm[username]'; | ||||
| 	/** | ||||
| 	 * login form password text field locator | ||||
| 	 * @var string | ||||
| 	 */ | ||||
| 	public $password = 'LoginForm[password]'; | ||||
| 
 | ||||
| 	/** | ||||
| 	 *  | ||||
| 	 * @param string $username | ||||
| 	 * @param string $password | ||||
| 	 */ | ||||
| 	public function login($username, $password) | ||||
| 	{ | ||||
| 		$this->guy->submitForm('#login-form', [ | ||||
| 			$this->username	=> $username, | ||||
| 			$this->password	=> $password, | ||||
| 		]); | ||||
| 	} | ||||
| } | ||||
| @ -1,11 +0,0 @@ | ||||
| <?php | ||||
| 
 | ||||
| // this file is used as the entry script for codeception functional testing | ||||
| 
 | ||||
| $config = yii\helpers\ArrayHelper::merge( | ||||
| 	require(__DIR__ . '/../config/web.php'), | ||||
| 	require(__DIR__ . '/../config/codeception/functional.php') | ||||
| ); | ||||
| 
 | ||||
| $config['class'] = 'yii\web\Application'; | ||||
| return $config; | ||||
| @ -0,0 +1,72 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace yii\debug\components\search; | ||||
| 
 | ||||
| use yii\base\Component; | ||||
| 
 | ||||
| class Filter extends Component | ||||
| { | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var array rules for matching filters in the way: [:fieldName => [rule1, rule2,..]] | ||||
| 	 */ | ||||
| 	protected $rules = []; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Adds rules for filtering data. Match can be partial or exactly. | ||||
| 	 * @param string $name attribute name | ||||
| 	 * @param \yii\debug\components\search\matches\Base $rule | ||||
| 	 */ | ||||
| 	public function addMatch($name, $rule) | ||||
| 	{ | ||||
| 		if (empty($rule->value) && $rule->value !== 0) { | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		$this->rules[$name][] = $rule; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Applies filter on given array and returns filtered data. | ||||
| 	 * @param array $data data to filter | ||||
| 	 * @return array filtered data | ||||
| 	 */ | ||||
| 	public function filter(array $data) | ||||
| 	{ | ||||
| 		$filtered = []; | ||||
| 
 | ||||
| 		foreach ($data as $row) { | ||||
| 			if ($this->checkFilter($row)) { | ||||
| 				$filtered[] = $row; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return $filtered; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Check if the given data satisfies filters. | ||||
| 	 * @param array $row | ||||
| 	 */ | ||||
| 	public function checkFilter(array $row) | ||||
| 	{ | ||||
| 		$matched = true; | ||||
| 
 | ||||
| 		foreach ($row as $name => $value) { | ||||
| 			if (isset($this->rules[$name])) { | ||||
| 
 | ||||
| 				#check all rules for given attribute | ||||
| 
 | ||||
| 				foreach ($this->rules[$name] as $rule) { | ||||
| 					if (!$rule->check($value)) { | ||||
| 						$matched = false; | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return $matched; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,26 @@ | ||||
| <?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; | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,36 @@ | ||||
| <?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 mathc 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($value, $this->value) !== false); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| <?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); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| <?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); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @ -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\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); | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,149 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace yii\debug\models\search; | ||||
| 
 | ||||
| use yii\base\Model; | ||||
| use yii\data\ArrayDataProvider; | ||||
| use yii\debug\components\search\Filter; | ||||
| use yii\debug\components\search\matches; | ||||
| 
 | ||||
| /** | ||||
|  * Debug represents the model behind the search form about requests manifest data. | ||||
|  */ | ||||
| class Debug extends Model | ||||
| { | ||||
| 	/** | ||||
| 	 * @var string tag attribute input search value | ||||
| 	 */ | ||||
| 	public $tag; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var string ip attribute input search value | ||||
| 	 */ | ||||
| 	public $ip; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var string method attribute input search value | ||||
| 	 */ | ||||
| 	public $method; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var integer ajax attribute input search value | ||||
| 	 */ | ||||
| 	public $ajax; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var string url attribute input search value | ||||
| 	 */ | ||||
| 	public $url; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var string status code attribute input search value | ||||
| 	 */ | ||||
| 	public $statusCode; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * | ||||
| 	 * @var integer sql count attribute input search value | ||||
| 	 */ | ||||
| 	public $sqlCount; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var array critical codes, used to determine grid row options. | ||||
| 	 */ | ||||
| 	public $criticalCodes = [400, 404, 500]; | ||||
| 
 | ||||
| 	public function rules() | ||||
| 	{ | ||||
| 		return [ | ||||
| 			[['tag', 'ip', 'method', 'ajax', 'url', 'statusCode', 'sqlCount'], 'safe'], | ||||
| 		]; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @inheritdoc | ||||
| 	 */ | ||||
| 	public function attributeLabels() | ||||
| 	{ | ||||
| 		return [ | ||||
| 			'tag' => 'Tag', | ||||
| 			'ip' => 'Ip', | ||||
| 			'method' => 'Method', | ||||
| 			'ajax' => 'Ajax', | ||||
| 			'url' => 'url', | ||||
| 			'statusCode' => 'Status code', | ||||
| 			'sqlCount' => 'Total queries count', | ||||
| 		]; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Returns data provider with filled models. Filter applied if needed. | ||||
| 	 * @param array $params | ||||
| 	 * @param array $models | ||||
| 	 * @return \yii\data\ArrayDataProvider | ||||
| 	 */ | ||||
| 	public function search($params, $models) | ||||
| 	{ | ||||
| 		$dataProvider = new ArrayDataProvider([ | ||||
| 			'allModels' => $models, | ||||
| 			'sort' => [ | ||||
| 				'attributes' => ['method', 'ip', 'tag', 'time', 'statusCode', 'sqlCount'], | ||||
| 			], | ||||
| 			'pagination' => [ | ||||
| 				'pageSize' => 10, | ||||
| 			], | ||||
| 		]); | ||||
| 
 | ||||
| 		if (!($this->load($params) && $this->validate())) { | ||||
| 			return $dataProvider; | ||||
| 		} | ||||
| 
 | ||||
| 		$filter = new Filter(); | ||||
| 		$this->addCondition($filter, 'tag', true); | ||||
| 		$this->addCondition($filter, 'ip', true); | ||||
| 		$this->addCondition($filter, 'method'); | ||||
| 		$this->addCondition($filter, 'ajax'); | ||||
| 		$this->addCondition($filter, 'url', true); | ||||
| 		$this->addCondition($filter, 'statusCode'); | ||||
| 		$this->addCondition($filter, 'sqlCount'); | ||||
| 		$dataProvider->allModels = $filter->filter($models); | ||||
| 
 | ||||
| 		return $dataProvider; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Checks if the code is critical: 400 or greater, 500 or greater. | ||||
| 	 * @param integer $code | ||||
| 	 * @return bool | ||||
| 	 */ | ||||
| 	public function isCodeCritical($code) | ||||
| 	{ | ||||
| 		return in_array($code, $this->criticalCodes); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param Filter $filter | ||||
| 	 * @param string $attribute | ||||
| 	 * @param boolean $partial | ||||
| 	 */ | ||||
| 	public function addCondition($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])); | ||||
| 
 | ||||
| 		} elseif (mb_strpos($value, '<') !== false) { | ||||
| 
 | ||||
| 			$value = intval(str_replace('<', '', $value)); | ||||
| 			$filter->addMatch($attribute, new matches\Lower(['value' => $value])); | ||||
| 
 | ||||
| 		} else { | ||||
| 			$filter->addMatch($attribute, new matches\Exact(['value' => $value, 'partial' => $partial])); | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue