function testNew() { $manager = new Manager(); $new = $manager->getInstance('Common\\InjectNew'); $this->assertInstanceOf('Common\\InjectNew', $new); $this->assertInstanceOf('Common\\Module', $new->module1); $this->assertInstanceOf('Common\\Module', $new->module2); $this->assertNotSame($new->module1, $new->module2); $this->assertSame($manager->getInjector()->getReferences($new->module1), array(array('instance' => $new, 'property' => 'module1'))); $this->assertSame($manager->getInstances('Common\\Module'), array($new->module1, $new->module2)); $new2 = $manager->create('Common\\InjectNew'); $this->assertInstanceOf('Common\\InjectNew', $new2); $this->assertInstanceOf('Common\\Module', $new2->module1); $this->assertInstanceOf('Common\\Module', $new2->module2); $this->assertNotSame($new2->module1, $new2->module2); $this->assertNotSame($new->module1, $new2->module1); $this->assertNotSame($new->module2, $new2->module2); $this->assertSame($manager->getInstances('Common\\Module'), array($new->module1, $new->module2, $new2->module1, $new2->module2)); $references = array($new, $new, $new2, $new2); foreach ($manager->getInstances('Common\\Module') as $module) { foreach ($manager->getInjector()->getReferences($module) as $reference) { $actual[] = $reference['instance']; } } $this->assertSame($references, $actual); }
public function testUrl() { $manager = new Manager(); $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/application-url/direct'; $web = $manager->create('Cti\\Core\\Module\\Web', array('base' => '/application-url/')); $this->assertSame($web->getUrl('test'), '/application-url/test'); }
public function testMethod() { $manager = new Manager(); $manager->getInitializer()->before('Common\\Module', array($this, 'callBefore')); $manager->getInitializer()->after('Common\\Module', array(__CLASS__, 'callAfter')); $module = $manager->create('Common\\Module'); $this->assertSame($module->state, 'Cti\\Di\\Manager'); $this->assertSame($module->reference, $manager); }
function testUsing() { $manager = new Manager(); /** * @var \Common\Usage $usage */ $usage = $manager->create('Common\\Usage'); $this->assertSame($usage->manager, $manager); $this->assertSame($usage->config, $manager->getConfiguration()); $this->assertSame($usage->globalManager, $manager); }
function getJobList(JobRepository $repository, Manager $manager) { $rows = array(); foreach ($repository->find(array(), 'many') as $item) { $rows[] = $item->asArray(); } if (!count($rows)) { $initializer = $manager->create('Scheduler\\Init'); return $this->getJobList($repository, $manager); } return array('data' => $rows); }
public function testAlias() { $manager = new Manager(); $manager->getConfiguration()->setAlias('app', 'Common\\Application'); $this->assertSame($manager->get('app'), $manager->get('Common\\Application')); $this->assertInstanceOf('Common\\Application', $manager->create('app')); }
/** * Create new model * @param $name * @param $comment * @param array $properties * @return Model */ public function createModel($name, $comment, $properties = array(), $pk = array()) { $this->models[$name] = $this->manager->create('Cti\\Storage\\Component\\Model', array('name' => $name, 'comment' => $comment, 'properties' => $properties, 'pk' => $pk)); $this->models[$name]->setNamespace($this->getNamespace()); return $this->models[$name]; }