set() публичный Метод

Set a value in the data
public set ( string $name, mixed $value )
$name string The key used to set the value
$value mixed The value to set
Пример #1
0
 /**
  * @param string $module
  * @param string $format
  * @return Data
  */
 protected function _listFactory($module, $format)
 {
     $key = $module . '.' . $format;
     if ($list = $this->_storage->get($key)) {
         return $list;
     }
     if ($module === self::DEFAULT_MODULE) {
         $path = $module . ':langs/' . $this->_code . '.' . $format;
     } else {
         $path = $module . ':langs/' . $this->_code . '.' . $module . '.' . $format;
     }
     $listPath = $this->_path->get($path);
     // @codeCoverageIgnoreStart
     if ('php' === $format) {
         $list = new PHPArray($listPath);
     } elseif ('json' === $format) {
         $list = new JSON($listPath);
     } elseif ('ini' === $format) {
         $list = new Ini($listPath);
     } elseif ('yml' === $format) {
         $list = new Yml($listPath);
     } else {
         $list = new Data([]);
     }
     // @codeCoverageIgnoreEnd
     $this->_storage->set($key, $list);
     return $list;
 }
Пример #2
0
 public function testSet()
 {
     // methods
     $data = new Data($this->_test);
     is(10, $data->get('number'));
     $data->set('number', 'qqq');
     is('qqq', $data->get('number'));
     // like array
     $data = new Data($this->_test);
     is(10, $data['number']);
     $data['number'] = 'qqq';
     is('qqq', $data['number']);
     // like object
     $data = new Data($this->_test);
     is(10, $data->number);
     $data->number = 'qqq';
     is('qqq', $data->number);
 }