Example #1
0
 /**
  * Magic method for lazy loading $components.
  *
  * @param string $name Name of component to get.
  * @return mixed A Component object or null.
  */
 public function __get($name)
 {
     if (isset($this->_componentMap[$name]) && !isset($this->{$name})) {
         $config = ['enabled' => false] + (array) $this->_componentMap[$name]['config'];
         $this->{$name} = $this->_registry->load($this->_componentMap[$name]['class'], $config);
     }
     if (isset($this->{$name})) {
         return $this->{$name};
     }
 }
Example #2
0
 /**
  * Test a duplicate component being loaded more than once with same and differing configurations.
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage The "Banana" alias has already been loaded with the following config:
  * @return void
  */
 public function testDuplicateComponentInitialize()
 {
     $Collection = new ComponentRegistry();
     $Collection->load('Banana', ['property' => ['closure' => function () {
     }]]);
     $Collection->load('Banana', ['property' => ['closure' => function () {
     }]]);
     $this->assertInstanceOf('TestApp\\Controller\\Component\\BananaComponent', $Collection->Banana, 'class is wrong');
     $Collection->load('Banana', ['property' => ['differs']]);
 }
 /**
  * test a component being used more than once.
  *
  * @return void
  */
 public function testMultipleComponentInitialize()
 {
     $Collection = new ComponentRegistry();
     $Banana = $Collection->load('Banana');
     $Orange = $Collection->load('Orange');
     $this->assertSame($Banana, $Orange->Banana, 'Should be references');
     $Banana->testField = 'OrangeField';
     $this->assertSame($Banana->testField, $Orange->Banana->testField, 'References are broken');
 }