Skip to content

Commit

Permalink
Swap FileHelper methods for new Ini parser
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Oct 2, 2015
1 parent 8ed6a3c commit 91d3d4d
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 172 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* **Build 300** (2015-10-xx)
- Added new helper `Twig::parse` for parsing Twig.
- Page settings now support infinite array nesting with October flavored INI syntax via `Ini::parse` and `Ini::render`.

* **Build 298** (2015-09-24)
- Added the ability to use a wildcard URL parameter in CMS pages (see CMS > Pages docs).
Expand Down
4 changes: 2 additions & 2 deletions modules/cms/classes/CmsCompoundObject.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php namespace Cms\Classes;

use Ini;
use Cache;
use Config;
use Validator;
use SystemException;
use ValidationException;
use Cms\Classes\ViewBag;
use Cms\Classes\CodeBase;
use Cms\Classes\FileHelper;
use Cms\Twig\Loader as TwigLoader;
use Cms\Twig\Extension as CmsTwigExtension;
use System\Twig\Extension as SystemTwigExtension;
Expand Down Expand Up @@ -227,7 +227,7 @@ public function save()
$content = [];

if ($this->settings) {
$content[] = FileHelper::formatIniString($this->settings);
$content[] = Ini::render($this->settings);
}

if ($this->code) {
Expand Down
1 change: 1 addition & 0 deletions modules/cms/classes/CmsObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Cache;
use Config;
use Validator;
use Cms\Helpers\File as FileHelper;
use ApplicationException;
use ValidationException;
use RecursiveDirectoryIterator;
Expand Down
1 change: 0 additions & 1 deletion modules/cms/classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Cms\Twig\Loader as TwigLoader;
use Cms\Twig\DebugExtension;
use Cms\Twig\Extension as CmsTwigExtension;
use Cms\Classes\FileHelper as CmsFileHelper;
use Cms\Models\MaintenanceSettings;
use System\Models\RequestLog;
use System\Classes\ErrorHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php namespace Cms\Classes;
<?php namespace Cms\Helpers;

/**
* Defines some file-system helpers for the CMS system.
*
* @package october\system
* @author Alexey Bobkov, Samuel Georges
*/
class FileHelper
class File
{
/**
* Validates a CMS object file or directory name.
Expand Down Expand Up @@ -68,48 +68,4 @@ public static function validatePath($filePath, $maxNesting = 2)

return true;
}

/**
* Formats an INI file string from an array
* @param array $data Data to format.
* @param int $level Specifies the level of array value.
* @return string Returns the INI file string.
*/
public static function formatIniString($data, $level = 1)
{
$content = null;
$sections = [];

foreach ($data as $key => $value) {
if (is_array($value)) {
if ($level == 1) {
$sections[$key] = self::formatIniString($value, $level+1);
}
else {
foreach ($value as $val) {
$content .= $key.'[] = "'.self::escapeIniString($val).'"'.PHP_EOL;
}
}
}
elseif (strlen($value)) {
$content .= $key.' = "'.self::escapeIniString($value).'"'.PHP_EOL;
}
}

foreach ($sections as $key => $section) {
$content .= PHP_EOL.'['.$key.']'.PHP_EOL.$section.PHP_EOL;
}

return trim($content);
}

/**
* Escapes a string for saving in INI format
* @param string $string Specifies the string to escape
* @return string Returns the processed string
*/
public static function escapeIniString($string)
{
return str_replace('"', '\"', $string);
}
}
3 changes: 0 additions & 3 deletions modules/system/assets/ui/js/input.trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

this.options = options || {};

// @deprecated remove if year >= 2016
if (this.options.triggerType !== false && this.options.triggerAction === false) this.options.triggerAction = this.options.triggerType

if (this.options.triggerCondition === false)
throw new Error('Trigger condition is not specified.')

Expand Down
2 changes: 1 addition & 1 deletion modules/system/providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
'October\Rain\Foundation\Providers\ArtisanServiceProvider',
'October\Rain\Database\DatabaseServiceProvider',
'October\Rain\Filesystem\FilesystemServiceProvider',
'October\Rain\Parse\ParseServiceProvider',
'October\Rain\Html\HtmlServiceProvider',
'October\Rain\Html\UrlServiceProvider',
'October\Rain\Network\NetworkServiceProvider',
'October\Rain\Scaffold\ScaffoldServiceProvider',
'October\Rain\Flash\FlashServiceProvider',
'October\Rain\Mail\MailServiceProvider',
'October\Rain\Parse\ParseServiceProvider',

];
10 changes: 0 additions & 10 deletions tests/fixtures/cms/filehelper/sections.ini

This file was deleted.

2 changes: 0 additions & 2 deletions tests/fixtures/cms/filehelper/simple.ini

This file was deleted.

15 changes: 0 additions & 15 deletions tests/fixtures/cms/filehelper/subsections.ini

This file was deleted.

92 changes: 0 additions & 92 deletions tests/unit/cms/classes/FileHelperTest.php

This file was deleted.

18 changes: 18 additions & 0 deletions tests/unit/cms/helpers/FileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Cms\Helpers\File as FileHelper;

class FileTest extends TestCase
{
public function testValidateName()
{
$this->assertFalse(FileHelper::validateName(''));
$this->assertTrue(FileHelper::validateName('01test-testdat'));
$this->assertTrue(FileHelper::validateName('test/testdat'));
$this->assertFalse(FileHelper::validateName('test\testdat'));
$this->assertTrue(FileHelper::validateName('01test-test.dat'));
$this->assertFalse(FileHelper::validateName('[email protected]'));
$this->assertFalse(FileHelper::validateName('test::test'));
$this->assertFalse(FileHelper::validateName('@test'));
}
}

0 comments on commit 91d3d4d

Please sign in to comment.