Example #1
0
 /**
  * @param $id
  * @return mixed|null|ClassDefinition
  * @throws \Exception
  */
 public static function getById($id)
 {
     if ($id === null) {
         throw new \Exception("Class id is null");
     }
     $cacheKey = "class_" . $id;
     try {
         $class = \Zend_Registry::get($cacheKey);
         if (!$class) {
             throw new \Exception("Class in registry is null");
         }
     } catch (\Exception $e) {
         try {
             $class = new self();
             $name = $class->getDao()->getNameById($id);
             $definitionFile = $class->getDefinitionFile($name);
             $class = (include $definitionFile);
             if (!$class instanceof self) {
                 throw new \Exception("Class definition with name " . $name . " or ID " . $id . " does not exist");
             }
             $class->setId($id);
             \Zend_Registry::set($cacheKey, $class);
         } catch (\Exception $e) {
             Logger::error($e);
             return null;
         }
     }
     return $class;
 }