コード例 #1
0
ファイル: Strings.php プロジェクト: uruba/financalc
 /**
  * @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];
 }
コード例 #2
0
 /**
  * @return \FinanCalc\Calculators\AnnuityCalculator
  * @throws Exception
  */
 private function newPerpetuity()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('AnnuityCalculatorFactory')->newPerpetuity(50, 0.08);
 }
コード例 #3
0
 /**
  * @return SimpleInterestCalculator
  * @throws Exception
  */
 private function newSimpleInterestCalculatorFactory()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleInterestCalculatorFactory')->newSimpleInterest(100, 0.0375, TimeSpan::asDuration(1));
 }
コード例 #4
0
 /**
  * Test presence in the main Factories array
  */
 public function testPresenceInMainFactoriesArray()
 {
     $this->assertTrue(isObjectTypeInArray('FinanCalc\\Calculators\\Factories\\BondYTMCalculatorFactory', \FinanCalc\FinanCalc::getInstance()->getFactories()));
 }
コード例 #5
0
 protected function setUp()
 {
     $this->debtAmortizatorFactory = FinanCalc::getInstance()->getFactory('DebtAmortizatorFactory')->newYearlyDebtAmortization(40000, 6, 0.12);
     parent::setUp();
 }
コード例 #6
0
 /**
  * @return mixed
  * @throws Exception
  */
 private function newSimpleDiscountCalculatorFactory()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('SimpleDiscountCalculatorFactory')->newSimpleDiscount(100000, 0.13, TimeSpan::asDuration(0, 6));
 }
コード例 #7
0
 /**
  * @return mixed
  * @throws Exception
  */
 private function newBondFairValueCalculatorFactorySemiAnnually()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('BondFairValueCalculatorFactory')->newSemiAnnualCouponsBond(10000, 0.12, 0.1, 7.5);
 }
コード例 #8
0
 /**
  * @return mixed
  * @throws Exception
  */
 private function newStockDividendDiscountModelCalculatorFactory()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('StockDividendDiscountModelCalculatorFactory')->newZeroGrowthDividendDiscountModel(0.1, 75);
 }
コード例 #9
0
 /**
  * @return mixed
  * @throws Exception
  */
 private function newBondInstanceFactoryAnnually()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('BondDurationCalculatorFactory')->newAnnualCouponsBond(1000, 0.08, 0.1, 3);
 }
コード例 #10
0
ファイル: FinanCalc.php プロジェクト: uruba/financalc
 /**
  *
  * 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));
                 }
             }
         }
     }
 }
コード例 #11
0
 /**
  * @return mixed
  * @throws Exception
  */
 private function newBondYTMCalculatorFactoryAnnually()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('BondYTMCalculatorFactory')->newAnnualCouponsBond(10000, 10800, 0.146, 3);
 }
コード例 #12
0
 /**
  * @return mixed
  * @throws Exception
  */
 private function newStockInvestmentCalculatorFactory()
 {
     return \FinanCalc\FinanCalc::getInstance()->getFactory('StockInvestmentRatiosCalculatorFactory')->newCustomStocks(8000, 10000, 100);
 }