mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 08:04:05 +02:00
Flextype Core: New Fieldsets API
This commit is contained in:
121
flextype/Fieldsets.php
Normal file
121
flextype/Fieldsets.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Flextype
|
||||
*
|
||||
* @author Sergey Romanenko <hello@romanenko.digital>
|
||||
* @link http://romanenko.digital
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Registry\Registry;
|
||||
|
||||
class Fieldsets
|
||||
{
|
||||
|
||||
/**
|
||||
* Rename fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $fieldset Fieldset
|
||||
* @param string $new_fieldset New fieldset
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function rename(string $fieldset, string $new_fieldset) : bool
|
||||
{
|
||||
return rename(Fieldsets::_file_location($fieldset), Fieldsets::_file_location($new_fieldset));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $fieldset Fieldset
|
||||
* @param string $data Data
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function update(string $fieldset, string $data) : bool
|
||||
{
|
||||
$fieldset_file = Fieldsets::_file_location($fieldset);
|
||||
|
||||
if (Filesystem::has($fieldset_file)) {
|
||||
return Filesystem::write($fieldset_file, $data);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $fieldset Fieldset
|
||||
* @param string $data Data
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function create(string $fieldset, string $data = '') : bool
|
||||
{
|
||||
$fieldset_file = Fieldsets::_file_location($fieldset);
|
||||
|
||||
// Check if new entry file exists
|
||||
if (!Filesystem::has($fieldset_file)) {
|
||||
return Filesystem::write($fieldset_file, $data);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete fieldset.
|
||||
*
|
||||
* @access public
|
||||
* @param string $fieldset Fieldset
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function delete(string $fieldset) : bool
|
||||
{
|
||||
return Filesystem::delete(Fieldsets::_file_location($fieldset));
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy fieldset
|
||||
*
|
||||
* @access public
|
||||
* @param string $fieldset Fieldset
|
||||
* @param string $new_fieldset New fieldset
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function copy(string $fieldset, string $new_fieldset) : bool
|
||||
{
|
||||
return Filesystem::copy(Fieldsets::_file_location($fieldset), Fieldsets::_file_location($new_fieldset), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether fieldset exists.
|
||||
*
|
||||
* @access public
|
||||
* @param string $fieldset Fieldset
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function has(string $fieldset) : bool
|
||||
{
|
||||
return Filesystem::has(Fieldsets::_file_location($fieldset));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method _file_location
|
||||
*
|
||||
* @access private
|
||||
* @param string $name Name
|
||||
* @return string
|
||||
*/
|
||||
private static function _file_location($name)
|
||||
{
|
||||
return PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . $name . '.yaml';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user