PageRenderTime 160ms CodeModel.GetById 62ms app.highlight 3ms RepoModel.GetById 94ms app.codeStats 0ms

/framework/caching/dependencies/CExpressionDependency.php

http://github.com/yiisoft/yii
PHP | 55 lines | 13 code | 3 blank | 39 comment | 0 complexity | 17543157380aa8ed401836ee7908b890 MD5 | raw file
 1<?php
 2/**
 3 * CExpressionDependency class file.
 4 *
 5 * @author Qiang Xue <qiang.xue@gmail.com>
 6 * @link http://www.yiiframework.com/
 7 * @copyright 2008-2013 Yii Software LLC
 8 * @license http://www.yiiframework.com/license/
 9 */
10
11/**
12 * CExpressionDependency represents a dependency based on the result of a PHP expression.
13 *
14 * CExpressionDependency performs dependency checking based on the
15 * result of a PHP {@link expression}.
16 * The dependency is reported as unchanged if and only if the result is
17 * the same as the one evaluated when storing the data to cache.
18 *
19 * @author Qiang Xue <qiang.xue@gmail.com>
20 * @package system.caching.dependencies
21 * @since 1.0
22 */
23class CExpressionDependency extends CCacheDependency
24{
25	/**
26	 * @var string the PHP expression whose result is used to determine the dependency.
27	 * The expression can also be a valid serializable PHP callback.
28	 * It will be passed with a parameter which is the dependency object itself.
29	 *
30	 * The PHP expression will be evaluated using {@link evaluateExpression}.
31	 *
32	 * A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
33	 * please refer to the {@link http://www.php.net/manual/en/language.expressions.php php manual}.
34	 */
35	public $expression;
36
37	/**
38	 * Constructor.
39	 * @param string $expression the PHP expression whose result is used to determine the dependency.
40	 */
41	public function __construct($expression='true')
42	{
43		$this->expression=$expression;
44	}
45
46	/**
47	 * Generates the data needed to determine if dependency has been changed.
48	 * This method returns the result of the PHP expression.
49	 * @return mixed the data needed to determine if dependency has been changed.
50	 */
51	protected function generateDependentData()
52	{
53		return $this->evaluateExpression($this->expression);
54	}
55}