Pimcore\Model\Object\AbstractObject::getById PHP Method

getById() public static method

public static getById ( integer $id ) : static
$id integer
return static
    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;
    }

Usage Example

Esempio n. 1
0
 /**
  * @return OnlineShop_Framework_ProductInterfaces_ICheckoutable
  */
 public function getProduct()
 {
     if ($this->product) {
         return $this->product;
     }
     $this->product = \Pimcore\Model\Object\AbstractObject::getById($this->productId);
     return $this->product;
 }
All Usage Examples Of Pimcore\Model\Object\AbstractObject::getById