1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-12 16:14:16 +02:00

Flextype Core: Snippets API - improvements and fixes

This commit is contained in:
Awilum
2019-02-20 16:46:06 +03:00
parent 3e5bc7622b
commit 6e9d53ac28

View File

@@ -45,10 +45,7 @@ class Snippets
*/
public static function rename(string $snippet, string $new_snippet) : bool
{
$snippet_file = PATH['snippets'] . '/' . $snippet . '.php';
$new_snippet_file = PATH['snippets'] . '/' . $new_snippet . '.php';
return rename($snippet_file, $new_snippet_file);
return rename(Snippets::_file_location($snippet), Snippets::_file_location($new_snippet));
}
/**
@@ -61,7 +58,7 @@ class Snippets
*/
public static function update(string $snippet, string $data) : bool
{
$snippet_file = PATH['snippets'] . '/' . $snippet . '.php';
$snippet_file = Snippets::_file_location($snippet);
if (Filesystem::has($snippet_file)) {
return Filesystem::write($snippet_file, $data);
@@ -80,7 +77,7 @@ class Snippets
*/
public static function create(string $snippet, string $data = '') : bool
{
$snippet_file = PATH['snippets'] . '/' . $snippet . '.php';
$snippet_file = Snippets::_file_location($snippet);
// Check if new entry file exists
if (!Filesystem::has($snippet_file)) {
@@ -99,9 +96,7 @@ class Snippets
*/
public static function delete(string $snippet) : bool
{
$snippet_file = PATH['snippets'] . '/' . $snippet . '.php';
return Filesystem::delete($snippet_file);
return Filesystem::delete(Snippets::_file_location($snippet));
}
/**
@@ -114,10 +109,7 @@ class Snippets
*/
public static function copy(string $snippet, string $new_snippet) : bool
{
$snippet_file = PATH['snippets'] . '/' . $snippet . '.php';
$new_snippet_file = PATH['snippets'] . '/' . $new_snippet . '.php';
return Filesystem::copy($snippet_file, $new_snippet_file, false);
return Filesystem::copy(Snippets::_file_location($snippet), Snippets::_file_location($new_snippet), false);
}
/**
@@ -129,9 +121,7 @@ class Snippets
*/
public static function has(string $snippet) : bool
{
$snippet_file = PATH['snippets'] . '/' . $snippet . '.php';
return Filesystem::has($snippet_file);
return Filesystem::has(Snippets::_file_location($snippet));
}
/**
@@ -151,7 +141,7 @@ class Snippets
$name = (isset($fetch)) ? (string) $fetch : '';
// Define snippet path
$snippet_file = PATH['snippets'] . '/' . $name . '.php';
$snippet_file = Snippets::_file_location($name);
// Process snippet
if (Filesystem::has($snippet_file)) {
@@ -168,4 +158,16 @@ class Snippets
throw new \RuntimeException("Snippet {$name} does not exist.");
}
}
/**
* Helper method _file_location
*
* @access private
* @param string $name Name
* @return string
*/
private static function _file_location($name)
{
return PATH['snippets'] . '/' . $name . '.php';
}
}