/** * Create an object or return existing one. * * <code> * $currencyId = 1; * * $currency = Crowdfunding\Currency::getInstance(\JFactory::getDbo(), $currencyId); * </code> * * @param \JDatabaseDriver $db * @param int $id * @param array $options * * @return null|self */ public static function getInstance(\JDatabaseDriver $db, $id, array $options = array()) { if (!array_key_exists($id, self::$instances)) { $item = new Currency($db); $item->load($id, $options); self::$instances[$id] = $item; } return self::$instances[$id]; }
/** * Create an object or return existing one. * * <code> * $currencyId = 1; * * $currency = Crowdfunding\Currency::getInstance(\JFactory::getDbo(), $currencyId); * </code> * * @param \JDatabaseDriver $db * @param int $id * * @return null|self */ public static function getInstance(\JDatabaseDriver $db, $id) { if (!isset(self::$instances[$id])) { $item = new Currency($db); $item->load($id); self::$instances[$id] = $item; } return self::$instances[$id]; }
/** * Return currency object. * * <code> * $currencyId = 1; * $currency = $this->getCurrency($currencyId); * </code> * * @param int $currencyId * * @throws \InvalidArgumentException * @throws \RuntimeException * * @return Currency */ protected function getCurrency($currencyId) { if (!$currencyId) { throw new \InvalidArgumentException('It is missing currency ID'); } $currency = new Currency(\JFactory::getDbo()); $currency->load($currencyId); return $currency; }
/** * Prepare and return currency object. * * <code> * $this->prepareCurrency($container, $params); * </code> * * @param Container $container * @param Registry $params * * @throws \RuntimeException * @throws \InvalidArgumentException * @throws \OutOfBoundsException */ protected function prepareCurrency($container, $params) { $currencyId = $params->get('project_currency'); $currencyHash = StringHelper::generateMd5Hash(Constants::CONTAINER_CURRENCY, $currencyId); // Get the currency from the container. if (!$container->exists($currencyHash)) { $currency = new Currency(\JFactory::getDbo()); $currency->load($currencyId); $container->set($currencyHash, $currency); } }