commit 3a439538ca6a431a16d8fe21504bd92591126d04 Author: dimti Date: Thu Nov 10 10:49:09 2022 +0300 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a09c56d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea diff --git a/Plugin.php b/Plugin.php new file mode 100644 index 0000000..9bdc8b7 --- /dev/null +++ b/Plugin.php @@ -0,0 +1,96 @@ + 'helpers', + 'description' => 'No description provided yet...', + 'author' => 'wpstudio', + 'icon' => 'icon-leaf' + ]; + } + + /** + * Register method, called when the plugin is first registered. + * + * @return void + */ + public function register() + { + + } + + /** + * Boot method, called right before the request route. + * + * @return array + */ + public function boot() + { + + } + + /** + * Registers any front-end components implemented in this plugin. + * + * @return array + */ + public function registerComponents() + { + return []; // Remove this line to activate + + return [ + 'Wpstudio\Helpers\Components\MyComponent' => 'myComponent', + ]; + } + + /** + * Registers any back-end permissions used by this plugin. + * + * @return array + */ + public function registerPermissions() + { + return []; // Remove this line to activate + + return [ + 'wpstudio.helpers.some_permission' => [ + 'tab' => 'helpers', + 'label' => 'Some permission' + ], + ]; + } + + /** + * Registers back-end navigation items for this plugin. + * + * @return array + */ + public function registerNavigation() + { + return []; // Remove this line to activate + + return [ + 'helpers' => [ + 'label' => 'helpers', + 'url' => Backend::url('wpstudio/helpers/mycontroller'), + 'icon' => 'icon-leaf', + 'permissions' => ['wpstudio.helpers.*'], + 'order' => 500, + ], + ]; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..3596b90 --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +# Observers + +Observers maybe used for creating and clearing cache purposes + +## Example observer use + +Create you own class with observer: + +```php +rememberForever($cacheKey, fn() => + Models\Tag::all() +)); +``` + +* CacheManager::formatCacheKey - that is simple helper for concatenate array elements to string + +## Clearing cache from admin dashboard widget + +### Template + +```html + +``` + +### Controller widget action + +```php +use Dimti\Mirsporta\Classes\Observers; + +//... + +public function onClearTagCache() +{ + Observers\TagObserver::clearCache(); + + return ['status' => 1]; +} + +//... +``` diff --git a/classes/observer/BaseObserver.php b/classes/observer/BaseObserver.php new file mode 100644 index 0000000..515de4b --- /dev/null +++ b/classes/observer/BaseObserver.php @@ -0,0 +1,26 @@ +flush(); + } + + /** + * Получение тэка кеша + * @return string + */ + public static function getCacheTag(): string + { + return static::getClass(); + } +} diff --git a/classes/observer/Observer.php b/classes/observer/Observer.php new file mode 100644 index 0000000..03137f9 --- /dev/null +++ b/classes/observer/Observer.php @@ -0,0 +1,6 @@ +