public static function getById($id)
{
$id = intval($id);
if ($id < 1) {
return null;
}
$cacheKey = "object_" . $id;
try {
$object = \Zend_Registry::get($cacheKey);
if (!$object) {
throw new \Exception("Object\\AbstractObject: object in registry is null");
}
} catch (\Exception $e) {
try {
if (!($object = Cache::load($cacheKey))) {
$object = new Model\Object();
$typeInfo = $object->getDao()->getTypeById($id);
if ($typeInfo["o_type"] == "object" || $typeInfo["o_type"] == "variant" || $typeInfo["o_type"] == "folder") {
if ($typeInfo["o_type"] == "folder") {
$className = "Pimcore\\Model\\Object\\Folder";
} else {
$className = "Pimcore\\Model\\Object\\" . ucfirst($typeInfo["o_className"]);
}
$object = \Pimcore::getDiContainer()->make($className);
\Zend_Registry::set($cacheKey, $object);
$object->getDao()->getById($id);
Cache::save($object, $cacheKey);
} else {
throw new \Exception("No entry for object id " . $id);
}
} else {
\Zend_Registry::set($cacheKey, $object);
}
} catch (\Exception $e) {
Logger::warning($e->getMessage());
return null;
}
}
// check for type
$staticType = get_called_class();
if ($staticType != 'Pimcore\\Model\\Object\\Concrete' && $staticType != 'Pimcore\\Model\\Object\\AbstractObject') {
if (!$object instanceof $staticType) {
return null;
}
}
if (!$object) {
return null;
}
return $object;
}