/** * @param string $identifier * @param string|null $locale * @return string * @throws \Exception */ public static function getString($identifier, $locale = null) { if (is_null($locale)) { $locale = Config::getConfigField("locale"); } $localePath = FinanCalc::getPath() . "/locale/{$locale}.php"; if (!file_exists($localePath)) { return null; } /** @noinspection PhpIncludeInspection */ $strings = (include $localePath); if (!is_array($strings) || !array_key_exists($identifier, $strings)) { return null; } return $strings[$identifier]; }
/** * @return \FinanCalc\Calculators\AnnuityCalculator * @throws Exception */ private function newPerpetuity() { return \FinanCalc\FinanCalc::getInstance()->getFactory('AnnuityCalculatorFactory')->newPerpetuity(50, 0.08); }
/** * @return SimpleInterestCalculator * @throws Exception */ private function newSimpleInterestCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleInterestCalculatorFactory')->newSimpleInterest(100, 0.0375, TimeSpan::asDuration(1)); }
/** * Test presence in the main Factories array */ public function testPresenceInMainFactoriesArray() { $this->assertTrue(isObjectTypeInArray('FinanCalc\\Calculators\\Factories\\BondYTMCalculatorFactory', \FinanCalc\FinanCalc::getInstance()->getFactories())); }
protected function setUp() { $this->debtAmortizatorFactory = FinanCalc::getInstance()->getFactory('DebtAmortizatorFactory')->newYearlyDebtAmortization(40000, 6, 0.12); parent::setUp(); }
/** * @return mixed * @throws Exception */ private function newSimpleDiscountCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleDiscountCalculatorFactory')->newSimpleDiscount(100000, 0.13, TimeSpan::asDuration(0, 6)); }
/** * @return mixed * @throws Exception */ private function newBondFairValueCalculatorFactorySemiAnnually() { return \FinanCalc\FinanCalc::getInstance()->getFactory('BondFairValueCalculatorFactory')->newSemiAnnualCouponsBond(10000, 0.12, 0.1, 7.5); }
/** * @return mixed * @throws Exception */ private function newStockDividendDiscountModelCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('StockDividendDiscountModelCalculatorFactory')->newZeroGrowthDividendDiscountModel(0.1, 75); }
/** * @return mixed * @throws Exception */ private function newBondInstanceFactoryAnnually() { return \FinanCalc\FinanCalc::getInstance()->getFactory('BondDurationCalculatorFactory')->newAnnualCouponsBond(1000, 0.08, 0.1, 3); }
/** * * PRIVATE functions * */ private function populateFactoryClassesArray() { $factoryFiles = glob(FinanCalc::getPath() . Config::getConfigField('factories_relative_path') . '/*.php'); $factoriesNamespace = Config::getConfigField('factories_namespace'); foreach ($factoryFiles as $factoryFile) { $factoryFileContents = file_get_contents($factoryFile); $fileTokens = token_get_all($factoryFileContents); $numTokens = count($fileTokens); for ($i = 2; $i < $numTokens; $i++) { if ($fileTokens[$i - 2][0] == T_CLASS) { $factoryClassName = $fileTokens[$i][1]; try { /** @noinspection PhpIncludeInspection */ require_once $factoryFile; $factoryClassReflector = new ReflectionClass($factoriesNamespace . '\\' . $factoryClassName); } catch (ReflectionException $e) { error_log(ErrorMessages::getFactoryClassExpectedInNamespaceMessage($factoryClassName, $factoriesNamespace)); continue; } $factoryAbstractClass = 'FinanCalc\\Interfaces\\Calculator\\CalculatorFactoryAbstract'; if ($factoryClassReflector->isSubclassOf($factoryAbstractClass)) { $this->factoryClasses[$factoryClassName] = $factoryClassReflector->newInstance(); break; } else { error_log(ErrorMessages::getFactoryClassExpectedAncestorMessage($factoryClassName, $factoryAbstractClass)); } } } } }
/** * @return mixed * @throws Exception */ private function newBondYTMCalculatorFactoryAnnually() { return \FinanCalc\FinanCalc::getInstance()->getFactory('BondYTMCalculatorFactory')->newAnnualCouponsBond(10000, 10800, 0.146, 3); }
/** * @return mixed * @throws Exception */ private function newStockInvestmentCalculatorFactory() { return \FinanCalc\FinanCalc::getInstance()->getFactory('StockInvestmentRatiosCalculatorFactory')->newCustomStocks(8000, 10000, 100); }