/**
  * @param $xmlFilePath
  * @param bool $shareBeanCache whether to share the bean cache when the context's uniqueID (file path) is the same.
  * @param ValueTagProvider[] $customNamespaces
  * @throws \MooDev\Bounce\Exception\BounceException
  */
 public function __construct($xmlFilePath, $shareBeanCache = true, $customNamespaces = array())
 {
     if (!file_exists($xmlFilePath)) {
         throw new BounceException("XML context not found: " . $xmlFilePath);
     }
     $this->_customNamespaces = $customNamespaces;
     $contextConfig = $this->_parseXmlFile(realpath($xmlFilePath));
     //Create the bean factory
     $this->_beanFactory = BeanFactory::getInstance($contextConfig, $shareBeanCache);
 }
 public function testSimpleValue()
 {
     $factory = BeanFactory::getInstance(new Context());
     $impl = new SimpleValueProvider("steve");
     $this->assertEquals("steve", $impl->getValue($factory));
     $impl = new SimpleValueProvider(false);
     $this->assertFalse($impl->getValue($factory));
     $impl = new SimpleValueProvider(2);
     $this->assertEquals(2, $impl->getValue($factory));
     $impl = new SimpleValueProvider(56.789);
     $this->assertEquals(56.789, $impl->getValue($factory));
 }
 public function testBeanProvider()
 {
     $parentBean = new Bean();
     $parentBean->name = "parent";
     $parentBean->class = "StdClass";
     $childBean = new Bean();
     $childBean->class = "StdClass";
     $childBean->properties["grandChild"] = new SimpleValueProvider("someValue");
     $parentBean->properties["child"] = new BeanValueProvider($childBean);
     $beanFactory = BeanFactory::getInstance(new Context());
     $o = $beanFactory->create($parentBean);
     $this->assertEquals("someValue", $o->child->grandChild);
 }
 public function testBadFilepath()
 {
     //Have to keep the root dir within the moocommon-infra area in order for Hudson to
     //correctly work as well
     if (!defined("DOC_DIR")) {
         define("DOC_DIR", realpath(__DIR__ . '/../../../'));
     }
     $impl = new FilePathValueProvider("../moo-common-log/build.xml");
     try {
         $impl->getValue(BeanFactory::getInstance(new Context()));
     } catch (BounceException $e) {
         $this->assertEquals(1, preg_match("|^Relative path ../moo-common-log/build.xml (.*) does not lie within the root (.*)|", $e->getMessage()));
     }
 }
 public function getValue(BeanFactory $beanFactory)
 {
     return $beanFactory->createByName($this->_beanName);
 }
 public function testSimpleList()
 {
     $impl = new ListValueProvider(array(new SimpleValueProvider("steve"), new SimpleValueProvider("jon"), new SimpleValueProvider("roly")));
     $this->assertEquals(array("steve", "jon", "roly"), $impl->getValue(BeanFactory::getInstance(new Context())));
 }
 public function testConstantRetrieval()
 {
     define("STEVE_TEST", "HELLO!");
     $impl = new ConstantValueProvider("STEVE_TEST");
     $this->assertEquals("HELLO!", $impl->getValue(BeanFactory::getInstance(new Context())));
 }
Example #8
0
 /**
  * @param $xmlFilePath
  * @param bool $shareBeanCache whether to share the bean cache when the context's uniqueID (file path) is the same.
  * @param ValueTagProvider[] $customNamespaces
  * @throws \MooDev\Bounce\Exception\BounceException
  */
 public function __construct($xmlFilePath, $shareBeanCache = true, $customNamespaces = array())
 {
     $contextConfig = (new XmlContextParser($xmlFilePath, $customNamespaces))->getContext();
     //Create the bean factory
     parent::__construct(BeanFactory::getInstance($contextConfig, $shareBeanCache));
 }
Example #9
0
 /**
  * Returns the factory to be used for the bean with the given name from all the descendent contexts.
  *
  * @param string $name the name of the bean we wish to create.
  * @return BeanFactory the factory which will be able to create this
  * bean.
  */
 protected function _getChildFactoryFor($name)
 {
     $childContext = $this->_getChildContextFor($name, $this->_contextConfig);
     if (!is_null($childContext)) {
         return BeanFactory::getInstance($childContext);
     } else {
         return null;
     }
 }
 public function testNullValue()
 {
     $impl = new NullValueProvider();
     $this->assertNull($impl->getValue(BeanFactory::getInstance(new Context())));
 }
 /**
  * @param $xmlFilePath
  * @param bool $shareBeanCache whether to share the bean cache when the context's uniqueID (file path) is the same.
  * @param ValueTagProvider[] $customNamespaces
  * @param array $logFactory
  */
 public function __construct($xmlFilePath, $shareBeanCache = true, $customNamespaces = array(), $logFactory = array('\\MooDev\\Bounce\\Logger\\NullLogFactory', 'getLog'))
 {
     $contextConfig = (new XmlContextParser($xmlFilePath, $customNamespaces))->getContext();
     //Create the bean factory
     parent::__construct(BeanFactory::getInstance($contextConfig, $shareBeanCache));
 }
Example #12
0
 public function testMethodInjectionConstructors()
 {
     $context = new Config\Context();
     $bean = new Config\Bean();
     $bean->class = "StdClass";
     $bean->name = "in";
     $bean->properties["test"] = new Config\SimpleValueProvider("jon");
     $context->beans["in"] = $bean;
     $bean = new Config\Bean();
     $bean->class = '\\MooDev\\Bounce\\Context\\methodInjectionTestClass';
     $bean->name = "out";
     $context->beans["out"] = $bean;
     $bean->lookupMethods = array(new Config\LookupMethod("getInner", "in"));
     $bean->constructorArguments = array(new Config\SimpleValueProvider("hello"), new Config\SimpleValueProvider("world"));
     $impl = BeanFactory::getInstance($context);
     $o = $impl->createByName("out");
     $this->assertEquals("jon", $o->getInner()->test);
     $this->assertEquals("hello", $o->a);
     $this->assertEquals("world", $o->b);
 }