Passed
Pull Request — master (#23)
by Nikolay
09:42 queued 03:08
created

CacheCleanerPlugin::beforeDispatch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 3
nc 3
nop 0
1
<?php
2
/**
3
 * Copyright (C) MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Nikolay Beketov, 6 2018
7
 *
8
 */
9
10
namespace MikoPBX\AdminCabinet\Plugins;
11
12
use Phalcon\Di\Injectable;
13
14
/**
15
 * CacheCleanerPlugin
16
 *
17
 * Check messages on clean cache queue
18
 */
19
class CacheCleanerPlugin extends Injectable
20
{
21
    /**
22
     * This action is executed before execute any action in the application
23
     *
24
     * @return bool
25
     */
26
    public function beforeDispatch(): bool
27
    {
28
        $queue = $this->getDI()->getShared('beanstalkConnectionCache');
29
30
        $arrayOfClearedModels = $queue->getMessagesFromTube();
31
        foreach ($arrayOfClearedModels as $clearedModel) {
32
            if (class_exists($clearedModel)) {
33
                call_user_func([$clearedModel, 'clearCache'], $clearedModel);
34
            }
35
        }
36
37
        return true;
38
    }
39
}
40