/** * @depends testGetXmlRootObj */ public function testConfigureBySection($pSection) { $test = new testClass(); $this->assertEquals('', $test->LOGFILE); \Savant\CConfigure::configureBySection($test, $pSection->configurations->default); $this->assertEquals('bronckotest.log', $test->LOGFILE); }
/** * invoke before constructor is called * @param IConfigure $pObj * @param AOP\AJoinPoint $pJoinPoint */ public static function onBeforeConstructor(&$pObj, AOP\AJoinPoint $pJoinPoint) { if (!$pObj instanceof \Savant\IConfigure) { return; } if (\method_exists($pObj, 'configure')) { $pObj->configure($pObj->confSection); return; } $class = \get_class($pObj); try { $config = $pObj->config = CConfigure::getClassConfig($class, $pObj->confSection); } catch (\Savant\EConfigure $e) { return; } foreach ($config->member as $memberElement) { try { $propObj = new \ReflectionProperty($class, \strtoupper($memberElement->attributes()->name)); $propObj->setValue($pObj, $memberElement); } catch (ReflectionException $e) { return; } } }
/** * configure database object from datasources * @param string $pSection */ public function configure($pSection = 'default') { $config = \Savant\CConfigure::load($this->confFile); $section = $config->datasources->xpath("//datasource[@name='" . $pSection . "']"); foreach (\Savant\CConfigure::getConfigFromSection($section[0]) as $configVar => $configVal) { $this->{\strtoupper($configVar)} = $configVal; } }