Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/ObjectCommand.php
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | abstract class ObjectCommand extends Command | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
protected $cacheKeys = []; | protected $cacheKeys = []; | ||||
/** | /** | ||||
* Reset the cache for specified object using defined cacheKeys. | * Reset the cache for specified object using defined cacheKeys. | ||||
* | * | ||||
* @param object The object that was updated/created | * @param object $object The object that was updated/created | ||||
*/ | */ | ||||
protected function cacheRefresh($object): void | protected function cacheRefresh($object): void | ||||
{ | { | ||||
foreach ($this->cacheKeys as $cacheKey) { | foreach ($this->cacheKeys as $cacheKey) { | ||||
foreach ($object->toArray() as $propKey => $propValue) { | foreach ($object->toArray() as $propKey => $propValue) { | ||||
if (!is_object($propValue)) { | if (!is_object($propValue)) { | ||||
$cacheKey = str_replace('%' . $propKey . '%', $propValue, $cacheKey); | $cacheKey = str_replace('%' . $propKey . '%', $propValue, $cacheKey); | ||||
} | } | ||||
} | } | ||||
Cache::forget($cacheKey); | Cache::forget($cacheKey); | ||||
} | } | ||||
} | } | ||||
} | } |