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

feat(core): Flextype Solid Core - next round #458

This commit is contained in:
Awilum
2020-08-14 21:37:30 +03:00
parent 32610d01ca
commit ad075be668
10 changed files with 33 additions and 36 deletions

View File

@@ -221,7 +221,7 @@ class Collection
*
* @param int|null $firstResult The value to set.
*
* @return
* @return
*
* @access public
*/

View File

@@ -35,7 +35,7 @@ if (! function_exists('collect_filter')) {
$collection = new Collection($items);
// Bind: return
$bind_return = isset($filter['return']) ? $filter['return'] : 'all';
$bind_return = $filter['return'] ?? 'all';
// Bind: where
$bind_where = [];
@@ -113,20 +113,20 @@ if (! function_exists('collect_filter')) {
break;
case 'random':
$bind_random_value = isset($filter['random_value']) ? (int) $filter['random_value'] : null;
$items = $collection->random($bind_random_value);
$items = $collection->random($bind_random_value);
break;
case 'limit':
$bind_set_max_result_value = isset($filter['limit_value']) ? (int) $filter['limit_value'] : 0;
$items = $collection->limit($bind_set_max_result_value);
$items = $collection->limit($bind_set_max_result_value);
break;
case 'set_first_result':
$bind_set_first_result_value = isset($filter['set_first_result_value']) ? (int) $filter['set_first_result_value'] : 0;
$items = $collection->setFirstResult($bind_set_first_result_value);
$items = $collection->setFirstResult($bind_set_first_result_value);
break;
case 'slice':
$bind_slice_offset_value = isset($filter['slice_offset_value']) ? (int) $filter['slice_offset_value'] : 0;
$bind_slice_limit_value = isset($filter['slice_limit_value']) ? (int) $filter['slice_limit_value'] : 0;
$items = $collection->slice($bind_slice_offset_value, $bind_slice_limit_value);
$bind_slice_limit_value = isset($filter['slice_limit_value']) ? (int) $filter['slice_limit_value'] : 0;
$items = $collection->slice($bind_slice_offset_value, $bind_slice_limit_value);
break;
case 'exists':
$items = $collection->exists();

View File

@@ -27,19 +27,19 @@ if (! function_exists('find_filter')) {
{
$find = find()->in($path);
isset($filter['depth']) and $find->depth($filter['depth']) or $find->depth(1);
isset($filter['date']) and $find->date($filter['date']);
isset($filter['size']) and $find->size($filter['size']);
isset($filter['exclude']) and $find->exclude($filter['exclude']);
isset($filter['contains']) and $find->contains($filter['contains']);
isset($filter['not_contains']) and $find->notContains($filter['not_contains']);
isset($filter['filter']) and $find->filter($filter['filter']);
isset($filter['sort']) and $find->sort($filter['sort']);
isset($filter['path']) and $find->path($filter['path']);
isset($filter['sort_by']) && $filter['sort_by'] == 'atime' and $find->sortByAccessedTime();
isset($filter['sort_by']) && $filter['sort_by'] == 'mtime' and $find->sortByModifiedTime();
isset($filter['sort_by']) && $filter['sort_by'] == 'ctime' and $find->sortByChangedTime();
isset($filter['depth']) and $find->depth($filter['depth']) or $find->depth(1);
isset($filter['date']) and $find->date($filter['date']);
isset($filter['size']) and $find->size($filter['size']);
isset($filter['exclude']) and $find->exclude($filter['exclude']);
isset($filter['contains']) and $find->contains($filter['contains']);
isset($filter['not_contains']) and $find->notContains($filter['not_contains']);
isset($filter['filter']) and $find->filter($filter['filter']);
isset($filter['sort']) and $find->sort($filter['sort']);
isset($filter['path']) and $find->path($filter['path']);
isset($filter['sort_by']) && $filter['sort_by'] === 'atime' and $find->sortByAccessedTime();
isset($filter['sort_by']) && $filter['sort_by'] === 'mtime' and $find->sortByModifiedTime();
isset($filter['sort_by']) && $filter['sort_by'] === 'ctime' and $find->sortByChangedTime();
return ($search_in == 'files') ? $find->files() : $find->directories();
return $search_in === 'files' ? $find->files() : $find->directories();
}
}

View File

@@ -52,7 +52,7 @@ class Shortcode
*
* @access public
*/
public function addHandler(string $name, $handler)
public function addHandler(string $name, callable $handler)
{
return $this->shortcode->addHandler($name, $handler);
}
@@ -65,7 +65,8 @@ class Shortcode
*
* @access public
*/
public function addEventHandler($name, $handler) {
public function addEventHandler(string $name, callable $handler)
{
return $this->shortcode->addEventHandler($name, $handler);
}

View File

@@ -7,13 +7,12 @@ declare(strict_types=1);
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
use Flextype\Component\Arrays\Arrays;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.entries.enabled')) {
// Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"]
$flextype->container('shortcode')->addHandler('entries_fetch', function (ShortcodeInterface $s) use ($flextype) {
$flextype->container('shortcode')->addHandler('entries_fetch', static function (ShortcodeInterface $s) use ($flextype) {
return Arrays::get($flextype['entries']->fetch($s->getParameter('id')), $s->getParameter('field'), $s->getParameter('default'));
});
}

View File

@@ -7,14 +7,13 @@ declare(strict_types=1);
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
use Thunder\Shortcode\EventHandler\FilterRawEventHandler;
use Thunder\Shortcode\Events;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.raw.enabled')) {
// Shortcode: [raw]
$flextype->container('shortcode')->addHandler('raw', function (ShortcodeInterface $s) use ($flextype) {
$flextype->container('shortcode')->addHandler('raw', static function (ShortcodeInterface $s) {
return $s->getContent();
});

View File

@@ -10,9 +10,8 @@ declare(strict_types=1);
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.registry.enabled')) {
// Shortcode: [registry_get name="item-name" default="default-value"]
$flextype->container('shortcode')->addHandler('registry_get', function (ShortcodeInterface $s) use ($flextype) {
$flextype->container('shortcode')->addHandler('registry_get', static function (ShortcodeInterface $s) use ($flextype) {
return $flextype->container('registry')->get($s->getParameter('name'), $s->getParameter('default'));
});
}

View File

@@ -11,9 +11,8 @@ use Slim\Http\Environment;
use Slim\Http\Uri;
if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.url.enabled')) {
// Shortcode: [url]
$flextype->container('shortcode')->addHandler('url', function () use ($flextype) {
$flextype->container('shortcode')->addHandler('url', static function () use ($flextype) {
if ($flextype->container('registry')->has('flextype.settings.url') && $flextype->container('registry')->get('flextype.settings.url') !== '') {
return $flextype->container('registry')->get('flextype.settings.url');
}

View File

@@ -15,6 +15,7 @@ use function count;
use function implode;
use function ltrim;
use function md5;
use function preg_replace;
use function preg_split;
use function trim;
use const PHP_EOL;
@@ -88,12 +89,10 @@ class Frontmatter
$matter = $this->flextype->container('yaml')->encode($input);
}
$encoded = '---' . "\n" .
return '---' . "\n" .
$matter .
'---' . "\n" .
$content;
return $encoded;
}
/**

View File

@@ -13,6 +13,7 @@ use RuntimeException;
use Symfony\Component\Yaml\Exception\DumpException as SymfonyYamlDumpException;
use Symfony\Component\Yaml\Exception\ParseException as SymfonyYamlParseException;
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
use function error_reporting;
use function function_exists;
use function ini_get;
use function ini_set;
@@ -44,7 +45,7 @@ class Yaml
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
$this->flextype = $flextype;
}
/**