2.2. Getting a component

You can get a component by the s2get funcion. The class name that is the key to the component is specified by the argument of the s2get function.

<?php
require_once('S2Container.php');

class Service {}

class Action {
    public function setService(Service $service) {
        $this->service = $service;
    }
}

$action = s2get('Action');
var_dump($action);

The execution result is as follows. The Service instance is injected to the Action instance.

% php quickstart005.php
object(Action)#26 (1) {
  ["service"]=>
  object(Service)#39 (0) {
  }
}
%

Please refer to the following "Registration of the component" when you name the component name to the component besides the class name.


[Note]NOTE

This Example is located at "examples/quickstart/quickstart005.php".



© Copyright The Seasar Foundation and the others 2005-2010, all rights reserved.