Pimcore\Model\Object\ClassDefinition::getById PHP Méthode

getById() public static méthode

public static getById ( $id ) : mixed | null | ClassDefinition
$id
Résultat mixed | null | ClassDefinition
    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;
    }

Usage Example

Exemple #1
0
 /**
  * Loads a list of object-classes for the specicifies parameters, returns an array of Object|Class elements
  *
  * @return array
  */
 public function load()
 {
     $classes = array();
     $classesRaw = $this->db->fetchCol("SELECT id FROM classes" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($classesRaw as $classRaw) {
         $classes[] = Object\ClassDefinition::getById($classRaw);
     }
     $this->model->setClasses($classes);
     return $classes;
 }
All Usage Examples Of Pimcore\Model\Object\ClassDefinition::getById