public static function start(IRelatedObject $object, KalturaDetachedResponseProfile $responseProfile) { if (self::$cachedObject) { KalturaLog::debug("Object [" . get_class(self::$cachedObject) . "][" . self::$cachedObject->getId() . "] still caching"); return null; } KalturaLog::debug("Start " . get_class($object) . " [" . $object->getId() . "]"); $responseProfileKey = $responseProfile->getKey(); $setResponseProfile = self::$responseProfileKey != $responseProfileKey; $responseProfileCacheKey = self::getResponseProfileCacheKey($responseProfileKey, $object->getPartnerId()); if (self::get($responseProfileCacheKey)) { $key = self::getObjectSpecificCacheKey($object, $responseProfileKey); $invalidationKeys = array(self::getObjectKey($object), self::getRelatedObjectKey($object, $responseProfileKey)); $value = self::get($key, $invalidationKeys); if ($value) { $apiObject = unserialize($value->apiObject); KalturaLog::debug("Returned object: [" . print_r($apiObject, true) . "]"); if ($apiObject instanceof KalturaObject) { return $apiObject->relatedObjects; } } KalturaLog::debug("Object [" . get_class($object) . "][" . $object->getId() . "] - response profile found but object not cached"); } else { KalturaLog::debug("Object [" . get_class($object) . "][" . $object->getId() . "] - response profile not found"); } self::$cachedObject = $object; self::$responseProfileKey = $responseProfileKey; if ($setResponseProfile) { self::set($responseProfileCacheKey, serialize($responseProfile)); } }
public static function fromDbArray($arr, KalturaDetachedResponseProfile $responseProfile = null) { $newArr = new KalturaDetachedResponseProfileArray(); if ($arr == null) { return $newArr; } foreach ($arr as $obj) { $nObj = new KalturaDetachedResponseProfile(); if (!$nObj) { KalturaLog::alert("Object [" . get_class($obj) . "] type [" . $obj->getType() . "] could not be translated to API object"); continue; } $nObj->fromObject($obj, $responseProfile); $newArr[] = $nObj; } return $newArr; }
public function doFromObject($srcObj, KalturaDetachedResponseProfile $responseProfile = null) { /* @var $srcObj ResponseProfile */ parent::doFromObject($srcObj, $responseProfile); if ($srcObj->getFilter() && $this->shouldGet('filter', $responseProfile)) { $filterApiClassName = $srcObj->getFilterApiClassName(); $this->filter = new $filterApiClassName(); $this->filter->fromObject($srcObj->getFilter()); } }
public function loadRelatedObjects(KalturaDetachedResponseProfile $responseProfile) { // trigger validation $responseProfile->toObject(); if (!$responseProfile->relatedProfiles) { return; } $this->relatedObjects = new KalturaListResponseArray(); foreach ($responseProfile->relatedProfiles as $relatedProfile) { /* @var $relatedProfile KalturaDetachedResponseProfile */ if (!$relatedProfile->filter) { KalturaLog::notice("Related response-profile [{$relatedProfile->name}] has no filter and should not be used as nested profile"); continue; } KalturaLog::debug("Loading related response-profile [{$relatedProfile->name}] with filter [" . get_class($relatedProfile->filter) . "]"); $filter = clone $relatedProfile->filter; if ($relatedProfile->mappings) { $applied = true; foreach ($relatedProfile->mappings as $mapping) { /* @var $mapping KalturaResponseProfileMapping */ if (!$mapping->apply($filter, $this)) { $applied = false; break; } } if (!$applied) { KalturaLog::warning("Mappings could not be applied for response-profile [{$relatedProfile->name}]"); continue; } } else { KalturaLog::debug("No mappings defined in response-profile [{$relatedProfile->name}]"); } $pager = $relatedProfile->pager; if (!$pager) { $pager = new KalturaFilterPager(); } $this->relatedObjects[$relatedProfile->name] = $filter->getListResponse($pager, $relatedProfile); } }
public function toObject($object = null, $propertiesToSkip = array()) { if (is_null($object)) { $object = new ResponseProfile(); } return parent::toObject($object, $propertiesToSkip); }
/** * @param KalturaObject $apiObject * @param IRelatedObject $object * @param KalturaDetachedResponseProfile $responseProfile * @return boolean */ public static function start(KalturaObject $apiObject, IRelatedObject $object, KalturaDetachedResponseProfile $responseProfile) { if (self::$cachedObject) { KalturaLog::debug("Object [" . get_class(self::$cachedObject) . "][" . self::$cachedObject->getId() . "] still caching"); return false; } $responseProfileKey = $responseProfile->getKey(); $key = self::getObjectSpecificCacheKey($object, $responseProfileKey); $responseProfileCacheKey = self::getResponseProfileCacheKey($responseProfileKey, $object->getPartnerId()); list($value, $responseProfileCache) = self::get(array($key, $responseProfileCacheKey)); $invalidationKeys = array(self::getObjectKey($object), self::getRelatedObjectKey($object, $responseProfileKey)); if ($value && self::areKeysValid($invalidationKeys, $value->{self::CACHE_VALUE_TIME})) { $cachedApiObject = unserialize($value->apiObject); if ($cachedApiObject instanceof KalturaObject) { $properties = get_object_vars($cachedApiObject); foreach ($properties as $propertyName => $propertyValue) { $apiObject->{$propertyName} = $propertyValue; } return true; } KalturaLog::err("Object [" . get_class($object) . "][" . $object->getId() . "] - invalid object cached"); } KalturaLog::debug("Start " . get_class($object) . " [" . $object->getId() . "]"); if (self::$responseProfileKey != $responseProfileKey && !$responseProfileCache) { self::set($responseProfileCacheKey, array('responseProfile' => serialize($responseProfile))); } self::$cachedObject = $object; self::$responseProfileKey = $responseProfileKey; return false; }