diff --git a/Aeria/Aeria.php b/Aeria/Aeria.php index b9a3763..449f703 100755 --- a/Aeria/Aeria.php +++ b/Aeria/Aeria.php @@ -33,7 +33,7 @@ */ class Aeria extends Container { - public const VERSION = '3.0.17'; + public const VERSION = '3.0.18'; /** * Constructs the Aeria container * diff --git a/Aeria/Kernel/Kernel.php b/Aeria/Kernel/Kernel.php index 3f7c7b3..61473f6 100644 --- a/Aeria/Kernel/Kernel.php +++ b/Aeria/Kernel/Kernel.php @@ -5,51 +5,48 @@ use Aeria\Container\Container; use Aeria\Kernel\AbstractClasses\Task; use Aeria\Structure\Traits\DictionaryTrait; + /** * The kernel is in charge of the boot of Aeria. - * + * * @category Kernel - * @package Aeria + * * @author Jacopo Martinelli * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license - * @link https://github.com/caffeinalab/aeria + * + * @see https://github.com/caffeinalab/aeria */ class Kernel { use DictionaryTrait; + /** * This function registers a task to the kernel. * * @param Task $task the task we want to register * - * @return void - * - * @access public * @since Method available since Release 3.0.0 */ public function register(Task $task) { $key = get_class($task); - $key = substr($key, strrpos($key, '\\')+1); + $key = substr($key, strrpos($key, '\\') + 1); $key = toSnake($key); $this->set($key, $task); } /** - * This function boots all of the services and tasks. + * This function boots all of the services and tasks. * * @param Container $container where we've bound the services * - * @return void - * - * @access public * @since Method available since Release 3.0.0 - */ + */ public function boot(Container $container) { // Services - $service_abstracts = ['meta', 'validator', 'query', 'router', 'controller', - 'taxonomy', 'updater', 'render_engine', 'field', 'options', 'post_type']; + $service_abstracts = ['config', 'meta', 'validator', 'query', 'router', 'controller', + 'taxonomy', 'updater', 'render_engine', 'field', 'options', 'post_type', ]; foreach ($service_abstracts as $abstract) { $service[$abstract] = $container->make($abstract); } @@ -57,32 +54,36 @@ public function boot(Container $container) $args = [ 'config' => $container->make('config')->all(), 'service' => $service, - 'container' => $container + 'container' => $container, ]; $tasks = $this->all(); uasort($tasks, array($this, 'compareTasks')); foreach ($tasks as $task) { - if(is_admin() && $task->admin_only) - $task->do($args); - else if (!$task->admin_only) - $task->do($args); + if ((is_admin() && $task->admin_only) || !$task->admin_only) { + $new_args = $task->do($args); + if (isset($new_args)) { + $args = $new_args; + } + } } } + /** - * This function is required to order the tasks by their priorities + * This function is required to order the tasks by their priorities. * * @param Task $a the first task * @param Task $b the second task * * @return 1 if a>b, -1 if not * - * @access private * @since Method available since Release 3.0.0 - */ + */ private function compareTasks(Task $a, Task $b) { - if ($a->priority == $b->priority) + if ($a->priority == $b->priority) { return 0; + } + return ($a->priority < $b->priority) ? -1 : 1; } -} \ No newline at end of file +} diff --git a/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php b/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php index cc5fe1a..df388e0 100755 --- a/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php +++ b/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php @@ -6,47 +6,43 @@ use Aeria\Container\Container; use Aeria\Kernel\Kernel; use Aeria\Config\Config; -use Aeria\PostType\PostType; -use Aeria\Taxonomy\Taxonomy; use Aeria\Kernel\Loader; -use Aeria\Kernel\Tasks\{ - CreateAdminScripts, - CreateControllers, - CreateField, - CreateMeta, - CreateOptions, - CreatePostType, - CreateRenderer, - CreateRouter, - CreateTaxonomy, - CreateUpdater -}; +use Aeria\Kernel\Tasks\CreateAdminScripts; +use Aeria\Kernel\Tasks\CreateConfig; +use Aeria\Kernel\Tasks\CreateControllers; +use Aeria\Kernel\Tasks\CreateField; +use Aeria\Kernel\Tasks\CreateMeta; +use Aeria\Kernel\Tasks\CreateOptions; +use Aeria\Kernel\Tasks\CreatePostType; +use Aeria\Kernel\Tasks\CreateRenderer; +use Aeria\Kernel\Tasks\CreateRouter; +use Aeria\Kernel\Tasks\CreateTaxonomy; +use Aeria\Kernel\Tasks\CreateUpdater; /** - * KernelServiceProvider is in charge of registering the Kernel to the container + * KernelServiceProvider is in charge of registering the Kernel to the container. * * @category Kernel - * @package Aeria + * * @author Jacopo Martinelli * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license - * @link https://github.com/caffeinalab/aeria + * + * @see https://github.com/caffeinalab/aeria */ class KernelServiceProvider implements ServiceProviderInterface { /** - * Registers the service to the provided container, as a singleton + * Registers the service to the provided container, as a singleton. * * @param Container $container Aeria's container * - * @return void - * - * @access public * @since Method available since Release 3.0.0 */ public function register(Container $container) { $container->singleton('kernel', Kernel::class); } + /** * In charge of booting the service. It loads the config, * then registers the tasks to the kernel. Finally, it boots the @@ -56,7 +52,6 @@ public function register(Container $container) * * @return bool true: service booted * - * @access public * @since Method available since Release 3.0.0 */ public function boot(Container $container): bool @@ -65,6 +60,7 @@ public function boot(Container $container): bool $config = $container->make('config'); Loader::loadConfig($config, $container); $kernel->register(new CreateAdminScripts()); + $kernel->register(new CreateConfig()); $kernel->register(new CreateControllers()); $kernel->register(new CreateField()); $kernel->register(new CreateMeta()); @@ -76,6 +72,7 @@ public function boot(Container $container): bool $kernel->register(new CreateUpdater()); $kernel->boot($container); do_action('aeria_booted'); + return true; } } diff --git a/Aeria/Kernel/Tasks/CreateConfig.php b/Aeria/Kernel/Tasks/CreateConfig.php new file mode 100644 index 0000000..3137394 --- /dev/null +++ b/Aeria/Kernel/Tasks/CreateConfig.php @@ -0,0 +1,86 @@ + + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * + * @see https://github.com/caffeinalab/aeria + */ +class CreateConfig extends Task +{ + public $priority = 2; + public $admin_only = false; + + /** + * The main task method. It registers the fields to the field service. + * + * @param array $args the arguments to be passed to the Task + * + * @since Method available since Release 3.0.17 + */ + public function do(array $args) + { + $config = $args['container']->make('config')->all(); + $args['config'] = $this->manipulateConfig($config); + $args['config'] = $this->checkSectionIds($args['config']); + + return $args; + } + + private function checkSectionIds($tree) + { + foreach ($tree as $key => $value) { + $tree[$key]['id'] = $key; + } + + return $tree; + } + + private function manipulateConfig($tree) + { + foreach ($tree as $key => $value) { + if (is_array($tree[$key])) { + $tree[$key] = $this->manipulateConfig($tree[$key]); + } + if ($key === 'section') { + $tree[$key] = $this->checkSectionIds($tree[$key]); + } + if ($key === 'fields') { + foreach ($tree[$key] as $fieldKey => $field_config) { + $tree[$key][$fieldKey] = $this->getRealFields($field_config); + } + } + } + + return $tree; + } + + private function getRealFields($field_config) + { + $fields_registry = aeria('field'); + if (isset($field_config['fields'])) { + $field_config['fields'] = $this->getRealFields($field_config['fields']); + } + if (!isset($field_config['type'])) { + return $field_config; + } + $type = $field_config['type']; + if (!$fields_registry->exists($type)) { + return $field_config; + } + $field_type_class = $fields_registry->get($type); + $new_field_config = is_array($field_config) + ? $field_type_class::transformConfig($field_config) + : $field_config; + + return $new_field_config; + } +} diff --git a/Aeria/Kernel/Tasks/CreateField.php b/Aeria/Kernel/Tasks/CreateField.php index 3cdd43a..fdd5a30 100644 --- a/Aeria/Kernel/Tasks/CreateField.php +++ b/Aeria/Kernel/Tasks/CreateField.php @@ -3,27 +3,27 @@ namespace Aeria\Kernel\Tasks; use Aeria\Kernel\AbstractClasses\Task; + /** * This task is in charge of creating fields. * * @category Kernel - * @package Aeria + * * @author Simone Montali * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license - * @link https://github.com/caffeinalab/aeria + * + * @see https://github.com/caffeinalab/aeria */ class CreateField extends Task { - public $priority = 2; + public $priority = 1; public $admin_only = false; + /** * The main task method. It registers the fields to the field service. * * @param array $args the arguments to be passed to the Task * - * @return void - * - * @access public * @since Method available since Release 3.0.0 */ public function do(array $args) @@ -52,8 +52,6 @@ public function do(array $args) $args['service']['field']->register('url', \Aeria\Field\Fields\BaseField::class); $args['service']['field']->register('date', \Aeria\Field\Fields\BaseField::class); - do_action('aeria_register_field', $args['service']['field'], $args['container']); } - } diff --git a/Aeria/helpers.php b/Aeria/helpers.php index 79168fb..9c053ec 100755 --- a/Aeria/helpers.php +++ b/Aeria/helpers.php @@ -1,9 +1,7 @@ exists($type)) { - return $config; - } - $field_type_class = $fields_registry->get($type); - $new_config = is_array($config) - ? $field_type_class::transformConfig($config) - : $config; - - return $new_config; - } - - /** - * Applies config transformation on list a meta field configuration. - * - * @param array $config a list of field config - * - * @return array the transformed list of config - */ - function transform_aeria_meta_config_list(array $configs) - { - foreach ($configs as $index => $config) { - $configs[$index] = transform_aeria_meta_config($config); - } - - return $configs; - } - - /** - * Applies config transformation on a list of section definitions. - * - * @param array $config a list of section definitions - * - * @return array the transformed list of section definitions - */ - function transform_aeria_sections_definitions(array $configs) - { - foreach ($configs as $index => $config) { - $configs[$index]['fields'] = transform_aeria_meta_config_list($config['fields']); - } - - return $configs; - } - /** * Flattens an array. * diff --git a/Resources/Templates/MetaTemplate.php b/Resources/Templates/MetaTemplate.php index ccd6176..5589fd2 100644 --- a/Resources/Templates/MetaTemplate.php +++ b/Resources/Templates/MetaTemplate.php @@ -1,7 +1,9 @@ -
- +
+
+ +
diff --git a/Resources/Templates/OptionTemplate.php b/Resources/Templates/OptionTemplate.php index 07226b1..f454989 100644 --- a/Resources/Templates/OptionTemplate.php +++ b/Resources/Templates/OptionTemplate.php @@ -1,12 +1,14 @@ -

+

-
" class="aeriaApp"> - +
+
+ +
diff --git a/Resources/Templates/SectionEncoderTemplate.php b/Resources/Templates/SectionEncoderTemplate.php index 1a82717..f45816d 100644 --- a/Resources/Templates/SectionEncoderTemplate.php +++ b/Resources/Templates/SectionEncoderTemplate.php @@ -1,3 +1,3 @@ diff --git a/aeria.php b/aeria.php index f7550bc..e4e6e44 100755 --- a/aeria.php +++ b/aeria.php @@ -11,7 +11,7 @@ * Plugin Name: Aeria * Plugin URI: https://github.com/caffeinalab/aeria * Description: Aeria is a modular, lightweight, fast WordPress Application development kit. - * Version: 3.0.17 + * Version: 3.0.18 * Author: Caffeina * Author URI: https://caffeina.com * Text Domain: aeria diff --git a/vendor/autoload.php b/vendor/autoload.php index 621ff20..0ff7f4a 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitfceaec5a919c74e81bdeb7d4cf8f444e::getLoader(); +return ComposerAutoloaderInit90e03e2dfe985392e1653de22bc948ce::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 5d3065c..01f73ad 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitfceaec5a919c74e81bdeb7d4cf8f444e +class ComposerAutoloaderInit90e03e2dfe985392e1653de22bc948ce { private static $loader; @@ -19,15 +19,15 @@ public static function getLoader() return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitfceaec5a919c74e81bdeb7d4cf8f444e', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit90e03e2dfe985392e1653de22bc948ce', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInitfceaec5a919c74e81bdeb7d4cf8f444e', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit90e03e2dfe985392e1653de22bc948ce', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitfceaec5a919c74e81bdeb7d4cf8f444e::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit90e03e2dfe985392e1653de22bc948ce::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ public static function getLoader() $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitfceaec5a919c74e81bdeb7d4cf8f444e::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit90e03e2dfe985392e1653de22bc948ce::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequirefceaec5a919c74e81bdeb7d4cf8f444e($fileIdentifier, $file); + composerRequire90e03e2dfe985392e1653de22bc948ce($fileIdentifier, $file); } return $loader; } } -function composerRequirefceaec5a919c74e81bdeb7d4cf8f444e($fileIdentifier, $file) +function composerRequire90e03e2dfe985392e1653de22bc948ce($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 19bf6d4..170e122 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitfceaec5a919c74e81bdeb7d4cf8f444e +class ComposerStaticInit90e03e2dfe985392e1653de22bc948ce { public static $files = array ( 'd675c376038c78b0d320f3c784804a3c' => __DIR__ . '/../..' . '/Aeria/helpers.php', @@ -27,8 +27,8 @@ class ComposerStaticInitfceaec5a919c74e81bdeb7d4cf8f444e public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitfceaec5a919c74e81bdeb7d4cf8f444e::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitfceaec5a919c74e81bdeb7d4cf8f444e::$prefixDirsPsr4; + $loader->prefixLengthsPsr4 = ComposerStaticInit90e03e2dfe985392e1653de22bc948ce::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit90e03e2dfe985392e1653de22bc948ce::$prefixDirsPsr4; }, null, ClassLoader::class); }