setService() public method

Set a service
public setService ( string $name, mixed $call, mixed $params = null ) : Project
$name string
$call mixed
$params mixed
return Project
コード例 #1
0
ファイル: project.php プロジェクト: nicksagona/PopPHP
<?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
ファイル: ProjectTest.php プロジェクト: nicksagona/PopPHP
 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());
 }