コード例 #1
0
ファイル: KalturaObject.php プロジェクト: panigh/server
 public final function fromObject($srcObj, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if (!is_object($srcObj)) {
         KalturaLog::err("expected an object, got " . print_r($srcObj, true));
         return;
     }
     $thisClass = get_class($this);
     $srcObjClass = get_class($srcObj);
     $fromObjectClass = "Map_{$thisClass}_{$srcObjClass}";
     if (!class_exists($fromObjectClass)) {
         $cacheFileName = kConf::get("cache_root_path") . "/api_v3/fromObject/{$fromObjectClass}.php";
         if (!file_exists($cacheFileName)) {
             $cacheDir = dirname($cacheFileName);
             if (!is_dir($cacheDir)) {
                 mkdir($cacheDir);
                 chmod($cacheDir, 0755);
             }
             $fromObjectClassCode = $this->generateFromObjectClass($srcObj, $fromObjectClass);
             if (!$fromObjectClassCode) {
                 return;
             }
             kFile::safeFilePutContents($cacheFileName, $fromObjectClassCode);
         }
         require_once $cacheFileName;
     }
     $fromObjectClass::fromObject($this, $srcObj, $responseProfile);
     $this->doFromObject($srcObj, $responseProfile);
     if ($srcObj instanceof IRelatedObject) {
         KalturaResponseProfileCacher::onPersistentObjectLoaded($srcObj);
         if ($responseProfile && $responseProfile->relatedProfiles) {
             // trigger validation
             $responseProfile->validateNestedObjects();
             $this->relatedObjects = KalturaResponseProfileCacher::start($srcObj, $responseProfile);
             if (!$this->relatedObjects) {
                 $this->loadRelatedObjects($responseProfile);
                 KalturaResponseProfileCacher::stop($srcObj, $this);
             }
         }
     }
 }
コード例 #2
0
ファイル: KalturaObject.php プロジェクト: wzur/server
 public final function fromObject($srcObj, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if (!is_object($srcObj)) {
         KalturaLog::err("expected an object, got " . print_r($srcObj, true));
         return;
     }
     if ($srcObj instanceof IRelatedObject && $responseProfile && $responseProfile->relatedProfiles) {
         if (KalturaResponseProfileCacher::start($this, $srcObj, $responseProfile)) {
             return;
         }
     }
     $thisClass = get_class($this);
     $srcObjClass = get_class($srcObj);
     $fromObjectClass = "Map_{$thisClass}_{$srcObjClass}";
     if (!class_exists($fromObjectClass)) {
         $cacheFileName = kConf::get("cache_root_path") . "/api_v3/fromObject/{$fromObjectClass}.php";
         $max_include_retries = 10;
         $fromObjectClassCode = null;
         while (!@(include_once $cacheFileName) and $max_include_retries--) {
             if (!$fromObjectClassCode) {
                 $fromObjectClassCode = $this->generateFromObjectClass($srcObj, $fromObjectClass);
                 if (!$fromObjectClassCode) {
                     return;
                 }
             }
             $cacheDir = dirname($cacheFileName);
             if (!is_dir($cacheDir)) {
                 mkdir($cacheDir);
                 chmod($cacheDir, 0775);
             }
             kFile::safeFilePutContents($cacheFileName, $fromObjectClassCode, 0644);
         }
         if (!class_exists($fromObjectClass)) {
             throw new Exception("Could not include cached code file - {$cacheFileName}");
         }
     }
     $fromObjectClass::fromObject($this, $srcObj, $responseProfile);
     $this->doFromObject($srcObj, $responseProfile);
     if ($srcObj instanceof IRelatedObject) {
         KalturaResponseProfileCacher::onPersistentObjectLoaded($srcObj);
         if ($responseProfile && $responseProfile->relatedProfiles) {
             $responseProfile->validateNestedObjects();
             $this->loadRelatedObjects($responseProfile);
             KalturaResponseProfileCacher::stop($srcObj, $this);
         }
     }
 }