/** * Reload the data if new file(s) are added */ private static function refresh() { if (self::$reload) { self::$instance->analyzeIniFile(); self::$reload = false; } }
/** * Factory for the serialize object manager. Get value from config.ini * * @param string $contextReferenceId the context reference id * * @return Serializer * * @throws OvoLoaderException */ public static function getSerializer($contextReferenceId) { $serializer = PropertiesLoader::getProperty(self::SERIALIZER); if (!$serializer) { throw new OvoLoaderException(self::SERIALIZER . ' not a valid serializer'); } /** @var $serializer SessionSerializer */ return $serializer::getInstance($contextReferenceId); }
private function __construct($class) { //TODO handle different logger object for different $class $cls = PropertiesLoader::getProperty(self::LOGGER); if (!class_exists($cls)) { throw new OvoLoaderException('Log adapter ' . $cls . ' not found'); } $this->logger = new $cls($class); }
/** * Check if session exists * * @param $applicationContextReference string the string to creare unique session reference ID * * @return void */ public static function init($contextReferenceId) { $name = PropertiesLoader::getProperty(self::SUFFIX) . md5(md5($contextReferenceId) . OvoVersion::VERSION); self::$sessionRepository[$contextReferenceId] = $name; if (self::sessionNotExist()) { //create session name from contextReferenceId self::createOvoSession($name); } else { self::getSessionName($name); } }
require_once '../../src/Ovo/Container/OvoLoader.php'; //Application file to classpath XmlContainer::addNamespaceToClassLoader('Ovo\\Test', '../src/'); //DI Container $container = new XmlContainer('../config/shopContext.xml', '../config/property.ini'); //empty the basket if (isset($_GET['void'])) { $container->destroyBean('basket'); } //get basket bean, defined as session and init only first time $basket = $container->getBean('basket'); //Business logic if (isset($_GET['add']) and is_int((int) $_GET['add'])) { $basket->addToBasket((int) $_GET['add']); } if (isset($_GET['remove']) and is_int((int) $_GET['remove'])) { $basket->removeFromBasket((int) $_GET['remove']); } //View - Print all product shop $shop = new ProductRepository(); echo PropertiesLoader::getProperty('shop_name') . '<hr>'; foreach ($shop->getShopProducts() as $k => $v) { echo 'ID: ' . $v->getId() . ' Description: ' . $v->getDescription() . ' Price:' . $v->getPrice() . ' - <a href=\'shop.php?add=' . $v->getId() . '\'>Add To Basket</a> - <a href=\'shop.php?remove=' . $v->getId() . '\'>Remove From Basket</a></br>'; } //Print Basket echo 'Basket (Products ' . $basket->numberOfBasketProducts() . ''; echo ' / Amount ' . $basket->amountOfBasketProducts() . ')'; echo ' </br><a href=\'shop.php?void=true\'>Void Basket</a>';
public function testRewriteSystemPropertiesFromExternalIniFileCalledFromConstruct() { $this->container->close(); $this->container = new XmlContainer(__DIR__ . self::CONFIG_FILE, __DIR__ . '/config/rewrite.ini'); $this->assertEquals('false', PropertiesLoader::getProperty('ovo.bean.lazy.init'), 'init-on-boot is not false'); }
/** * If $old is a variable, replace it with the INI value * * @param $old string the name present into the XML file * * @return string the name of the variabile */ private function replaceVariable($old) { //TODO refactoring $value = $old; $this->logger->debug('Check if ' . $old . ' it is a variable'); if (substr($old, 0, 2) == self::DEL_LEFT and substr($old, -1) == self::DEL_RIGHT) { $name = str_replace(self::DEL_RIGHT, '', str_replace(self::DEL_LEFT, '', $old)); $new = PropertiesLoader::getProperty($name); $this->logger->debug('replace ' . $old . ' variable with the value ' . $new . ' of variable ' . $name); $value = $new; } return $value; }
/** * @expectedException Ovo\Common\Exception\OvoCommonException */ public function testAddNotParsableIniFile() { PropertiesLoader::getInstance(__DIR__ . '/ini/simpleWithError.ini'); PropertiesLoader::getProperty('test'); }
/** * Method to shutdown the container * * @return void */ public function close() { PropertiesLoader::destroy(); $this->ovoContainer->close(); }
public function __construct($class) { $this->logger = new Logger($class); $this->logger->pushHandler(new StreamHandler(PropertiesLoader::getProperty(self::LOGGER_FILE), PropertiesLoader::getProperty(self::LOGGER_LEVEL))); }
/** * Get the ContextReader and set up this into the Container * * @param Configuration $configuration the Configuration implementation * @param string $contextReferenceId the context application reference id * * @return void */ private function init(Configuration $configuration, $contextReferenceId) { $this->logger->debug('Create configuration ' . get_class($configuration)); $contextReader = $configuration->getContextReader(); $this->coreContainer = SingletonCoreContainer::getInstance($contextReferenceId); $this->isApplicationLoaded($contextReader, $contextReferenceId); if ($configuration->isLoadedForTheFirstTime() and PropertiesLoader::getProperty(self::LAZY_INIT) == 'false') { $this->initBeans($contextReader); } }
public function getVarFromIniFile() { return PropertiesLoader::getProperty('varByClass'); }