示例#1
0
 /**
  * Constructor.
  * The default implementation does two things:
  *
  * - Initializes the object with the given configuration `$config`.
  * - Call [[init()]].
  *
  * If this method is overridden in a child class, it is recommended that
  *
  * - the last parameter of the constructor is a configuration array, like `$config` here.
  * - call the parent implementation at the end of the constructor.
  *
  * @param array $config name-value pairs that will be used to initialize the object properties
  */
 public function __construct($config = [])
 {
     if (!empty($config)) {
         Creator::configure($this, $config);
     }
     $this->init();
 }
 protected function configure($config = [])
 {
     if (!empty($config)) {
         $autoCamelCase = isset($this->autoCamelCase) ? $this->autoCamelCase : false;
         Creator::configure($this, $config, $autoCamelCase);
     }
 }
 public function testConfigure()
 {
     $obj = Creator::createObject(['class' => 'TestCreate', 'test' => 1]);
     $this->assertInstanceOf('TestCreate', $obj);
     $this->assertEquals(1, $obj->test);
     Creator::configure($obj, ['test' => 2]);
     $this->assertEquals(2, $obj->test);
 }
 public function __construct(Model $model, array $config = [])
 {
     Creator::configure($this, $config);
     $this->_model = $model;
 }
 protected function configure($config = [])
 {
     if (!empty($config)) {
         Creator::configure($this, $config);
     }
 }