Пример #1
0
 public function testFormatIniString()
 {
     $data = ['var1' => 'value 1', 'var2' => 'value 21'];
     $path = base_path() . '/tests/fixtures/cms/filehelper/simple.ini';
     $this->assertFileExists($path);
     $str = FileHelper::formatIniString($data);
     $this->assertNotEmpty($str);
     $this->assertEquals(file_get_contents($path), $str);
     $data = ['section' => ['sectionVar1' => 'section value 1', 'sectionVar2' => 'section value 2'], 'section data' => ['sectionVar3' => 'section value 3', 'sectionVar4' => 'section value 4'], 'var1' => 'value 1', 'var2' => 'value 21'];
     $path = base_path() . '/tests/fixtures/cms/filehelper/sections.ini';
     $this->assertFileExists($path);
     $str = FileHelper::formatIniString($data);
     $this->assertEquals(file_get_contents($path), $str);
     $data = ['section' => ['sectionVar1' => 'section value 1', 'sectionVar2' => 'section value 2', 'subsection' => ['subsectionVar1' => 'subsection value 1', 'subsectionVar2' => 'subsection value 2'], 'sectionVar3' => 'section value 3'], 'section data' => ['sectionVar3' => 'section value 3', 'sectionVar4' => 'section value 4', 'subsection' => ['subsectionVar1' => 'subsection value 1', 'subsectionVar2' => 'subsection value 2']], 'var1' => 'value 1', 'var2' => 'value 21'];
     $path = base_path() . '/tests/fixtures/cms/filehelper/subsections.ini';
     $this->assertFileExists($path);
     $str = FileHelper::formatIniString($data);
     $this->assertEquals(file_get_contents($path), $str);
 }
Пример #2
0
 /**
  * Saves the object to the disk.
  */
 public function save()
 {
     $this->code = trim($this->code);
     $this->markup = trim($this->markup);
     $trim = function (&$values) use(&$trim) {
         foreach ($values as &$value) {
             if (!is_array($value)) {
                 $value = trim($value);
             } else {
                 $trim($value);
             }
         }
     };
     $trim($this->settings);
     if (array_key_exists('components', $this->settings) && count($this->settings['components']) == 0) {
         unset($this->settings['components']);
     }
     $this->validate();
     $content = [];
     if ($this->settings) {
         $content[] = FileHelper::formatIniString($this->settings);
     }
     if ($this->code) {
         if ($this->wrapCodeToPhpTags() && array_get($this->originalData, 'code') != $this->code) {
             $code = preg_replace('/^\\<\\?php/', '', $this->code);
             $code = preg_replace('/^\\<\\?/', '', $code);
             $code = preg_replace('/\\?>$/', '', $code);
             $content[] = '<?php' . PHP_EOL . $this->code . PHP_EOL . '?>';
         } else {
             $content[] = $this->code;
         }
     }
     $content[] = $this->markup;
     $this->content = trim(implode(PHP_EOL . '==' . PHP_EOL, $content));
     parent::save();
 }
Пример #3
0
 /**
  * Saves the object to the disk.
  */
 public function save()
 {
     $this->code = trim($this->code);
     $this->markup = trim($this->markup);
     $trim = function (&$values) use(&$trim) {
         foreach ($values as &$value) {
             if (!is_array($value)) {
                 $value = trim($value);
             } else {
                 $trim($value);
             }
         }
     };
     $trim($this->settings);
     $this->validate();
     $content = [];
     if ($this->settings) {
         $content[] = FileHelper::formatIniString($this->settings);
     }
     if ($this->code) {
         $code = preg_replace('/^\\<\\?php/', '', $this->code);
         $code = preg_replace('/^\\<\\?/', '', $code);
         $code = preg_replace('/\\?>$/', '', $code);
         $content[] = '<?php' . PHP_EOL . $this->code . PHP_EOL . '?>';
     }
     $content[] = $this->markup;
     $this->content = trim(implode(PHP_EOL . '==' . PHP_EOL, $content));
     parent::save();
 }