for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Yii2 AR Tag Cache.
*
* This file contains behavior class.
* @author Aleksei Korotin <[email protected]>
*/
namespace herroffizier\yii2artc;
use Yii;
use yii\db\ActiveRecord;
use yii\caching\TagDependency;
class Behavior extends \yii\base\Behavior
{
* Cache component.
* @var string
public $cache = 'cache';
public function events()
return [
ActiveRecord::EVENT_AFTER_INSERT => 'invalidateCache',
ActiveRecord::EVENT_AFTER_UPDATE => 'invalidateCache',
ActiveRecord::EVENT_AFTER_DELETE => 'invalidateCache',
];
}
* Get array of tags for dependency.
* @return string[]
protected function getCacheTags()
$classes = [$this->owner];
$tags = TagBuilder::buildTags($classes);
return $tags;
* Invalidate cache for current model.
public function invalidateCache()
$tags = $this->getCacheTags();
TagDependency::invalidate(Yii::$app->get($this->cache), $tags);
* Get tag dependency for current ActiveRecord class.
* @return Dependency
TagDependency
This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.
@return
public function getTagDependency()
return new TagDependency(['tags' => $tags]);
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.