Beispiel #1
0
 public function testServicesSearch()
 {
     $this->object->set('testDef', ScalarDefinition::factory('definitionDataTest')->setData(array('dataOne' => true, 'text' => 'hello John')));
     $this->object->set('testDef2', ScalarDefinition::factory('definitionDataTest')->setData(array('dataOne' => false, 'text' => 'hello Doe')));
     $this->object->set('testDef3', ScalarDefinition::factory('definitionDataTest')->setData(array('dataTwo' => false, 'text' => 'Hey guys!')));
     $results = $this->object->search(array('dataOne' => true));
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('testDef', $results);
     $results = $this->object->search(array('dataOne' => false));
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('testDef2', $results);
     $results = $this->object->search(array('nothing'));
     $this->assertEquals(0, count($results));
     $results = $this->object->search(array('text' => 'hello*'));
     $this->assertEquals(2, count($results));
     $this->assertArrayHasKey('testDef', $results);
     $this->assertArrayHasKey('testDef2', $results);
     $results = $this->object->search(array('text' => '*guys?'));
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('testDef3', $results);
 }
Beispiel #2
0
 /**
  * Registers a definition
  * 
  * @param string  $name             Identifier
  * @param DefinitionInterface|mixed $definition Definition, callable or value
  *
  * @return Container
  */
 public function set($name, $definition)
 {
     if (!$definition instanceof DefinitionInterface) {
         if (is_callable($definition)) {
             $definition = CallableDefinition::factory($definition);
         } elseif (is_array($definition)) {
             $definition = ArrayDefinition::factory($definition);
         } else {
             $wasObj = is_object($definition);
             $definition = ScalarDefinition::factory($definition);
             if ($wasObj) {
                 $definition->setShared(true);
                 $this->_sharedInstances->attach($definition, $name);
             }
         }
     }
     $event = new BeforeServiceRegisteredEvent($this, $name, $definition);
     $this->notify($event);
     if ($event->isStopped()) {
         return $this;
     }
     $this->store->attach($definition, $name);
     $this->notify(new AfterServiceRegisteredEvent($this, $name, $definition));
     return $this;
 }