setService() 공개 메소드

Set a service
public setService ( string $name, mixed $call, mixed $params = null ) : Project
$name string
$call mixed
$params mixed
리턴 Project
예제 #1
0
<?php

require_once '../../bootstrap.php';
use Pop\Project\Project;
try {
    $project = new Project();
    $project->setService('config', 'Pop\\Config', array(array('test' => 123)))->setService('color', 'Pop\\Color\\Color', function () {
        return array(new \Pop\Color\Rgb(255, 0, 0));
    });
    print_r($project);
    print_r($project->getService('config'));
    print_r($project->getService('color'));
    print_r($project);
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
예제 #2
0
 public function testServiceLocator()
 {
     $p = new Project();
     $p->setService('config', 'Pop\\Config', array(array('test' => 123)))->setService('color', 'Pop\\Color\\Color', function () {
         return array(new \Pop\Color\Space\Rgb(255, 0, 0));
     });
     $this->assertInstanceOf('Pop\\Config', $p->getService('config'));
     $this->assertInstanceOf('Pop\\Color\\Color', $p->getService('color'));
     $this->assertInstanceOf('Pop\\Service\\Locator', $p->getServiceLocator());
 }