mikaelkael /
GearmanBundle
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Gearman Bundle for Symfony2 / Symfony3 |
||
| 5 | * |
||
| 6 | * For the full copyright and license information, please view the LICENSE |
||
| 7 | * file that was distributed with this source code. |
||
| 8 | * |
||
| 9 | * Feel free to edit as you please, and have fun. |
||
| 10 | * |
||
| 11 | * @author Marc Morera <[email protected]> |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Mkk\GearmanBundle\Service; |
||
| 15 | |||
| 16 | use Doctrine\Common\Cache\Cache; |
||
| 17 | use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface; |
||
| 18 | use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Gearman cache loader class |
||
| 22 | * |
||
| 23 | * This class has responsability of loading all gearman data structure |
||
| 24 | * and cache it if needed. |
||
| 25 | * |
||
| 26 | * Also provides this data to external services |
||
| 27 | */ |
||
| 28 | class GearmanCacheWrapper implements CacheClearerInterface, CacheWarmerInterface |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @var GearmanParser |
||
| 32 | * |
||
| 33 | * Gearman file parser |
||
| 34 | */ |
||
| 35 | private $gearmanParser; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var Cache |
||
| 39 | * |
||
| 40 | * Cache instance |
||
| 41 | */ |
||
| 42 | private $cache; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | * |
||
| 47 | * Cache id |
||
| 48 | */ |
||
| 49 | private $cacheId; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var array |
||
| 53 | * |
||
| 54 | * WorkerCollection with all workers and jobs available |
||
| 55 | */ |
||
| 56 | private $workerCollection; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Construct method |
||
| 60 | * |
||
| 61 | * @param GearmanParser $gearmanParser Gearman Parser |
||
| 62 | * @param Cache $cache Cache instance |
||
| 63 | * @param string $cacheId Cache id |
||
| 64 | */ |
||
| 65 | 8 | public function __construct( |
|
| 66 | GearmanParser $gearmanParser, |
||
| 67 | Cache $cache, |
||
| 68 | $cacheId |
||
| 69 | ) |
||
| 70 | { |
||
| 71 | 8 | $this->gearmanParser = $gearmanParser; |
|
| 72 | 8 | $this->cache = $cache; |
|
| 73 | 8 | $this->cacheId = $cacheId; |
|
| 74 | 8 | } |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Return gearman file parser |
||
| 78 | * |
||
| 79 | * @return GearmanParser |
||
| 80 | */ |
||
| 81 | 3 | public function getGearmanParser() |
|
| 82 | { |
||
| 83 | 3 | return $this->gearmanParser; |
|
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Return cache |
||
| 88 | * |
||
| 89 | * @return Cache Cache |
||
| 90 | */ |
||
| 91 | 4 | public function getCache() |
|
| 92 | { |
||
| 93 | 4 | return $this->cache; |
|
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Return cache id |
||
| 98 | * |
||
| 99 | * @return string Cache id |
||
| 100 | */ |
||
| 101 | 4 | public function getCacheId() |
|
| 102 | { |
||
| 103 | 4 | return $this->cacheId; |
|
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Return workerCollection |
||
| 108 | * |
||
| 109 | * @return array all available workers |
||
| 110 | */ |
||
| 111 | 3 | public function getWorkers() |
|
| 112 | { |
||
| 113 | 3 | return $this->workerCollection; |
|
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * loads Gearman cache, only if is not loaded yet |
||
| 118 | * |
||
| 119 | * @param Cache $cache Cache instance |
||
| 120 | * @param string $cacheId Cache id |
||
| 121 | * |
||
| 122 | * @return GearmanCacheWrapper self Object |
||
| 123 | */ |
||
| 124 | 8 | public function load(Cache $cache, $cacheId) |
|
| 125 | { |
||
| 126 | 8 | if ($cache->contains($cacheId)) { |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Cache contains gearman structure |
||
| 130 | */ |
||
| 131 | 6 | $this->workerCollection = $cache->fetch($cacheId); |
|
|
0 ignored issues
–
show
|
|||
| 132 | |||
| 133 | } else { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Cache is empty. |
||
| 137 | * |
||
| 138 | * Full structure must be generated and cached |
||
| 139 | */ |
||
| 140 | 3 | $this->workerCollection = $this |
|
| 141 | 3 | ->getGearmanParser() |
|
| 142 | 3 | ->load() |
|
| 143 | 3 | ->toArray(); |
|
| 144 | |||
| 145 | 3 | $cache->save($cacheId, $this->workerCollection); |
|
| 146 | } |
||
| 147 | |||
| 148 | 8 | return $this; |
|
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * flush all cache |
||
| 153 | * |
||
| 154 | * @param Cache $cache Cache instance |
||
| 155 | * @param string $cacheId Cache id |
||
| 156 | * |
||
| 157 | * @return GearmanCacheWrapper self Object |
||
| 158 | */ |
||
| 159 | 2 | public function flush(Cache $cache, $cacheId) |
|
| 160 | { |
||
| 161 | 2 | $cache->delete($cacheId); |
|
| 162 | |||
| 163 | 2 | return $this; |
|
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Cache clear implementation |
||
| 168 | * |
||
| 169 | * @param string $cacheDir The cache directory |
||
| 170 | * |
||
| 171 | * @return GearmanCacheWrapper self Object |
||
| 172 | */ |
||
| 173 | 2 | public function clear($cacheDir) |
|
| 174 | { |
||
| 175 | 2 | $this->flush($this->getCache(), $this->getCacheId()); |
|
| 176 | |||
| 177 | 2 | return $this; |
|
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Warms up the cache. |
||
| 182 | * |
||
| 183 | * @param string $cacheDir The cache directory |
||
| 184 | * |
||
| 185 | * @return GearmanCacheWrapper self Object |
||
| 186 | */ |
||
| 187 | 2 | public function warmUp($cacheDir) |
|
| 188 | { |
||
| 189 | 2 | $this->load($this->getCache(), $this->getCacheId()); |
|
| 190 | |||
| 191 | 2 | return $this; |
|
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Checks whether this warmer is optional or not. |
||
| 196 | * |
||
| 197 | * Optional warmers can be ignored on certain conditions. |
||
| 198 | * |
||
| 199 | * A warmer should return true if the cache can be |
||
| 200 | * generated incrementally and on-demand. |
||
| 201 | * |
||
| 202 | * As GearmanBundle loads cache incrementaly so is optional |
||
| 203 | * |
||
| 204 | * @return Boolean true if the warmer is optional, false otherwise |
||
| 205 | */ |
||
| 206 | 1 | public function isOptional() |
|
| 207 | { |
||
| 208 | 1 | return true; |
|
| 209 | } |
||
| 210 | } |
||
| 211 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..