diff --git a/Aeria/Action/ActionDispatcher.php b/Aeria/Action/ActionDispatcher.php index c48ea99..04cb20a 100644 --- a/Aeria/Action/ActionDispatcher.php +++ b/Aeria/Action/ActionDispatcher.php @@ -6,15 +6,42 @@ use Aeria\Action\Traits\ListManagerTrait; use Aeria\Container\Container; +/** + * ActionDispatcher is in charge of registering Actions to WP + * + * @category Action + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ActionDispatcher { use ListManagerTrait; - + /** + * Registers a new Action to the list + * + * @param ActionInterface $action the new action + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(ActionInterface $action) { $this->push($action); } - + /** + * Dispatches the saved actions to WP + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function dispatch(Container $container) { foreach ($this->list() as $action) { diff --git a/Aeria/Action/Actions/AdminEnqueueScripts.php b/Aeria/Action/Actions/AdminEnqueueScripts.php index 2429283..7990619 100644 --- a/Aeria/Action/Actions/AdminEnqueueScripts.php +++ b/Aeria/Action/Actions/AdminEnqueueScripts.php @@ -6,21 +6,54 @@ use Aeria\Action\Interfaces\ActionInterface; use Aeria\Action\Traits\ListManagerTrait; use Aeria\Container\Container; - +/** + * AdminEnqueueScripts is in charge of enqueuing scripts to WP + * + * @category Action + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class AdminEnqueueScripts implements ActionInterface { use ListManagerTrait; - + /** + * Returns the type + * + * @return string the type = 'admin_enqueue_scripts' + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getType(): string { return 'admin_enqueue_scripts'; } - + /** + * Registers a new Enqueuer + * + * @param EnqueuerInterface $enqueuer the new enqueuer + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(EnqueuerInterface $enqueuer) { $this->push($enqueuer); } - + /** + * Dispatches the enqueuers + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function dispatch(Container $container) { wp_enqueue_editor(); diff --git a/Aeria/Action/Enqueuers/ScriptsEnqueuer.php b/Aeria/Action/Enqueuers/ScriptsEnqueuer.php index 786b019..d95f521 100644 --- a/Aeria/Action/Enqueuers/ScriptsEnqueuer.php +++ b/Aeria/Action/Enqueuers/ScriptsEnqueuer.php @@ -6,6 +6,15 @@ use Aeria\Container\Container; use Closure; +/** + * ScriptsEnqueuer is in charge of enqueuing scripts to WP + * + * @category Action + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ScriptsEnqueuer implements EnqueuerInterface { @@ -14,7 +23,21 @@ class ScriptsEnqueuer implements EnqueuerInterface protected $deps; protected $ver; protected $in_footer; - + /** + * Constructs the ScriptsEnqueuer object + * + * @param string $name the handle + * @param string $path the scripts path + * @param array $deps the script dependencies + * @param string|bool|null $ver the script version number + * @param bool $in_footer whether the script has to be in + * the head, or footer + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct( string $name, string $path, @@ -28,7 +51,16 @@ public function __construct( $this->ver = $ver; $this->in_footer = $in_footer; } - + /** + * Constructs the ScriptsEnqueuer object + * + * @param Container $container Aeria's container + * + * @return Closure the script enqueuer + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getEnqClosure(Container $container): Closure { $name = $this->name; diff --git a/Aeria/Action/Interfaces/ActionInterface.php b/Aeria/Action/Interfaces/ActionInterface.php index 2d7ac41..c04abad 100644 --- a/Aeria/Action/Interfaces/ActionInterface.php +++ b/Aeria/Action/Interfaces/ActionInterface.php @@ -5,9 +5,46 @@ use Aeria\Action\Interfaces\EnqueuerInterface; use Aeria\Container\Container; +/** + * ActionInterface describes an Action class + * + * @category Action + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface ActionInterface { + /** + * Returns the type + * + * @return string the type + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getType(): string; + /** + * Registers a new Enqueuer + * + * @param EnqueuerInterface $enqueuer the new enqueuer + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(EnqueuerInterface $enqueuer); + /** + * Dispatches the enqueuers + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function dispatch(Container $container); } diff --git a/Aeria/Action/Interfaces/EnqueuerInterface.php b/Aeria/Action/Interfaces/EnqueuerInterface.php index 13275ee..18b6501 100644 --- a/Aeria/Action/Interfaces/EnqueuerInterface.php +++ b/Aeria/Action/Interfaces/EnqueuerInterface.php @@ -4,7 +4,27 @@ use Aeria\Container\Container; use Closure; + +/** + * ActionInterface describes an Enqueuer class + * + * @category Action + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface EnqueuerInterface { + /** + * Constructs the ScriptsEnqueuer object + * + * @param Container $container Aeria's container + * + * @return Closure the script enqueuer + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getEnqClosure(Container $container): Closure; } diff --git a/Aeria/Action/ServiceProviders/ActionProvider.php b/Aeria/Action/ServiceProviders/ActionProvider.php index 72050d6..ed4cedb 100644 --- a/Aeria/Action/ServiceProviders/ActionProvider.php +++ b/Aeria/Action/ServiceProviders/ActionProvider.php @@ -8,13 +8,42 @@ use Aeria\Action\Enqueuers\ScriptsEnqueuer; use Aeria\Action\Actions\AdminEnqueueScripts as AdminEnqueueScriptsAction; +/** + * ActionProvider is in charge of registering the Action service + * to the container + * + * @category Action + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ActionProvider implements ServiceProviderInterface { + /** + * 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('action', ActionDispatcher::class); } - + /** + * In charge of booting the service. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { $dispatcher = $container->make('action'); diff --git a/Aeria/Action/Traits/ListManagerTrait.php b/Aeria/Action/Traits/ListManagerTrait.php index cbfb6ac..26bed06 100644 --- a/Aeria/Action/Traits/ListManagerTrait.php +++ b/Aeria/Action/Traits/ListManagerTrait.php @@ -2,21 +2,53 @@ namespace Aeria\Action\Traits; +/** + * ListManagerTrait makes a class able to manage a list + * + * @category Action + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ trait ListManagerTrait { protected $list; - + /** + * Constructs the list + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct() { $this->list = []; } - + /** + * Pushes an element to the list + * + * @param mixed $elem the element to add + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function push($elem) { $this->list[] = $elem; } - + /** + * Returns the full list + * + * @return array the list + * + * @access public + * @since Method available since Release 3.0.0 + */ public function list(): array { return $this->list; diff --git a/Aeria/Aeria.php b/Aeria/Aeria.php index 1336e90..5bbaf66 100755 --- a/Aeria/Aeria.php +++ b/Aeria/Aeria.php @@ -22,17 +22,39 @@ use Aeria\Router\ServiceProviders\ControllerServiceProvider; use Aeria\RenderEngine\ServiceProviders\RenderEngineServiceProvider; - +/** + * Aeria is a lightweight and modular WP development tool. + * + * @category Action + * @package Aeria + * @author Caffeina Devs + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Aeria extends Container { - public const VERSION = '3.0.2'; - + public const VERSION = '3.0.3'; + /** + * Constructs the Aeria container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct() { $this->registerBindings(); $this->registerServiceProviders(); } - + /** + * Registers Aeria's bindings + * + * @return void + * + * @access protected + * @since Method available since Release 3.0.0 + */ protected function registerBindings() { static::setInstance($this); @@ -41,7 +63,14 @@ protected function registerBindings() $this->bind(Container::class, $this); } - + /** + * Registers all the required ServiceProviders to the container + * + * @return void + * + * @access protected + * @since Method available since Release 3.0.0 + */ protected function registerServiceProviders() // : void { $this->register(new ConfigProvider()); @@ -59,12 +88,27 @@ protected function registerServiceProviders() // : void $this->register(new OptionsPageServiceProvider()); $this->register(new RenderEngineServiceProvider()); } - + /** + * Returns Aeria's version + * + * @return string the version + * + * @access public + * @since Method available since Release 3.0.0 + */ public function version() : string { return static::VERSION; } - + /** + * Returns Aeria's instance + * + * @return Aeria the instance + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getInstance() : ContainerInterface { if (is_null(static::$instance)) { @@ -73,7 +117,17 @@ public static function getInstance() : ContainerInterface return static::$instance; } - + /** + * Sets Aeria's instance + * + * @param ContainerInterface $container the container + * + * @return ContainerInterface the instance we've set + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function setInstance( ContainerInterface $container ) : ContainerInterface { diff --git a/Aeria/Config/Config.php b/Aeria/Config/Config.php index 0b03c71..1f46194 100755 --- a/Aeria/Config/Config.php +++ b/Aeria/Config/Config.php @@ -15,7 +15,15 @@ DriverException, InvalidNamespaceException }; - +/** + * Config is the class in charge of parsing configuration files from your theme. + * + * @category Config + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Config implements ExtensibleInterface, JsonSerializable, ValidateConfInterface { use ExtensibleTrait; @@ -25,16 +33,35 @@ class Config implements ExtensibleInterface, JsonSerializable, ValidateConfInter use ValidateConfTrait; protected $drivers = []; - protected $root_path = ''; + protected $root_paths = []; protected $active_driver = 'json'; private $_kind; - + /** + * Constructs the Config singleton + * + * We're adding the theme folder aeria-config, and the folder in resources. + * Both contain configuration files for Aeria. + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct() { $this->instanciateDictionary(); - $this->root_path = get_template_directory() . '/aeria-config'; + $this->root_paths[] = get_template_directory() . '/aeria-config'; + $this->root_paths[] = WP_PLUGIN_DIR.'/aeria/resources/Config'; } - + /** + * Returns the validation array + * + * The returned array contains the validators we need in the config. + * It is structured as the config files. + * + * @return array the validators array + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getValidationStructure() : array { switch ($this->_kind){ @@ -99,13 +126,21 @@ public function getValidationStructure() : array break; case 'taxonomy': $spec = [ - 'label' => $this->makeRegExValidator( - "/^.{1,30}$/" - ), - 'labels' => function ($value) { + 'args' => [ + 'label' => $this->makeRegExValidator( + "/^.{1,30}$/" + ), + 'labels' => function ($value) { + return [ + 'result' => is_array($value), + 'message' => 'labels should be an array' + ]; + } + ], + 'object_type' => function ($value) { return [ 'result' => is_array($value), - 'message' => 'labels should be an array' + 'message' => 'object_type should be an array' ]; } ]; @@ -137,17 +172,12 @@ public function getValidationStructure() : array ]; break; case 'route': - $spec = [ - 'path' => $this->makeRegExValidator( - "/^[a-z0-9_-]{1,20}$/" - ), - 'method' => $this->makeRegExValidator( - "/^POST|GET|PUT|DELETE$/" - ), - 'handler' => $this->makeRegExValidator( - "/^[a-z0-9_-]{1,50}$/" - ) - ]; + $spec = function ($value) { + return [ + 'result' => is_array($value), + 'message' => 'spec should be an array' + ]; + }; break; case 'options': $spec = [ @@ -182,20 +212,58 @@ public function getValidationStructure() : array 'spec' => $spec, 'kind' => $this->makeRegExValidator( "/^post-type|taxonomy|meta|section|controller|route|options$/" - ) + ), + 'enabled' => function ($value) { + return [ + 'result' => is_bool($value), + 'message' => 'enabled should be a boolean' + ]; + } ]; } - + /** + * Returns the needed loader name. + * + * @param string $driver_name the driver's name + * + * @return string the loader method name + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getLoaderMethod($driver_name) { return 'load' . ucwords($driver_name); } - + /** + * Returns the needed parser name. + * + * @param string $driver_name the driver's name + * + * @return string the parser method name + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getParserMethod($driver_name) { return 'parse' . ucwords($driver_name); } - + /** + * Registers a driver in the Config Loader. + * + * @param DriverInterface $driver the driver's object + * @param bool $is_selected whether $driver is the active one + * + * @return bool the driver was succesfully added + * @throws InvalidNamespaceException when the namespace interfers with Aeria + * @throws DriverException the adding of the driver fails + * + * @access public + * @since Method available since Release 3.0.0 + */ public function addDriver(DriverInterface $driver, bool $is_selected = false) : bool { $driver_name = $driver->getDriverName(); @@ -237,7 +305,19 @@ function (array $data, ?string $namespace = 'aeria') use ($driver) { return $extend_result_parser && $extend_result_driver; } - + /** + * Returns the namespace mapped list + * + * @param string $namespace the namespace + * @param string $separator the namespace separator + * @param array $element the inital element for reduce + * + * @return array the mapped list + * + * @access protected + * @static + * @since Method available since Release 3.0.0 + */ protected static function createNamespaceTree( string $namespace, string $separator, @@ -254,7 +334,16 @@ protected static function createNamespaceTree( ); return $mappedList; } - + /** + * Checks validity of standard configurations + * + * @param array $data the configuration + * + * @return bool whether the configuration is valid + * + * @access public + * @since Method available since Release 3.0.0 + */ public function isValidStandardConfiguration($data) { $this->_kind = $data['kind']; @@ -263,7 +352,16 @@ public function isValidStandardConfiguration($data) throw $exeption; } } - + /** + * Adds an array of drivers. + * + * @param array $drivers the additional drivers + * + * @return bool whether the drivers were successfully added. + * + * @access public + * @since Method available since Release 3.0.0 + */ public function addDrivers(array $drivers) : bool { $result = true; @@ -272,30 +370,72 @@ public function addDrivers(array $drivers) : bool } return $result; } - + /** + * Loads an array of configs + * + * @param array $array the configs + * + * @return bool whether the loading was successful + * + * @access public + * @since Method available since Release 3.0.0 + */ public function loadArray(array $array) : bool { return $this->merge($array); } - + /** + * Returns the saved drivers. + * + * @return array the saved drivers + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getDrivers() : array { return $this->drivers; } - - public function getRootPath() : string + /** + * Returns the saved root paths + * + * @return array the root paths + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getRootPath() : array { - return $this->root_path; + return $this->root_paths; } - + /** + * Adds a root path + * + * @param string $root_path the additional path + * + * @return void + * @throws Exception when $root_path is not a directory + * + * @access public + * @since Method available since Release 3.0.0 + */ public function setRootPath(string $root_path) { if (!is_dir($root_path)) { throw new Exception("{$root_path} is not a directory"); } - $this->root_path = $root_path; + $this->root_paths[] = $root_path; } - + /** + * Gets the current driver or the requested one + * + * @param string $file_name The requested driver + * + * @return string the driver name + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getDriverInUse(string $file_name = null) : string { if (!is_null($file_name)) { @@ -305,7 +445,17 @@ public function getDriverInUse(string $file_name = null) : string } return $this->active_driver; } - + /** + * Gets a driver name from a file extension + * + * @param string $ext the file extension + * + * @return string the driver name + * @throws DriverException when there's no available driver + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getDriverNameFromExtension(string $ext): string { if (isset($this->drivers[$ext])) { diff --git a/Aeria/Config/Drivers/ENVDriver.php b/Aeria/Config/Drivers/ENVDriver.php index d1b7d45..06bb2c2 100755 --- a/Aeria/Config/Drivers/ENVDriver.php +++ b/Aeria/Config/Drivers/ENVDriver.php @@ -3,23 +3,47 @@ namespace Aeria\Config\Drivers; use Aeria\Config\Interfaces\DriverInterface; - +/** + * ENVDriver is a driver for .env files + * + * @category Config + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ENVDriver implements DriverInterface { protected const FILE_FLAGS = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; public $driver_name = 'env'; - + /** + * Return this driver's name + * + * @return string the driver name + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getDriverName() : string { return $this->driver_name; } - + /** + * Parse the requested file + * + * @param string $env_file_path the file path + * + * @return array the parsed file + * + * @access public + * @since Method available since Release 3.0.0 + */ public function parse(string $env_file_path) : array { $result = []; - foreach($this->fileLinesGenerator($env_file_path) as $key => $value) { + foreach ($this->fileLinesGenerator($env_file_path) as $key => $value) { $key = $this->cleanKey($key); $value = $this->cleanValue($value); @@ -29,7 +53,16 @@ public function parse(string $env_file_path) : array return $result; } - + /** + * Parse the requested file + * + * @param string $file_path the file path + * + * @return array the parsed file + * + * @access public + * @since Method available since Release 3.0.0 + */ protected function fileLinesGenerator(string $file_path) : Iterable { foreach(file($dir, static::FILE_FLAGS) as $line) { $line = trim($line); diff --git a/Aeria/Config/Drivers/INIDriver.php b/Aeria/Config/Drivers/INIDriver.php index 549493f..da69e47 100755 --- a/Aeria/Config/Drivers/INIDriver.php +++ b/Aeria/Config/Drivers/INIDriver.php @@ -4,21 +4,45 @@ use Aeria\Config\Interfaces\DriverInterface; use Aeria\Config\Exceptions\DecodeException; - +/** + * INIDriver is a driver for .ini files + * + * @category Config + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class INIDriver implements DriverInterface { public $driver_name = 'ini'; - + /** + * Return this driver's name + * + * @return string the driver name + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getDriverName() : string { return $this->driver_name; } - + /** + * Parse the requested file + * + * @param string $ini_file_path the file path + * + * @return array the parsed file + * + * @access public + * @since Method available since Release 3.0.0 + */ public function parse(string $ini_file_path) : array { $result = parse_ini_file($ini_file_path, true); - if (false === $result) { + if (empty($result)) { throw new DecodeException(static::class . ": invalid ini file parsed by INI config driver"); } diff --git a/Aeria/Config/Drivers/JsonDriver.php b/Aeria/Config/Drivers/JsonDriver.php index 3bdbea3..9fcd52a 100755 --- a/Aeria/Config/Drivers/JsonDriver.php +++ b/Aeria/Config/Drivers/JsonDriver.php @@ -4,16 +4,40 @@ use Aeria\Config\Interfaces\DriverInterface; use Aeria\Config\Exceptions\DecodeException; - +/** + * JSONDriver is a driver for .json files + * + * @category Config + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class JsonDriver implements DriverInterface { public $driver_name = 'json'; - + /** + * Return this driver's name + * + * @return string the driver name + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getDriverName() : string { return $this->driver_name; } - + /** + * Parse the requested file + * + * @param string $json_filename the file path + * + * @return array the parsed file + * + * @access public + * @since Method available since Release 3.0.0 + */ public function parse(string $json_filename) : array { $json = file_get_contents($json_filename); diff --git a/Aeria/Config/Drivers/PHPDriver.php b/Aeria/Config/Drivers/PHPDriver.php index 4e15439..5a36298 100755 --- a/Aeria/Config/Drivers/PHPDriver.php +++ b/Aeria/Config/Drivers/PHPDriver.php @@ -4,23 +4,47 @@ use Aeria\Config\Interfaces\DriverInterface; use Aeria\Config\Exceptions\DecodeException; - +/** + * PHPDriver parses PHP configuration files + * + * @category Config + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class PHPDriver implements DriverInterface { public $driver_name = 'php'; - + /** + * Return this driver's name + * + * @return string the driver name + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getDriverName() : string { return $this->driver_name; } - + /** + * Parse the requested file + * + * @param string $php_file_path the file path + * + * @return array the parsed file + * + * @access public + * @since Method available since Release 3.0.0 + */ public function parse(string $php_file_path) : array { ob_start(); $result = include $php_file_path; ob_end_clean(); - if (is_null($result)) { + if (!is_array($result)) { throw new DecodeException(static::class . ": invalid php file parsed by PHP config driver"); } diff --git a/Aeria/Config/Exceptions/ConfigValidationException.php b/Aeria/Config/Exceptions/ConfigValidationException.php index f6c5dac..6e8f079 100755 --- a/Aeria/Config/Exceptions/ConfigValidationException.php +++ b/Aeria/Config/Exceptions/ConfigValidationException.php @@ -3,5 +3,15 @@ namespace Aeria\Config\Exceptions; use UnexpectedValueException; - -class ConfigValidationException extends UnexpectedValueException {} \ No newline at end of file +/** + * ConfigValidationException gets thrown when a config isn't valid + * + * @category Field + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class ConfigValidationException extends UnexpectedValueException +{ +} \ No newline at end of file diff --git a/Aeria/Config/Exceptions/DecodeException.php b/Aeria/Config/Exceptions/DecodeException.php index 74d5f2a..eb96ef9 100755 --- a/Aeria/Config/Exceptions/DecodeException.php +++ b/Aeria/Config/Exceptions/DecodeException.php @@ -3,5 +3,15 @@ namespace Aeria\Config\Exceptions; use UnexpectedValueException; - -class DecodeException extends UnexpectedValueException {} \ No newline at end of file +/** + * DecodeException gets thrown when a decode fails + * + * @category Field + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class DecodeException extends UnexpectedValueException +{ +} \ No newline at end of file diff --git a/Aeria/Config/Exceptions/DriverException.php b/Aeria/Config/Exceptions/DriverException.php index f67f64f..c12c1a3 100755 --- a/Aeria/Config/Exceptions/DriverException.php +++ b/Aeria/Config/Exceptions/DriverException.php @@ -3,5 +3,15 @@ namespace Aeria\Config\Exceptions; use Exception; - -class DriverException extends Exception {} \ No newline at end of file +/** + * DriverException gets thrown when the requested driver is not available + * + * @category Field + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class DriverException extends Exception +{ +} \ No newline at end of file diff --git a/Aeria/Config/Exceptions/InvalidNamespaceException.php b/Aeria/Config/Exceptions/InvalidNamespaceException.php index 822136e..421fb16 100755 --- a/Aeria/Config/Exceptions/InvalidNamespaceException.php +++ b/Aeria/Config/Exceptions/InvalidNamespaceException.php @@ -3,5 +3,15 @@ namespace Aeria\Config\Exceptions; use UnexpectedValueException; - -class InvalidNamespaceException extends UnexpectedValueException {} \ No newline at end of file +/** + * InvalidNamespaceException gets thrown when a namespace isn't valid + * + * @category Field + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class InvalidNamespaceException extends UnexpectedValueException +{ +} \ No newline at end of file diff --git a/Aeria/Config/Exceptions/NoCallableArgumentException.php b/Aeria/Config/Exceptions/NoCallableArgumentException.php index ec07eb5..6624bc6 100755 --- a/Aeria/Config/Exceptions/NoCallableArgumentException.php +++ b/Aeria/Config/Exceptions/NoCallableArgumentException.php @@ -3,5 +3,16 @@ namespace Aeria\Config\Exceptions; use UnexpectedValueException; - -class NoCallableArgumentException extends UnexpectedValueException {} \ No newline at end of file +/** + * NoCallableArgumentException gets thrown when a declared + * callable isn't actually a callable + * + * @category Field + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class NoCallableArgumentException extends UnexpectedValueException +{ +} \ No newline at end of file diff --git a/Aeria/Config/Interfaces/DriverInterface.php b/Aeria/Config/Interfaces/DriverInterface.php index 333f429..9783bf8 100755 --- a/Aeria/Config/Interfaces/DriverInterface.php +++ b/Aeria/Config/Interfaces/DriverInterface.php @@ -1,9 +1,35 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface DriverInterface { - public function parse(string $path) : array; - public function getDriverName() : string; + /** + * Parse the requested file + * + * @param string $path the file path + * + * @return array the parsed file + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function parse(string $path) : array; + /** + * Return this driver's name + * + * @return string the driver name + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getDriverName() : string; } \ No newline at end of file diff --git a/Aeria/Config/ServiceProviders/ConfigProvider.php b/Aeria/Config/ServiceProviders/ConfigProvider.php index 4bb0f77..953d0b4 100755 --- a/Aeria/Config/ServiceProviders/ConfigProvider.php +++ b/Aeria/Config/ServiceProviders/ConfigProvider.php @@ -13,10 +13,27 @@ ENVDriver, INIDriver }; - +/** + * ConfigProvider is in charge of registering the Config singleton to the container + * + * @category Config + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ConfigProvider implements ServiceProviderInterface { - + /** + * 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('config', Config::class); @@ -34,7 +51,16 @@ public function register(Container $container) ] ); } - + /** + * In charge of booting the service. Config doesn't need any additional operation + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { return true; diff --git a/Aeria/Config/Traits/ValidateConfTrait.php b/Aeria/Config/Traits/ValidateConfTrait.php index 2cae477..e406531 100755 --- a/Aeria/Config/Traits/ValidateConfTrait.php +++ b/Aeria/Config/Traits/ValidateConfTrait.php @@ -6,10 +6,27 @@ use Aeria\Config\Exceptions\NoCallableArgumentException; use Closure; -// TODO: Rifattorizzare come una classe +/** + * ValidateConfTrait allows a class to validate configurations + * + * @category Config + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ trait ValidateConfTrait { - + /** + * Checks if the passed configuration is valid + * + * @param array $to_validate the validatable configuration + * + * @return null|Exception null if the validation was ok + * + * @access public + * @since Method available since Release 3.0.0 + */ public function isValid(array $to_validate = []) { $message = static::validateStructure( @@ -18,7 +35,16 @@ public function isValid(array $to_validate = []) ); return is_null($message) ? null : new ConfigValidationException($message); } - + /** + * Combines validators with an OR condition + * + * @param array ...$args the required validators + * + * @return Closure the multiple validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function combineOrValidator(...$args) : Closure { foreach ($args as $func) { @@ -48,7 +74,16 @@ function ($acc, $func) use ($value) { ); }; } - + /** + * Combines validators with an AND condition + * + * @param array ...$args the required validators + * + * @return Closure the multiple validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function combineAndValidator(...$args) : Closure { foreach ($args as $func) { @@ -78,7 +113,14 @@ function ($acc, $func) use ($value) { ); }; } - + /** + * Returns an array validator + * + * @return Closure the isArray validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeIsArrayValidator() : Closure { return function ($value) { @@ -94,7 +136,16 @@ public function makeIsArrayValidator() : Closure } }; } - + /** + * Returns a string comparator + * + * @param string $string_value the string to be compared to + * + * @return Closure the string validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeIsEqualToValidator(string $string_value) { return function ($value) { @@ -117,7 +168,16 @@ public function makeIsEqualToValidator(string $string_value) } }; } - + /** + * Returns a RegEx validator + * + * @param string $regEx the regEx to validate with + * + * @return Closure the RegEx validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeRegExValidator(string $regEx) : Closure { return function ($value) use ($regEx) { @@ -134,7 +194,14 @@ public function makeRegExValidator(string $regEx) : Closure } }; } - + /** + * Returns a boolean validator, valid if true + * + * @return Closure the truthness validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeTruthyValidator() : Closure { return function ($value) { @@ -150,7 +217,14 @@ public function makeTruthyValidator() : Closure } }; } - + /** + * Returns a boolean validator, valid if false + * + * @return Closure the falseness validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeFalselyValidator() : Closure { return function ($value) { @@ -166,7 +240,16 @@ public function makeFalselyValidator() : Closure } }; } - + /** + * Returns a custom validator + * + * @param func $validator the function to validate with + * + * @return Closure the custom validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeCustomValidator(func $validator): Closure { return function ($value) { @@ -183,7 +266,18 @@ public function makeCustomValidator(func $validator): Closure } }; } - + /** + * Validates a structure of validators vs. an array + * + * @param array $validation_structure the validation structure + * @param array $array_to_validate the array to validate + * + * @return null|string null if valid, string with the error if not + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function validateStructure( array $validation_structure, array $array_to_validate @@ -199,31 +293,42 @@ public static function validateStructure( $key ); } - if (!is_null($error)) { - return $error; - } - + if (!is_null($error)) { + return $error; + } } } return null; } - - private static function handleClosure($elementToValidate, $closure, $key) + /** + * Validates a single element + * + * @param mixed $element_to_validate the element we want to validate + * @param Closure $closure the function to validate the element with + * @param string $key the element's key + * + * @return Closure the RegEx validator + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + private static function handleClosure($element_to_validate, $closure, $key) { - if (is_null($elementToValidate)) { + if (is_null($element_to_validate)) { return "key:{$key} is null"; } - if (is_array($closure) && is_array($elementToValidate)) { + if (is_array($closure) && is_array($element_to_validate)) { $rec_valid = static::validateStructure( $closure, - $elementToValidate + $element_to_validate ); if (!is_null($rec_valid)) { return $rec_valid; } } if (is_callable($closure)) { - $is_valid = $closure($elementToValidate); + $is_valid = $closure($element_to_validate); if (!$is_valid['result']) { return "key:{$key} is not valid, {$is_valid['message']}"; } diff --git a/Aeria/Container/Container.php b/Aeria/Container/Container.php index a4a8df2..1224d12 100755 --- a/Aeria/Container/Container.php +++ b/Aeria/Container/Container.php @@ -12,7 +12,15 @@ UnknownServiceException, ServiceAlreadyBoundException }; - +/** + * Container contains all of Aeria's services + * + * @category Container + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Container implements ContainerInterface { protected static $instance; @@ -22,12 +30,34 @@ class Container implements ContainerInterface private $keys = []; private $cache = []; private $providers = []; - + /** + * Checks whether a service exists in the container + * + * @param string $id the searched service ID + * + * @return bool whether the container has the service or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function has(string $id) : bool { return isset($this->keys[$id]); } - + /** + * Binds a service to the container + * + * @param string $abstract the "slug" we wanna refer the service as + * @param mixed $element the element we want to bind + * @param bool $shared whether the service is a singleton + * + * @return bool true if the binding was successful + * @throws ServiceAlreadyBoundException if the service was already bound + * in this container + * + * @access public + * @since Method available since Release 3.0.0 + */ public function bind( string $abstract, $element = null, @@ -46,14 +76,33 @@ public function bind( return true; } - + /** + * Binds a singleton to the container + * + * @param string $abstract the "slug" we wanna refer the service to + * @param mixed $element the element we want to bind + * + * @return bool whether the container has the service or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function singleton(string $abstract, $element = null) : bool { $result = $this->bind($abstract, $element, true); return $result; } - + /** + * Returns a service + * + * @param string $abstract the "slug" we refer the service to + * + * @return mixed the requested service + * + * @access public + * @since Method available since Release 3.0.0 + */ public function make(string $abstract) // : mixed { if (!$this->has($abstract)) { @@ -78,7 +127,16 @@ public function make(string $abstract) // : mixed return $this->cache[$abstract]; } - + /** + * Resolves a service + * + * @param mixed $service the service we want to resolve + * + * @return mixed the callable result, or the service + * + * @access protected + * @since Method available since Release 3.0.0 + */ protected function resolve(/* mixed */ $service) // : mixed { if (is_callable($service)) { @@ -95,7 +153,16 @@ protected function resolve(/* mixed */ $service) // : mixed return $service; } - + /** + * Removes a service from the container + * + * @param string $abstract the "slug" we refer the service to + * + * @return bool whether the service was deleted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function remove(string $abstract) : bool { if (!$this->has($abstract)) { @@ -111,7 +178,14 @@ public function remove(string $abstract) : bool return true; } - + /** + * Flushes the container properties + * + * @return bool true if everything was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function flush() : bool { $this->services = []; @@ -120,7 +194,17 @@ public function flush() : bool $this->keys = []; return true; } - + /** + * Returns the saved service + * + * @param string $abstract the "slug" we refer the service to + * + * @return mixed the searched service + * @throws UnknownServiceException if the service wasn't found + * + * @access public + * @since Method available since Release 3.0.0 + */ public function raw(string $abstract) // : mixed { if (!$this->has($abstract)) { @@ -129,7 +213,16 @@ public function raw(string $abstract) // : mixed return $this->services[$abstract]; } - + /** + * Mutually registers the service provider and the container + * + * @param ServiceProviderInterface $provider the service provider + * + * @return ContainerInterface this container + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register( ServiceProviderInterface $provider ) : ContainerInterface { @@ -137,7 +230,14 @@ public function register( $this->providers[] = $provider; return $this; } - + /** + * Boots the container's services + * + * @return bool true if the boot was successful + * + * @access public + * @since Method available since Release 3.0.0 + */ public function bootstrap() : bool { foreach ($this->providers as $provider) { @@ -145,10 +245,4 @@ public function bootstrap() : bool } return true; } - - /* - public function extend($abstract, Closure $closure) { - return; - } - */ } diff --git a/Aeria/Container/Exceptions/ServiceAlreadyBoundException.php b/Aeria/Container/Exceptions/ServiceAlreadyBoundException.php new file mode 100755 index 0000000..51543b0 --- /dev/null +++ b/Aeria/Container/Exceptions/ServiceAlreadyBoundException.php @@ -0,0 +1,19 @@ + + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class ServiceAlreadyBoundException extends Exception +{ + +} \ No newline at end of file diff --git a/Aeria/Container/Exceptions/UnknownServiceException.php b/Aeria/Container/Exceptions/UnknownServiceException.php index 388f7eb..feac1dd 100755 --- a/Aeria/Container/Exceptions/UnknownServiceException.php +++ b/Aeria/Container/Exceptions/UnknownServiceException.php @@ -3,7 +3,15 @@ namespace Aeria\Container\Exceptions; use Exception; - +/** + * UnknownServiceException gets thrown when Aeria looks for a non-existent service + * + * @category Field + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class UnknownServiceException extends Exception { diff --git a/Aeria/Container/Interfaces/ContainerInterface.php b/Aeria/Container/Interfaces/ContainerInterface.php index 74d83be..ad37a18 100755 --- a/Aeria/Container/Interfaces/ContainerInterface.php +++ b/Aeria/Container/Interfaces/ContainerInterface.php @@ -3,32 +3,123 @@ namespace Aeria\Container\Interfaces; use Aeria\Container\Interfaces\ServiceProviderInterface; - +/** + * This interface describes a container + * + * @category Container + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface ContainerInterface { + /** + * Checks whether a service exists in the container + * + * @param string $abstract the searched service ID + * + * @return bool whether the container has the service or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function has(string $abstract) : bool; - + /** + * Binds a service to the container + * + * @param string $abstract the "slug" we wanna refer the service as + * @param mixed $element the element we want to bind + * @param bool $shared whether the service is a singleton + * + * @return bool true if the binding was successful + * @throws ServiceAlreadyBoundException if the service was already bound + * in this container + * + * @access public + * @since Method available since Release 3.0.0 + */ public function bind( string $abstract, $element = null, bool $shared = false ) : bool; - + /** + * Binds a singleton to the container + * + * @param string $abstract the "slug" we wanna refer the service to + * @param mixed $element the element we want to bind + * + * @return bool whether the container has the service or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function singleton(string $abstract, $element = null) : bool; - // public function extend(string $abstract, Closure $closure); - + /** + * Returns the saved service + * + * @param string $abstract the "slug" we refer the service to + * + * @return mixed the searched service + * @throws UnknownServiceException if the service wasn't found + * + * @access public + * @since Method available since Release 3.0.0 + */ public function raw(string $abstract); // : mixed - + /** + * Removes a service from the container + * + * @param string $abstract the "slug" we refer the service to + * + * @return bool whether the service was deleted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function remove(string $abstract) : bool; - + /** + * Flushes the container properties + * + * @return bool true if everything was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function flush() : bool; - + /** + * Returns a service + * + * @param string $abstract the "slug" we refer the service to + * + * @return mixed the requested service + * + * @access public + * @since Method available since Release 3.0.0 + */ public function make(string $abstract); // : mixed - + /** + * Mutually registers the service provider and the container + * + * @param ServiceProviderInterface $provider the service provider + * + * @return ContainerInterface this container + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register( ServiceProviderInterface $provider ) : ContainerInterface; - + /** + * Boots the container's services + * + * @return bool true if the boot was successful + * + * @access public + * @since Method available since Release 3.0.0 + */ public function bootstrap() : bool; } diff --git a/Aeria/Container/Interfaces/ExtensibleInterface.php b/Aeria/Container/Interfaces/ExtensibleInterface.php index 1db77a7..3c34707 100755 --- a/Aeria/Container/Interfaces/ExtensibleInterface.php +++ b/Aeria/Container/Interfaces/ExtensibleInterface.php @@ -1,11 +1,65 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface ExtensibleInterface { + /** + * Extends the saved functions with the provided callable + * + * @param string $method_name the provided method name + * @param callable $callback the callable of the function + * + * @return bool the function was succesfully added + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function extend(string $method_name, callable $callback) : bool; + /** + * Checks whether the provided methods extend the saved functions + * + * @param array $methods_names the provided method name + * + * @return bool the function was succesfully added + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function extends(array $methods_names) : bool; + /** + * Overrides php __call. If the function is present in the class prototypes, it + * gets called. + * + * @param string $name the function name + * @param array $args the arguments to be passed to the function + * + * @return mixed the callable return value + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __call(string $name, array $args); // mixed + /** + * Overrides php __callStatic. If the function is present in the class prototypes, it + * gets called. + * + * @param string $name the function name + * @param array $args the arguments to be passed to the function + * + * @return mixed the callable return value + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function __callStatic(string $name, array $args); // mixed } diff --git a/Aeria/Container/Interfaces/ServiceProviderInterface.php b/Aeria/Container/Interfaces/ServiceProviderInterface.php index 2a5ae22..e1d4a9d 100755 --- a/Aeria/Container/Interfaces/ServiceProviderInterface.php +++ b/Aeria/Container/Interfaces/ServiceProviderInterface.php @@ -3,9 +3,37 @@ namespace Aeria\Container\Interfaces; use Aeria\Container\Container; - +/** + * This interface describes a generic service provider + * + * @category Container + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface ServiceProviderInterface { + /** + * Registers the service to the provided container + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(Container $container); + /** + * In charge of booting the service + * + * @param Container $container Aeria's container + * + * @return bool true if service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container) : bool; } diff --git a/Aeria/Container/Interfaces/ValidateConfInterface.php b/Aeria/Container/Interfaces/ValidateConfInterface.php index fd41884..ebe689a 100755 --- a/Aeria/Container/Interfaces/ValidateConfInterface.php +++ b/Aeria/Container/Interfaces/ValidateConfInterface.php @@ -1,16 +1,83 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface ValidateConfInterface { + /** + * Checks if the passed configuration is valid + * + * @param array $to_validate the validatable configuration + * + * @return null|Exception null if the validation was ok + * + * @access public + * @since Method available since Release 3.0.0 + */ public function isValid(array $to_validate); + /** + * Validates a structure of validators vs. an array + * + * @param array $validation_structure the validation structure + * @param array $array_to_validate the array to validate + * + * @return null|string null if valid, string with the error if not + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function validateStructure( array $validation_structure, array $array_to_validate ); + /** + * Returns the validation array + * + * The returned array contains the validators we need in the config. + * It is structured as the config files. + * + * @return array the validators array + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getValidationStructure() : array; + /** + * Returns a RegEx validator + * + * @param string $regEx the regEx to validate with + * + * @return Closure the RegEx validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeRegExValidator(string $regEx); + /** + * Returns a boolean validator, valid if true + * + * @return Closure the truthness validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeTruthyValidator(); + /** + * Returns a boolean validator, valid if false + * + * @return Closure the falseness validator + * + * @access public + * @since Method available since Release 3.0.0 + */ public function makeFalselyValidator(); } diff --git a/Aeria/Field/Exceptions/NonExistentConfigException.php b/Aeria/Field/Exceptions/NonExistentConfigException.php new file mode 100644 index 0000000..0200b38 --- /dev/null +++ b/Aeria/Field/Exceptions/NonExistentConfigException.php @@ -0,0 +1,9 @@ + + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class FieldError implements TransientableInterface { use Transientable; protected $listErrors = []; private static $_field_error_instances = []; - + /** + * Constructs the FieldError singleton + * + * @param array $list the field errors list + * + * @return void + * + * @access private + * @since Method available since Release 3.0.0 + */ private function __construct($list = []) { $this->listErrors = $list; } - + /** + * Creates the field error instance + * + * @param int $post_id the saved post ID + * + * @return FieldError the instance + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function make($post_id = null) { if ($post_id == null) { @@ -33,21 +60,47 @@ public static function make($post_id = null) } return self::$_field_error_instances[$id]; } - + /** + * Returns the errors list + * + * @return array the errors list + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getList() { return $this->listErrors; } - + /** + * Adds a new error + * + * @param string $key the field's key + * @param array $error the error array + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function addError($key, $error) { $this->listErrors[$key] = $error; } - - public function serializeError($inputId) + /** + * Serializes an error for the frontend + * + * @param string $input_ID the field's ID + * + * @return string|null the encoded error + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function serializeError($input_ID) { - if (isset($this->listErrors[$inputId])) { - return json_encode($this->listErrors[$inputId]); + if (isset($this->listErrors[$input_ID])) { + return json_encode($this->listErrors[$input_ID]); } return null; } diff --git a/Aeria/Field/FieldGroupProcessor.php b/Aeria/Field/FieldGroupProcessor.php index 983c899..d10bdee 100644 --- a/Aeria/Field/FieldGroupProcessor.php +++ b/Aeria/Field/FieldGroupProcessor.php @@ -3,83 +3,169 @@ namespace Aeria\Field; use Aeria\Field\FieldNodeFactory; +use Aeria\Field\Exceptions\NonExistentConfigException; use Aeria\Structure\Tree; - +/** + * FieldGroupProcessor is in charge of managing field groups + * + * @category Field + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class FieldGroupProcessor { - protected $savedFields; + protected $saved_fields; protected $sections; - protected $newValues; - private $tree; - - public function __construct($id, $fieldGroup, $sections, $newValues = []) + protected $new_values; + protected $render_service; + private $_tree; + /** + * Constructs the processor + * + * @param string $id the field group ID + * @param array $field_group the field group's config + * @param array $sections Aeria's sections config + * @param array $render_service Aeria's render service + * @param array $new_values values sent by $_POST + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct($id, $fieldGroup, $sections, $render_service, $new_values = []) { $this->id = $id; $this->sections = $sections; + $this->render_service = $render_service; $this->createTree($fieldGroup); - $this->newValues = $newValues; + $this->new_values = $new_values; } - - private function createTree($fieldGroup) + /** + * Creates the field tree + * + * @param array $field_group the field group's config + * + * @return void + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function createTree($field_group) { - $this->tree = new Tree(); - foreach ($fieldGroup['fields'] as $index=>$config) { - $parentKey = $fieldGroup['id']; - $this->tree->insert(FieldNodeFactory::make($parentKey, $config, $this->sections)); + $this->_tree = new Tree(); + foreach ($field_group['fields'] as $index=>$config) { + $parent_key = $field_group['id']; + $this->_tree->insert(FieldNodeFactory::make($parent_key, $config, $this->sections)); } } - - public function getType(){ - throw new Exception('Need to implement getType'); + /** + * Class to be extended in subclasses: returns the field type + * + * @return void + * @throws Exception if the method is not implemented + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getType() + { + throw new Exception('Need to implement getType'); } - - public function getSavedFields(){ - throw new Exception('Need to implement getSavedFields'); + /** + * Class to be extended in subclasses: returns the saved fields + * + * @return void + * @throws Exception if the method is not implemented + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getSavedFields() + { + throw new Exception('Need to implement getSavedFields'); } - + /** + * Returns the saved fields + * + * @return array the saved values + * + * @access public + * @since Method available since Release 3.0.0 + */ public function get() { $result = []; - $this->tree->executeOnNodes( - function ($node) use (&$result) { - $result[$node->id] = $node->get( - $this->getSavedFields() - ); - } - ); + try { + $this->_tree->executeOnNodes( + function ($node) use (&$result) { + $result[$node->id] = $node->get( + $this->getSavedFields() + ); + } + ); + } catch (NonExistentConfigException $nece) { + error_log("Aeria: there's a missing configuration for the metabox ".$nece->getMessage()); + } return $result; } - + /** + * Returns the saved fields and their configuration + * + * @return array the configuration, hydrated with values + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getAdmin() { $result = []; $savedErrors = FieldError::make($this->id)->getList(); - - $this->tree->executeOnNodes( - function ($node) use (&$result, $savedErrors) { - $result[] = $node->getAdmin( - $this->getSavedFields(), - $savedErrors - ); - } - ); + try { + $this->_tree->executeOnNodes( + function ($node) use (&$result, $savedErrors) { + $result[] = $node->getAdmin( + $this->getSavedFields(), + $savedErrors + ); + } + ); + } catch (NonExistentConfigException $nece) { + error_log("Aeria: there's a missing configuration for the metabox ".$nece->getMessage()); + } return $result; } - + /** + * Saves the new values to the fields. + * + * @param Validator $validator_service the validation service + * @param Query $query_service the DB query service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function set($validator_service, $query_service) { - $this->tree->executeOnNodes( - function ($node) use ($validator_service, $query_service) { - $fieldError = $node->set( - $this->id, - $this->getType(), - $this->getSavedFields(), - $this->newValues, - $validator_service, - $query_service - ); - } - ); + try{ + $this->_tree->executeOnNodes( + function ($node) use ($validator_service, $query_service) { + $fieldError = $node->set( + $this->id, + $this->getType(), + $this->getSavedFields(), + $this->new_values, + $validator_service, + $query_service + ); + } + ); + } catch (NonExistentConfigException $nece) { + error_log("Aeria: there's a missing configuration for the metabox ".$nece->getMessage()); + } } } diff --git a/Aeria/Field/FieldNodeFactory.php b/Aeria/Field/FieldNodeFactory.php index 55ca815..a8eb756 100644 --- a/Aeria/Field/FieldNodeFactory.php +++ b/Aeria/Field/FieldNodeFactory.php @@ -1,13 +1,34 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class FieldNodeFactory { - - public static function make($parentKey, $config, $sections, $index = null) + /** + * Returns an Aeria Field object + * + * @param string $parent_key the parent key for the field + * @param array $config the field's configuration + * @param array $sections the sections' configuration + * @param int $index the index for multiple fields + * + * @return FieldInterface the field object + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function make($parent_key, $config, $sections, $index = null) { - return aeria('field')->make($parentKey, $config, $sections, $index); + return aeria('field')->make($parent_key, $config, $sections, $index); } } diff --git a/Aeria/Field/Fields/BaseField.php b/Aeria/Field/Fields/BaseField.php index 4a6724c..81c50f4 100644 --- a/Aeria/Field/Fields/BaseField.php +++ b/Aeria/Field/Fields/BaseField.php @@ -8,131 +8,228 @@ use Aeria\Structure\Node; use Aeria\Field\Interfaces\FieldInterface; +/** + * BaseField is the class that represents every Aeria field + * + * @category Field + * @package Aeria + * @author Andrea Longo + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class BaseField extends Node implements FieldInterface { - public $isMultipleField = false; - - public function __construct($parentKey, $config, $sections, $index = null) { - $this->parentKey = $parentKey; - $this->config = $config; - $this->id = isset($config['id']) - ? $config['id'] - : null; - $this->index = $index; - $this->key = $this->getKey(); - $this->sections = $sections; + public $is_multiple_field = false; + /** + * Constructs the field + * + * @param string $parent_key the field's parent key + * @param array $config the field's config + * @param array $sections Aeria's sections config + * @param array $index index for multiple fields + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct($parent_key, $config, $sections, $index = null) { + $this->parent_key = $parent_key; + $this->config = $config; + $this->id = isset($config['id']) + ? $config['id'] + : null; + $this->index = $index; + $this->key = $this->getKey(); + $this->sections = $sections; } - - public function shouldBeChildOf(Node $possibleParent) + /** + * Checks whether a field should be child of another + * + * @param Node $possible_parent the field's possible parent + * + * @return bool whether the field should be child of $possible_parent + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function shouldBeChildOf(Node $possible_parent) { - if ($possibleParent->isMultipleField) { - if (preg_match('/^'.$possibleParent->getKey().'.{1,}/', $this->getKey())){ - return true; + if ($possible_parent->is_multiple_field) { + if (preg_match('/^'.$possible_parent->getKey().'.{1,}/', $this->getKey())) { + return true; + } else { + return false; + } } + else if (get_class($possible_parent)=="RootNode") // Check if possible_parent is root + return true; else return false; - } - else if (get_class($possibleParent)=="RootNode") // Check if possibleParent is root - return true; - else - return false; } - - public function getKey() { - return $this->parentKey - . (!is_null($this->index) ? '-'.$this->index : '') - . (!is_null($this->id) ? '-'.$this->id : ''); + /** + * Gets the field full key + * + * @return string the field's key + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getKey() + { + return $this->parent_key + . (!is_null($this->index) ? '-'.$this->index : '') + . (!is_null($this->id) ? '-'.$this->id : ''); } - - public function get(array $savedFields, bool $skipFilter = false) { - if (!isset($savedFields[$this->key])) - { - return null; - } - if(!$skipFilter){ - $savedFields[$this->key] = apply_filters("aeria_get_base", $savedFields[$this->key], $this->config); - $savedFields[$this->key] = apply_filters("aeria_get_".$this->key, $savedFields[$this->key], $this->config); - } - if (is_array($savedFields[$this->key])) { - return $savedFields[$this->key][0]; - } else { - return $savedFields[$this->key]; - } + /** + * Gets the field's value + * + * @param array $saved_fields the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return mixed the field's value + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $saved_fields, bool $skip_filter = false) { + if (!isset($saved_fields[$this->key])) { + return null; + } + if (!$skip_filter) { + $saved_fields[$this->key] = apply_filters("aeria_get_base", $saved_fields[$this->key], $this->config); + $saved_fields[$this->key] = apply_filters("aeria_get_".$this->key, $saved_fields[$this->key], $this->config); + } + if (is_array($saved_fields[$this->key])) { + return $saved_fields[$this->key][0]; + } else { + return $saved_fields[$this->key]; + } } + /** + * Gets the field's value and its errors + * + * @param array $saved_fields the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $saved_fields, array $errors) + { + if (isset($errors[$this->key])) { + $result = [ + 'value' => $errors[$this->key]["value"], + 'error' => $errors[$this->key]["message"] + ]; + } else { + $result = [ + 'value' => $this->get($saved_fields, true), + ]; + } - public function getAdmin(array $savedFields, array $errors) { - - if (isset($errors[$this->key])) { - $result = [ - 'value' => $errors[$this->key]["value"], - 'error' => $errors[$this->key]["message"] - ]; - } else { - $result = [ - 'value' => $this->get($savedFields, true), - ]; - } - - if(is_null($result['value'])){ - return $this->config; - } + if (is_null($result['value'])) { + return $this->config; + } - return array_merge( - $this->config, - $result - ); + return array_merge( + $this->config, + $result + ); } - - public function set($context_ID, $context_type, array $savedFields, array $newValues, $validator_service, $query_service) + /** + * Saves the new values to the fields. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param array $saved_fields the saved fields + * @param array $new_values the values we're saving + * @param Validator $validator_service Aeria's validator service + * @param Query $query_service Aeria's query service + * + * @return array the results of the saving + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function set($context_ID, $context_type, array $saved_fields, array $new_values, $validator_service, $query_service) { - $value = isset($newValues[$this->key]) ? $newValues[$this->key] : null; - $old = isset($savedFields[$this->key][0]) ? $savedFields[$this->key][0] : ''; + $value = isset($new_values[$this->key]) ? $new_values[$this->key] : null; + $old = isset($saved_fields[$this->key][0]) ? $saved_fields[$this->key][0] : ''; $value = apply_filters("aeria_set_".$this->key, $value, $this->config); if ($value == $old) return ["value" => $value]; if (is_null($value) || $value == '') { - $this->deleteField($context_ID, $context_type, $query_service); - return ["value" => $value]; - } else { - $validators=(isset($this->config["validators"])) ? $this->config["validators"] : ""; - $error=$validator_service->validate($value, $validators); - - if(!$error["status"]){ - $this->saveField($context_ID, $context_type, $value, $old); + $this->deleteField($context_ID, $context_type, $query_service); return ["value" => $value]; - } else { - FieldError::make($context_ID) - ->addError($this->key, $error); - return $error; - } + } else { + $validators=(isset($this->config["validators"])) ? $this->config["validators"] : ""; + $error=$validator_service->validate($value, $validators); + + if (!$error["status"]) { + $this->saveField($context_ID, $context_type, $value, $old); + return ["value" => $value]; + } else { + FieldError::make($context_ID) + ->addError($this->key, $error); + return $error; + } } } - - private function saveField($context_ID, $context_type, $value, $old){ - switch ($context_type) { + /** + * Saves a single field to the DB. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param mixed $value the new value + * @param mixed $old the old value + * + * @return void + * @throws Exception if the node context is invalid + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function saveField($context_ID, $context_type, $value, $old) + { + switch ($context_type) { case 'options': - update_option($this->key, $value); - break; + update_option($this->key, $value); + break; case 'meta': - update_post_meta($context_ID, $this->key, $value, $old); - break; + update_post_meta($context_ID, $this->key, $value, $old); + break; default: - throw new Exception("Node context is not valid."); - break; - } + throw new Exception("Node context is not valid."); + break; + } } - + /** + * Deletes a field value + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param Query $query_service Aeria's query service + * + * @return void + * @throws Exception if the node context is invalid + * + * @access private + * @since Method available since Release 3.0.0 + */ private function deleteField($context_ID, $context_type, $query_service){ - switch ($context_type) { + switch ($context_type) { case 'options': - $query_service->deleteOption($this->key); - break; + $query_service->deleteOption($this->key); + break; case 'meta': - $query_service->deleteMeta($context_ID, $this->key); - break; + $query_service->deleteMeta($context_ID, $this->key); + break; default: - throw new Exception("Node context is not valid."); - break; - } + throw new Exception("Node context is not valid."); + break; + } } } diff --git a/Aeria/Field/Fields/DateRangeField.php b/Aeria/Field/Fields/DateRangeField.php new file mode 100644 index 0000000..b6477cb --- /dev/null +++ b/Aeria/Field/Fields/DateRangeField.php @@ -0,0 +1,73 @@ + + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class DateRangeField extends BaseField +{ + public $is_multiple_field = false; + /** + * Gets the field's value + * + * @param array $metas the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return mixed the field's values, an array containing the start at [0], end at [1] + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $metas, bool $skip_filter = false) + { + $from = (new BaseField($this->key, ['id' => 'from'], $this->sections))->get($metas); + $to = (new BaseField($this->key, ['id' => 'to'], $this->sections))->get($metas); + $values = [$from,$to]; + if(!$skip_filter) + $values = apply_filters("aeria_get_daterange", $values, $this->config); + return $values; + } + /** + * Gets the field's value and its errors + * + * @param array $metas the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $metas, array $errors) + { + return parent::getAdmin($metas, $errors, true); + } + /** + * Saves the new values to the fields. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param array $saved_fields the saved fields + * @param array $new_values the values we're saving + * @param Validator $validator_service Aeria's validator service + * @param Query $query_service Aeria's query service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function set($context_ID, $context_type, array $saved_fields, array $new_values, $validator_service, $query_service) + { + (new BaseField($this->key, ['id' => 'from'], $this->sections))->set($context_ID, $context_type, $saved_fields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'to'], $this->sections))->set($context_ID, $context_type, $saved_fields, $new_values, $validator_service, $query_service); + } +} diff --git a/Aeria/Field/Fields/GalleryField.php b/Aeria/Field/Fields/GalleryField.php index 1c40174..dc1d6c9 100644 --- a/Aeria/Field/Fields/GalleryField.php +++ b/Aeria/Field/Fields/GalleryField.php @@ -4,53 +4,98 @@ use Aeria\Field\Fields\PictureField; use Aeria\Field\Interfaces\FieldInterface; - +/** + * Gallery is the class that represents a gallery field + * + * @category Field + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class GalleryField extends BaseField { - public $isMultipleField = false; - + public $is_multiple_field = false; - public function get(array $savedFields, bool $skipFilter = false) { - $length = (int)parent::get($savedFields, true); - $children = []; + /** + * Gets the field's value + * + * @param array $saved_fields the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return array the field's values, an array containing the gallery's children + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $saved_fields, bool $skip_filter = false) + { + $length = (int)parent::get($saved_fields, true); + $children = []; - for ($i = 0; $i < $length; ++$i) { - $children[] = (new PictureField( - $this->key, ['id' => 'picture'], $this->sections, $i - ))->get($savedFields); - } - if(!$skipFilter) - $children = apply_filters('aeria_get_gallery', $children, $this->config); - return $children; + for ($i = 0; $i < $length; ++$i) { + $children[] = (new PictureField( + $this->key, ['id' => 'picture'], $this->sections, $i + ))->get($saved_fields); + } + if (!$skip_filter) + $children = apply_filters('aeria_get_gallery', $children, $this->config); + return $children; } + /** + * Gets the field's value and its errors + * + * @param array $saved_fields the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $saved_fields, array $errors) + { + $stored_value = parent::get($saved_fields, true); + $result = []; + $result['value'] = (int)$stored_value; + $result['children'] = []; - public function getAdmin(array $savedFields, array $errors) { - $stored_value = parent::get($savedFields, true); - $result = []; - $result['value'] = (int)$stored_value; - $result['children'] = []; - - for ($i = 0; $i < $result['value']; ++$i) { - $result['children'][] = (new PictureField( - $this->key, ['id' => 'picture'], $this->sections, $i - ))->getAdmin($savedFields, $errors); - } - return array_merge( - $this->config, - $result - ); + for ($i = 0; $i < $result['value']; ++$i) { + $result['children'][] = (new PictureField( + $this->key, ['id' => 'picture'], $this->sections, $i + ))->getAdmin($saved_fields, $errors); + } + return array_merge( + $this->config, + $result + ); } - - public function set($context_ID, $context_type, array $savedFields, array $newValues, $validator_service, $query_service) { - $stored_values = (int)parent::set($context_ID, $context_type, $savedFields, $newValues, $validator_service, $query_service)["value"]; - if(!$stored_values) { - return; - } - for ($i = 0; $i < $stored_values; ++$i) { - (new PictureField( - $this->key, ['id' => 'picture'], $this->sections, $i - ))->set($context_ID, $context_type, $savedFields, $newValues, $validator_service, $query_service); - } + /** + * Saves the new values to the fields. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param array $saved_fields the saved fields + * @param array $new_values the values we're saving + * @param Validator $validator_service Aeria's validator service + * @param Query $query_service Aeria's query service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function set($context_ID, $context_type, array $saved_fields, array $new_values, $validator_service, $query_service) + { + $stored_values = (int)parent::set($context_ID, $context_type, $saved_fields, $new_values, $validator_service, $query_service)["value"]; + if (!$stored_values) { + return; + } + for ($i = 0; $i < $stored_values; ++$i) { + (new PictureField( + $this->key, ['id' => 'picture'], $this->sections, $i + ))->set($context_ID, $context_type, $saved_fields, $new_values, $validator_service, $query_service); + } } } diff --git a/Aeria/Field/Fields/MapField.php b/Aeria/Field/Fields/MapField.php new file mode 100644 index 0000000..df231ae --- /dev/null +++ b/Aeria/Field/Fields/MapField.php @@ -0,0 +1,60 @@ +key, ['id' => 'address', 'validators' => ''], $this->sections))->get($metas); + $autocomplete = (new BaseField($this->key, ['id' => 'autocomplete', 'validators' => ''], $this->sections))->get($metas); + $country = (new BaseField($this->key, ['id' => 'country', 'validators' => ''], $this->sections))->get($metas); + $lat = floatval((new BaseField($this->key, ['id' => 'lat', 'validators' => ''], $this->sections))->get($metas)); + $lng = floatval((new BaseField($this->key, ['id' => 'lng', 'validators' => ''], $this->sections))->get($metas)); + $locality = (new BaseField($this->key, ['id' => 'locality', 'validators' => ''], $this->sections))->get($metas); + $postal_code = (new BaseField($this->key, ['id' => 'postal_code', 'validators' => ''], $this->sections))->get($metas); + $region = (new BaseField($this->key, ['id' => 'region', 'validators' => ''], $this->sections))->get($metas); + $route = (new BaseField($this->key, ['id' => 'route', 'validators' => ''], $this->sections))->get($metas); + $street_number = (new BaseField($this->key, ['id' => 'street_number', 'validators' => ''], $this->sections))->get($metas); + $api_key = get_option('map_options-api_key'); + $infos = [ + 'api_key' => $api_key, + 'autocomplete' => $autocomplete, + 'address' => $address, + 'country' => $country, + 'lat' => $lat, + 'lng' => $lng, + 'locality' => $locality, + 'postal_code' => $postal_code, + 'region' => $region, + 'route' => $route, + 'street_number' => $street_number + ]; + if(!$skipFilter) + $infos = apply_filters("aeria_get_maps", $infos, $this->config); + return $infos; + } + + public function getAdmin(array $metas, array $errors) + { + return parent::getAdmin($metas, $errors, true); + } + + public function set($context_ID, $context_type, array $savedFields, array $new_values, $validator_service, $query_service) + { + (new BaseField($this->key, ['id' => 'autocomplete', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'address', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'country', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'lat', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'lng', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'locality', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'postal_code', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'region', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'route', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + (new BaseField($this->key, ['id' => 'street_number', 'validators' => ''], $this->sections))->set($context_ID, $context_type, $savedFields, $new_values, $validator_service, $query_service); + } +} \ No newline at end of file diff --git a/Aeria/Field/Fields/PictureField.php b/Aeria/Field/Fields/PictureField.php index b38505b..6043ccc 100644 --- a/Aeria/Field/Fields/PictureField.php +++ b/Aeria/Field/Fields/PictureField.php @@ -3,17 +3,36 @@ namespace Aeria\Field\Fields; use Aeria\Field\Interfaces\FieldInterface; - +/** + * Picture is the class that represents a picture field + * + * @category Field + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class PictureField extends BaseField { - public $isMultipleField = false; - - public function get(array $savedFields, bool $skipFilter = false) { - $value = (int) parent::get($savedFields, true); + public $is_multiple_field = false; + /** + * Gets the field's value + * + * @param array $saved_fields the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return array the field's values, an array containing the image's thumb and full res + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $saved_fields, bool $skip_filter = false) + { + $value = (int) parent::get($saved_fields, true); $thumb = wp_get_attachment_image_src($value)[0]; $full = wp_get_attachment_image_src($value, "full")[0]; - if($skipFilter) + if($skip_filter) return [ 'thumb' => $thumb, 'full' => $full @@ -29,9 +48,20 @@ public function get(array $savedFields, bool $skipFilter = false) { ); } - - public function getAdmin(array $savedFields, array $errors) { - $stored_value = parent::get($savedFields, true); + /** + * Gets the field's value and its errors + * + * @param array $saved_fields the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $saved_fields, array $errors) + { + $stored_value = parent::get($saved_fields, true); $result = []; $result['value'] = (int)$stored_value; $result['url'] = wp_get_attachment_image_src($result['value'])[0]; diff --git a/Aeria/Field/Fields/RelationField.php b/Aeria/Field/Fields/RelationField.php index f473f87..7d34497 100644 --- a/Aeria/Field/Fields/RelationField.php +++ b/Aeria/Field/Fields/RelationField.php @@ -4,14 +4,34 @@ use Aeria\Field\Fields\SelectField; use Aeria\Field\Interfaces\FieldInterface; - +/** + * Relation is the class that represents a relationship field + * + * @category Field + * @package Aeria + * @author Andrea Longo + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class RelationField extends SelectField { protected $original_config; - - public function __construct($parentKey, $config, $sections, $index = null) { - parent::__construct($parentKey, $config, $sections, $index); + /** + * Constructs the field + * + * @param string $parent_key the field's parent key + * @param array $config the field's config + * @param array $sections Aeria's sections config + * @param array $index index for of the subfield + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct($parent_key, $config, $sections, $index = null) { + parent::__construct($parent_key, $config, $sections, $index); $this->original_config = json_decode(json_encode($config)); @@ -19,23 +39,35 @@ public function __construct($parentKey, $config, $sections, $index = null) { $this->config['ajax'] = $this->config['relation']; unset($this->config['relation']); } + /** + * Gets the field's value + * + * @param array $saved_fields the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return array the field's related posts. + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $saved_fields, bool $skip_filter = false) { + $values = parent::get($saved_fields, true); - public function get(array $savedFields, bool $skipFilter = false) { - $values = parent::get($savedFields, true); - - if ($skipFilter) { + if ($skip_filter) { return $values; } if (!empty($values)) { - if(isset($this->config['multiple']) && $this->config['multiple']){ + if (isset($this->config['multiple']) && $this->config['multiple']) { $post_type = isset($this->config['relation']['type']) ? $this->config['relation']['type'] : 'any'; - $values = get_posts([ - 'post__in' => $values, - 'post_type' => 'any' - ]); + $values = get_posts( + [ + 'post__in' => $values, + 'post_type' => 'any' + ] + ); } else { $values = get_post($values); } diff --git a/Aeria/Field/Fields/RepeaterField.php b/Aeria/Field/Fields/RepeaterField.php index ce1f1a8..a33dc90 100644 --- a/Aeria/Field/Fields/RepeaterField.php +++ b/Aeria/Field/Fields/RepeaterField.php @@ -5,95 +5,159 @@ use Aeria\Field\Fields\BaseField; use Aeria\Field\FieldNodeFactory; use Aeria\Field\Interfaces\FieldInterface; - +/** + * Repeater is the class that represents a repeater field + * + * @category Field + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class RepeaterField extends BaseField { - public $isMultipleField = true; - - public function get(array $metas, bool $skipFilter = false) { - $stored_value = (int)parent::get($metas, true); - $children = []; - - $fields = $this->config['fields']; - - for ($i = 0; $i < $stored_value; ++$i) { - $child = new \StdClass(); - for ($j = 0; $j < count($fields); ++$j) { - $field_config = $fields[$j]; - - $child->{$field_config['id']} = FieldNodeFactory::make( - $this->key, $field_config, $this->sections, $i - )->get($metas); - } - - if(count($fields) === 1){ - $children[] = $child->{$fields[0]['id']}; - }else{ - $children[] = $child; + public $is_multiple_field = true; + /** + * Gets the field's value + * + * @param array $metas the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return array the field's children + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $metas, bool $skip_filter = false) { + $stored_value = (int)parent::get($metas, true); + $children = []; + + $fields = $this->config['fields']; + + for ($i = 0; $i < $stored_value; ++$i) { + $child = new \StdClass(); + for ($j = 0; $j < count($fields); ++$j) { + $field_config = $fields[$j]; + + $child->{$field_config['id']} = FieldNodeFactory::make( + $this->key, $field_config, $this->sections, $i + )->get($metas); + } + + if (count($fields) === 1) { + $children[] = $child->{$fields[0]['id']}; + } else { + $children[] = $child; + } } - } - if(!$skipFilter) - $children = apply_filters('aeria_get_repeater', $children, $this->config); - return $children; + if(!$skip_filter) + $children = apply_filters('aeria_get_repeater', $children, $this->config); + return $children; } - + /** + * Gets the field's value and its errors + * + * @param array $metas the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getAdmin(array $metas, array $errors) { - $stored_value = (int)parent::get($metas, true); - $children = []; + $stored_value = (int)parent::get($metas, true); + $children = []; - $fields = $this->config['fields']; + $fields = $this->config['fields']; - for ($i = 0; $i < $stored_value; ++$i) { - $child = []; - for ($j = 0; $j < count($fields); ++$j) { - $field_config = $fields[$j]; + for ($i = 0; $i < $stored_value; ++$i) { + $child = []; + for ($j = 0; $j < count($fields); ++$j) { + $field_config = $fields[$j]; - $child[] = FieldNodeFactory::make( - $this->key, $field_config, $this->sections, $i - )->getAdmin($metas, $errors); + $child[] = FieldNodeFactory::make( + $this->key, $field_config, $this->sections, $i + )->getAdmin($metas, $errors); + } + $children[] = $child; } - $children[] = $child; - } - return array_merge( - $this->config, - [ - "value" => $stored_value, - "children" => $children - ] - ); + return array_merge( + $this->config, + [ + "value" => $stored_value, + "children" => $children + ] + ); } + /** + * Saves the new values to the fields. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param array $metas the saved fields + * @param array $new_values the values we're saving + * @param Validator $validator_service Aeria's validator service + * @param Query $query_service Aeria's query service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function set($context_ID, $context_type, array $metas, array $new_values, $validator_service, $query_service) { + $stored_values = (int)parent::set($context_ID, $context_type, $metas, $new_values, $validator_service, $query_service)["value"]; + if (!$stored_values) { + return; + } - public function set($context_ID, $context_type, array $metas, array $newValues, $validator_service, $query_service) { - $stored_values = (int)parent::set($context_ID, $context_type, $metas, $newValues, $validator_service, $query_service)["value"]; - if(!$stored_values) { - return; - } - - $fields = $this->config['fields']; + $fields = $this->config['fields']; - for ($i = 0; $i < $stored_values; ++$i) { - for ($j = 0; $j < count($fields); ++$j) { - FieldNodeFactory::make( - $this->key, $fields[$j], $this->sections, $i - )->set($context_ID, $context_type, $metas, $newValues, $validator_service, $query_service); + for ($i = 0; $i < $stored_values; ++$i) { + for ($j = 0; $j < count($fields); ++$j) { + FieldNodeFactory::make( + $this->key, $fields[$j], $this->sections, $i + )->set($context_ID, $context_type, $metas, $new_values, $validator_service, $query_service); + } } - } - $this->deleteOrphanMeta($this->key,$metas, $newValues); + $this->deleteOrphanMeta($this->key, $metas, $new_values); } - - private function deleteOrphanMeta ($parentKey, $metas, $newValues) + /** + * Deletes the metas that lose a parent :( + * + * @param string $parent_key the parent's key + * @param array $metas the saved fields + * @param array $new_values the values we're saving + * + * @return void + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function deleteOrphanMeta($parent_key, $metas, $new_values) { - $oldFields=static::pregGrepKeys("/^".$parentKey."/", $metas); - $newFields=static::pregGrepKeys("/^".$parentKey."/", $newValues); + $oldFields=static::pregGrepKeys("/^".$parent_key."/", $metas); + $newFields=static::pregGrepKeys("/^".$parent_key."/", $new_values); $deletableFields = array_diff_key($oldFields, $newFields); foreach ($deletableFields as $deletableKey => $deletableField) { - delete_post_meta($newValues['post_ID'], $deletableKey); + delete_post_meta($new_values['post_ID'], $deletableKey); } } - - private static function pregGrepKeys($pattern, $input) { - return array_intersect_key($input, array_flip(preg_grep($pattern, array_keys($input)))); + /** + * Helper function for deleteOrphanMeta: gets the orphan keys + * + * @param string $pattern the parent's key RegEx + * @param array $input the values we're saving + * + * @return array the orphans to be deleted + * + * @access private + * @since Method available since Release 3.0.0 + */ + private static function pregGrepKeys($pattern, $input) + { + return array_intersect_key($input, array_flip(preg_grep($pattern, array_keys($input)))); } } diff --git a/Aeria/Field/Fields/SectionsField.php b/Aeria/Field/Fields/SectionsField.php index dac43bf..43d5bd2 100644 --- a/Aeria/Field/Fields/SectionsField.php +++ b/Aeria/Field/Fields/SectionsField.php @@ -7,66 +7,131 @@ use Aeria\Field\Fields\SwitchField; use Aeria\Field\FieldNodeFactory; use Aeria\Field\Interfaces\FieldInterface; - +use Aeria\Field\Exceptions\NonExistentConfigException; + +/** + * Sections is the class that represents a section field + * + * @category Field + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class SectionsField extends BaseField { public $isMultipleField = true; + /** + * Gets a section configuration + * + * @param string $type the searched section's configuration + * + * @return array the section's configuration + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function getSectionConfig($type) + { + if (isset($this->sections[$type])) + return $this->sections[$type]; + else + throw new NonExistentConfigException(); - private function getSectionConfig($type){ - return $this->sections[$type]; } - - private function getTitle($index){ - // TODO: decide if headerTitle is needed inside the theme - return new BaseField( - $this->key, - ["id" => 'headerTitle', "validators" =>"" ], - $this->sections, - $index - ); + /** + * Gets a section's title + * + * @param int $index the section's index + * + * @return BaseField the section's title field + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function getTitle($index) + { + return new BaseField( + $this->key, + ["id" => 'headerTitle', "validators" =>"" ], + $this->sections, + $index + ); } - - private function getDraftMode($index){ - return new SwitchField( - $this->key, - ["id" => 'draft', "validators" => "" ], - $this->sections, - $index - ); + /** + * Gets the "draft" switch + * + * @param int $index the section's index + * + * @return array the section's draft switch + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function getDraftMode($index) + { + return new SwitchField( + $this->key, + ["id" => 'draft', "validators" => "" ], + $this->sections, + $index + ); } + /** + * Gets the field's value + * + * @param array $metas the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return mixed the field's values, an array containing the sections' values + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $metas, bool $skip_filter = false) + { + $types = parent::get($metas, true); + if (is_null($types) || $types == '') { + return []; + } - public function get(array $metas, bool $skipFilter = false) { - $types = parent::get($metas, true); - if(is_null($types) || $types == ''){ - return []; - } - - $types = explode(',', $types); - $children = []; - - foreach ($types as $i => $type) { - $section_config = $this->getSectionConfig($type); - $field_result = new \StdClass(); - $field_result->type = $type; - $field_result->data = new \StdClass(); + $types = explode(',', $types); + $children = []; - foreach ($section_config['fields'] as $field_index => $field_config) { - $field_result->data->{$field_config['id']} = FieldNodeFactory::make( - $this->key, $field_config, $this->sections, $i - )->get($metas); - } + foreach ($types as $i => $type) { + $section_config = $this->getSectionConfig($type); + $field_result = new \StdClass(); + $field_result->type = $type; + $field_result->data = new \StdClass(); + + foreach ($section_config['fields'] as $field_index => $field_config) { + $field_result->data->{$field_config['id']} = FieldNodeFactory::make( + $this->key, $field_config, $this->sections, $i + )->get($metas); + } - $isDraft = $this->getDraftMode($i)->get($metas); - if(!$isDraft){ - $children[] = $field_result; + $isDraft = $this->getDraftMode($i)->get($metas); + if (!$isDraft) { + $children[] = $field_result; + } } - } - if(!$skipFilter) - $children = apply_filters('aeria_get_sections', $children, $this->config); - return $children; + if(!$skip_filter) + $children = apply_filters('aeria_get_sections', $children, $this->config); + return $children; } - - public function getAdmin(array $metas, array $errors) { + /** + * Gets the field's value and its errors + * + * @param array $metas the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the sections' config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $metas, array $errors) + { $stored_value = parent::get($metas, true); $stored_value = (bool)$stored_value ? explode(',', $stored_value) : []; @@ -105,42 +170,79 @@ public function getAdmin(array $metas, array $errors) { ] ); } + /** + * Saves the new values to the fields. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param array $metas the saved fields + * @param array $new_values the values we're saving + * @param Validator $validator_service Aeria's validator service + * @param Query $query_service Aeria's query service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function set($context_ID, $context_type, array $metas, array $new_values, $validator_service, $query_service) + { + $stored_value = parent::set($context_ID, $context_type, $metas, $new_values, $validator_service, $query_service)["value"]; + $stored_value = (bool)$stored_value ? explode(',', $stored_value) : []; - public function set($context_ID, $context_type, array $metas, array $newValues, $validator_service, $query_service) { - $stored_value = parent::set($context_ID, $context_type, $metas, $newValues, $validator_service, $query_service)["value"]; - $stored_value = (bool)$stored_value ? explode(',', $stored_value) : []; - - foreach ($stored_value as $type_index => $type) { - $section_config = $this->getSectionConfig($type); + foreach ($stored_value as $type_index => $type) { + $section_config = $this->getSectionConfig($type); - // save title - $this->getTitle($type_index)->set($context_ID, $context_type, $metas, $newValues, $validator_service, $query_service); + // save title + $this->getTitle($type_index)->set($context_ID, $context_type, $metas, $new_values, $validator_service, $query_service); - // save status - $this->getDraftMode($type_index)->set($context_ID, $context_type, $metas, $newValues, $validator_service, $query_service); + // save status + $this->getDraftMode($type_index)->set($context_ID, $context_type, $metas, $new_values, $validator_service, $query_service); - // save children - foreach ($section_config['fields'] as $field_index => $field_config) { - FieldNodeFactory::make( - $this->key, $field_config, $this->sections, $type_index - )->set($context_ID, $context_type, $metas, $newValues, $validator_service, $query_service, $query_service); + // save children + foreach ($section_config['fields'] as $field_index => $field_config) { + FieldNodeFactory::make( + $this->key, $field_config, $this->sections, $type_index + )->set($context_ID, $context_type, $metas, $new_values, $validator_service, $query_service, $query_service); + } + // remove orphans + $this->deleteOrphanMeta($this->key.'-'.$type_index, $metas, $new_values); } - // remove orphans - $this->deleteOrphanMeta($this->key.'-'.$type_index, $metas, $newValues); - } } - - private function deleteOrphanMeta($parentKey, $metas, $newValues) + /** + * Deletes the metas that lose a parent :( + * + * @param string $parent_key the parent's key + * @param array $metas the saved fields + * @param array $new_values the values we're saving + * + * @return void + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function deleteOrphanMeta($parent_key, $metas, $new_values) { - $oldFields=static::pregGrepKeys("/^".$parentKey."/", $metas); - $newFields=static::pregGrepKeys("/^".$parentKey."/", $newValues); + $oldFields=static::pregGrepKeys("/^".$parent_key."/", $metas); + $newFields=static::pregGrepKeys("/^".$parent_key."/", $new_values); $deletableFields = array_diff_key($oldFields, $newFields); - foreach ($deletableFields as $deletableKey => $deletableField){ - delete_post_meta($newValues['post_ID'], $deletableKey); + foreach ($deletableFields as $deletableKey => $deletableField) { + delete_post_meta($new_values['post_ID'], $deletableKey); } } - - private static function pregGrepKeys($pattern, $input) { - return array_intersect_key($input, array_flip(preg_grep($pattern, array_keys($input)))); + /** + * Helper function for deleteOrphanMeta: gets the orphan keys + * + * @param string $pattern the parent's key RegEx + * @param array $input the values we're saving + * + * @return array the orphans to be deleted + * + * @access private + * @since Method available since Release 3.0.0 + */ + private static function pregGrepKeys($pattern, $input) + { + return array_intersect_key($input, array_flip(preg_grep($pattern, array_keys($input)))); } } diff --git a/Aeria/Field/Fields/SelectField.php b/Aeria/Field/Fields/SelectField.php index 006ef98..b979b1f 100644 --- a/Aeria/Field/Fields/SelectField.php +++ b/Aeria/Field/Fields/SelectField.php @@ -3,13 +3,32 @@ namespace Aeria\Field\Fields; use Aeria\Field\Interfaces\FieldInterface; - +/** + * SelectField is the class that represents a select field + * + * @category Field + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class SelectField extends BaseField { - public $isMultipleField = false; - - public function get(array $savedFields, bool $skipFilter = false) { - $values = parent::get($savedFields, true); + public $is_multiple_field = false; + /** + * Gets the field's value + * + * @param array $saved_fields the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return mixed the field's values, an array containing the selected values + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $saved_fields, bool $skip_filter = false) + { + $values = parent::get($saved_fields, true); if (isset($this->config['multiple']) && $this->config['multiple'] && $values!="") { $values = explode(',', $values); @@ -18,13 +37,24 @@ public function get(array $savedFields, bool $skipFilter = false) { return null; } - if(!$skipFilter) + if(!$skip_filter) $values = apply_filters("aeria_get_select", $values, $this->config); return $values; } - - public function getAdmin(array $savedFields, array $errors) { - $savedValues = parent::getAdmin($savedFields, $errors, true); + /** + * Gets the field's value and its errors + * + * @param array $saved_fields the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $saved_fields, array $errors) + { + $savedValues = parent::getAdmin($saved_fields, $errors, true); return array_merge( $this->config, $savedValues diff --git a/Aeria/Field/Fields/SwitchField.php b/Aeria/Field/Fields/SwitchField.php index 92772bc..f60c598 100644 --- a/Aeria/Field/Fields/SwitchField.php +++ b/Aeria/Field/Fields/SwitchField.php @@ -3,31 +3,75 @@ namespace Aeria\Field\Fields; use Aeria\Field\Interfaces\FieldInterface; - +/** + * Switch is the class that represents an ON/OFF switch + * + * @category Field + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class SwitchField extends BaseField { - public $isMultipleField = false; - - public function get(array $savedFields, bool $skipFilter = false) { - $result = filter_var(parent::get($savedFields, true), FILTER_VALIDATE_BOOLEAN); - if(!$skipFilter) - $result = apply_filters('aeria_get_switch', $result, $this->config); - return $result; + public $is_multiple_field = false; + /** + * Gets the field's value + * + * @param array $saved_fields the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return mixed the field's values, containing true or false + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $saved_fields, bool $skip_filter = false) + { + $result = filter_var(parent::get($saved_fields, true), FILTER_VALIDATE_BOOLEAN); + if(!$skip_filter) + $result = apply_filters('aeria_get_switch', $result, $this->config); + return $result; } - - public function getAdmin(array $savedFields, array $errors) { - $savedValues = parent::getAdmin($savedFields, $errors, true); - $savedValues['value'] = filter_var($savedValues['value'], FILTER_VALIDATE_BOOLEAN); - return $savedValues; + /** + * Gets the field's value and its errors + * + * @param array $saved_fields the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $saved_fields, array $errors) + { + $savedValues = parent::getAdmin($saved_fields, $errors, true); + $savedValues['value'] = filter_var($savedValues['value'], FILTER_VALIDATE_BOOLEAN); + return $savedValues; } - - public function set($context_ID, $context_type, array $savedFields, array $newValues, $validator_service, $query_service) + /** + * Saves the new values to the fields. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param array $saved_fields the saved fields + * @param array $new_values the values we're saving + * @param Validator $validator_service Aeria's validator service + * @param Query $query_service Aeria's query service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function set($context_ID, $context_type, array $saved_fields, array $new_values, $validator_service, $query_service) { - if( !isset($newValues[$this->key]) || !filter_var($newValues[$this->key], FILTER_VALIDATE_BOOLEAN)) { - $newValues[$this->key] = 'false'; - } else { - $newValues[$this->key] = 'true'; - } - parent::set($context_ID, $context_type, $savedFields, $newValues, $validator_service, $query_service); + if (!isset($new_values[$this->key]) || !filter_var($new_values[$this->key], FILTER_VALIDATE_BOOLEAN)) { + $new_values[$this->key] = 'false'; + } else { + $new_values[$this->key] = 'true'; + } + parent::set($context_ID, $context_type, $saved_fields, $new_values, $validator_service, $query_service); } } diff --git a/Aeria/Field/FieldsRegistry.php b/Aeria/Field/FieldsRegistry.php index 2474cfd..b80f2dd 100644 --- a/Aeria/Field/FieldsRegistry.php +++ b/Aeria/Field/FieldsRegistry.php @@ -4,7 +4,15 @@ use Aeria\Field\Interfaces\FieldInterface; use Aeria\Structure\Traits\DictionaryTrait; - +/** + * FieldsRegistry is in charge of registering the different fields in Aeria + * + * @category Field + * @package Aeria + * @author Andrea Longo + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class FieldsRegistry { @@ -13,7 +21,19 @@ class FieldsRegistry protected $registry = []; const DEFAULT_FIELD_TYPE = 'base'; - + /** + * Registers a new field + * + * @param string $name the wanted "slug" for the field + * @param string $namespace the field's class namespace + * @param bool $override whether to override or not the existance check + * + * @return FieldsRegistry the fields registry + * @throws Exception if the field was already registered + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(string $name, string $namespace = null, bool $override = false) { if (empty($namespace)) { @@ -21,19 +41,31 @@ public function register(string $name, string $namespace = null, bool $override $name = strtolower(array_pop(explode('\\', $name))); } if ($this->exists($name) && !$override) { - throw new \Exception("The field named {$name} has been already registered"); + throw new \Exception("The field named {$name} has been already registered"); } $this->set($name, $namespace); return $this; } - - public function make($parentKey, $config, $sections, $index = null) : FieldInterface + /** + * Returns a field object + * + * @param string $parent_key the field's parent key + * @param array $config the field's configuration + * @param array $sections Aeria's sections configuration + * @param int $index for multiple fields with children + * + * @return FieldInterface the field + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function make($parent_key, $config, $sections, $index = null) : FieldInterface { $field_type = $config['type']; $fieldClass = $this->exists($field_type) ? $this->get($field_type) : $this->get(self::DEFAULT_FIELD_TYPE); - return new $fieldClass($parentKey, $config, $sections, $index); + return new $fieldClass($parent_key, $config, $sections, $index); } } diff --git a/Aeria/Field/Interfaces/FieldInterface.php b/Aeria/Field/Interfaces/FieldInterface.php index 423db2c..f381da4 100644 --- a/Aeria/Field/Interfaces/FieldInterface.php +++ b/Aeria/Field/Interfaces/FieldInterface.php @@ -1,16 +1,70 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface FieldInterface { - - public function __construct($parentKey, $config, $sections, $index); - - public function get(array $savedFields, bool $skipFilter); - - public function getAdmin(array $savedFields, array $errors); - - public function set($context_ID, $context_type, array $savedFields, array $newValues, $validator_service, $query_service); + /** + * Constructs the field + * + * @param string $parent_key the field's parent key + * @param array $config the field's config + * @param array $sections Aeria's sections config + * @param array $index index for multiple fields + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct($parent_key, $config, $sections, $index); + /** + * Gets the field's value + * + * @param array $saved_fields the FieldGroup's saved fields + * @param bool $skip_filter whether to skip or not WP's filter + * + * @return mixed the field's value + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function get(array $saved_fields, bool $skip_filter); + /** + * Gets the field's value and its errors + * + * @param array $saved_fields the FieldGroup's saved fields + * @param array $errors the saving errors + * + * @return array the field's config, hydrated with values and errors + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getAdmin(array $saved_fields, array $errors); + /** + * Saves the new values to the fields. + * + * @param int $context_ID the context ID. For posts, post's ID + * @param string $context_type the context type. Right now, options|meta + * @param array $saved_fields the saved fields + * @param array $new_values the values we're saving + * @param Validator $validator_service Aeria's validator service + * @param Query $query_service Aeria's query service + * + * @return array the results of the saving + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function set($context_ID, $context_type, array $saved_fields, array $new_values, $validator_service, $query_service); } diff --git a/Aeria/Field/ServiceProviders/FieldProvider.php b/Aeria/Field/ServiceProviders/FieldProvider.php index 7248732..b57e26e 100755 --- a/Aeria/Field/ServiceProviders/FieldProvider.php +++ b/Aeria/Field/ServiceProviders/FieldProvider.php @@ -5,17 +5,44 @@ use Aeria\Container\Interfaces\ServiceProviderInterface; use Aeria\Field\FieldsRegistry; use Aeria\Container\Container; - +/** + * FieldProvider is in charge of registering the Field singleton to the container + * + * @category Field + * @package Aeria + * @author Andrea Longo + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class FieldProvider implements ServiceProviderInterface { + /** + * 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('field', FieldsRegistry::class); } - + /** + * In charge of booting the service. Field doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { - return true; + return true; } } diff --git a/Aeria/Kernel/AbstractClasses/Task.php b/Aeria/Kernel/AbstractClasses/Task.php index 1ff80bb..a62f176 100644 --- a/Aeria/Kernel/AbstractClasses/Task.php +++ b/Aeria/Kernel/AbstractClasses/Task.php @@ -3,12 +3,31 @@ namespace Aeria\Kernel\AbstractClasses; use Aeria\Kernel\Exceptions\CallableNotDefinedException; - +/** + * This class describes what a Kernel task looks like + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ abstract class Task { public $priority; public $admin_only; - + /** + * The main task method. This is what the task does. + * + * @param array $args the arguments to be passed to the Task + * + * @return mixed the returned value + * @throws CallableNotDefinedException in case this abstract was used + * as a real class + * + * @access public + * @since Method available since Release 3.0.0 + */ public function do(array $args) { throw new CallableNotDefinedException(); diff --git a/Aeria/Kernel/Exceptions/CallableNotDefinedException.php b/Aeria/Kernel/Exceptions/CallableNotDefinedException.php index 9198085..793bf46 100644 --- a/Aeria/Kernel/Exceptions/CallableNotDefinedException.php +++ b/Aeria/Kernel/Exceptions/CallableNotDefinedException.php @@ -1,7 +1,15 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CallableNotDefinedException extends \Exception { } diff --git a/Aeria/Kernel/Kernel.php b/Aeria/Kernel/Kernel.php index 841f96f..3f7c7b3 100644 --- a/Aeria/Kernel/Kernel.php +++ b/Aeria/Kernel/Kernel.php @@ -5,11 +5,28 @@ 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 + */ 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); @@ -18,7 +35,16 @@ public function register(Task $task) $this->set($key, $task); } - // Booter + /** + * 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 @@ -35,14 +61,24 @@ public function boot(Container $container) ]; $tasks = $this->all(); uasort($tasks, array($this, 'compareTasks')); - foreach ($tasks as $task){ + foreach ($tasks as $task) { if(is_admin() && $task->admin_only) $task->do($args); else if (!$task->admin_only) $task->do($args); } } - + /** + * 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) diff --git a/Aeria/Kernel/Loader.php b/Aeria/Kernel/Loader.php index 5b9d3db..2e554c7 100644 --- a/Aeria/Kernel/Loader.php +++ b/Aeria/Kernel/Loader.php @@ -8,17 +8,49 @@ use \Exception; - +/** + * Loader is the class in charge of fetching configuration files from your theme. + * + * @category Config + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Loader { + /** + * This method loads a config + * + * @param Config $config the config to be loaded + * @param Container $container our container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function loadConfig(Config $config, Container $container) { - $root_path = $config->getRootPath(); + $root_paths = $config->getRootPath(); $render_service = $container->make('render_engine'); - static::recursiveLoad($config, $root_path, $render_service); + foreach ($root_paths as $root_path) { + static::recursiveLoad($config, $root_path, $render_service); + } } - + /** + * This method recursively loads the views for the renderer + * + * @param string $base_path the base path of the view + * @param Render $render_service the render service to load the views to + * @param string $context the context of the file + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function loadViews($base_path, $render_service, $context = '') { $new_base_path = static::joinPaths($base_path, $context); @@ -40,6 +72,19 @@ function ($path) { return $path !== '.' && $path !== '..'; } } } } + /** + * This method recursively loads the configs + * + * @param Config $config the config to be passed to loadSettings + * @param string $base_path the base path of the view + * @param Render $render_service the render service to load the views to + * @param string $context the context of the file + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function recursiveLoad( Config $config, string $base_path, @@ -96,7 +141,18 @@ function () use ($absolute_path, $render_service) { } } } - + /** + * This method loads settings from a config + * + * @param Config $config the fetched config + * @param string $file_path the file path + * @param string $context the context of the file + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ private static function loadSettings(Config $config, string $file_path, string $context) { $parsed_file = $config-> @@ -107,16 +163,27 @@ private static function loadSettings(Config $config, string $file_path, string $ $name = $parsed_file['name']; $spec_list = $parsed_file['spec']; $kind = $parsed_file['kind']; + $enabled = isset($parsed_file['enabled']) ? $parsed_file['enabled'] : true; $namespace = $kind == 'controller' || $kind == 'route' ? "global.{$kind}.{$name}" : "aeria.{$kind}.{$name}"; - - $config-> - { Config::getLoaderMethod($config->getDriverInUse($file_path)) }( - $spec_list, - $namespace - ); + if ($enabled) { + $config-> + { Config::getLoaderMethod($config->getDriverInUse($file_path)) }( + $spec_list, + $namespace + ); + } } + /** + * This method joins paths + * + * @return string joined paths + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ private static function joinPaths() { $args = func_get_args(); diff --git a/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php b/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php index ef780d7..e972d98 100755 --- a/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php +++ b/Aeria/Kernel/ServiceProviders/KernelServiceProvider.php @@ -21,14 +21,43 @@ CreateUpdater }; - +/** + * 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 + */ class KernelServiceProvider implements ServiceProviderInterface { + /** + * 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 + * kernel. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { $kernel = $container->make('kernel'); diff --git a/Aeria/Kernel/Tasks/CreateControllers.php b/Aeria/Kernel/Tasks/CreateControllers.php index 0593692..99170dd 100644 --- a/Aeria/Kernel/Tasks/CreateControllers.php +++ b/Aeria/Kernel/Tasks/CreateControllers.php @@ -4,12 +4,29 @@ use Aeria\Kernel\AbstractClasses\Task; - +/** + * This task is in charge of creating controllers. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreateControllers extends Task { public $priority = 8; public $admin_only = false; - + /** + * The main task method. It registers the controllers to Aeria. + * + * @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) { if (isset($args['config']['global']['controller'])) { diff --git a/Aeria/Kernel/Tasks/CreateField.php b/Aeria/Kernel/Tasks/CreateField.php index 98a3818..686271e 100644 --- a/Aeria/Kernel/Tasks/CreateField.php +++ b/Aeria/Kernel/Tasks/CreateField.php @@ -3,12 +3,29 @@ 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 + */ class CreateField 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 + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function do(array $args) { $args['service']['field']->register('base', \Aeria\Field\Fields\BaseField::class); @@ -19,6 +36,8 @@ public function do(array $args) $args['service']['field']->register('select', \Aeria\Field\Fields\SelectField::class); $args['service']['field']->register('switch', \Aeria\Field\Fields\SwitchField::class); $args['service']['field']->register('relation', \Aeria\Field\Fields\RelationField::class); + $args['service']['field']->register('maps', \Aeria\Field\Fields\MapField::class); + $args['service']['field']->register('daterange', \Aeria\Field\Fields\DateRangeField::class); // example of multiple registered fields with the same handler; not // really needed in this case, as they use the default BaseField, but // colud be useful; `register` accepts a third value: `override`. @@ -29,8 +48,10 @@ public function do(array $args) $args['service']['field']->register('number', \Aeria\Field\Fields\BaseField::class); $args['service']['field']->register('email', \Aeria\Field\Fields\BaseField::class); $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']); } -} \ No newline at end of file +} diff --git a/Aeria/Kernel/Tasks/CreateMeta.php b/Aeria/Kernel/Tasks/CreateMeta.php index 71a551f..4455cdd 100644 --- a/Aeria/Kernel/Tasks/CreateMeta.php +++ b/Aeria/Kernel/Tasks/CreateMeta.php @@ -5,12 +5,29 @@ use Aeria\Kernel\AbstractClasses\Task; use Aeria\Meta\Meta; - +/** + * This task is in charge of creating Metaboxes. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreateMeta extends Task { public $priority = 4; public $admin_only = true; - + /** + * The main task method. It registers the metaboxes and sections. + * + * @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) { if (isset($args['config']['aeria']['meta'])) { @@ -31,7 +48,7 @@ function () use ($meta_config, $args, $section_config) { ); } ); - add_action('save_post', Meta::save($meta_config, $_POST, $args['service']['validator'], $args['service']['query'], $section_config), 10, 2); + add_action('save_post', Meta::save($meta_config, $_POST, $args['service']['validator'], $args['service']['query'], $section_config, $args['service']['render_engine']), 10, 2); } add_action( diff --git a/Aeria/Kernel/Tasks/CreateOptions.php b/Aeria/Kernel/Tasks/CreateOptions.php index 776ca38..c15a8f0 100644 --- a/Aeria/Kernel/Tasks/CreateOptions.php +++ b/Aeria/Kernel/Tasks/CreateOptions.php @@ -4,12 +4,29 @@ use Aeria\Kernel\AbstractClasses\Task; - +/** + * This task is in charge of creating options pages. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreateOptions extends Task { public $priority = 6; public $admin_only = true; - + /** + * The main task method. It registers the option pages. + * + * @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) { $default_icon_data = file_get_contents(dirname(__DIR__, 2).'/aeria.svg'); diff --git a/Aeria/Kernel/Tasks/CreatePostType.php b/Aeria/Kernel/Tasks/CreatePostType.php index bd3450f..30ab865 100644 --- a/Aeria/Kernel/Tasks/CreatePostType.php +++ b/Aeria/Kernel/Tasks/CreatePostType.php @@ -4,12 +4,29 @@ use Aeria\Kernel\AbstractClasses\Task; - +/** + * This task is in charge of creating custom post types. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreatePostType extends Task { public $priority = 1; public $admin_only = false; - + /** + * The main task method. It registers the post types. + * + * @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) { if (isset($args['config']['aeria']['post-type'])) { diff --git a/Aeria/Kernel/Tasks/CreateRenderer.php b/Aeria/Kernel/Tasks/CreateRenderer.php index 27076bc..cd2c6f7 100644 --- a/Aeria/Kernel/Tasks/CreateRenderer.php +++ b/Aeria/Kernel/Tasks/CreateRenderer.php @@ -5,12 +5,29 @@ use Aeria\Kernel\AbstractClasses\Task; use Aeria\Kernel\Loader; - +/** + * This task is in charge of creating renderers. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreateRenderer extends Task { public $priority = 7; public $admin_only = false; - + /** + * The main task method. It loads the views from the files. + * + * @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) { foreach ($args['service']['render_engine']->getRootPaths() as $root_path) { diff --git a/Aeria/Kernel/Tasks/CreateRouter.php b/Aeria/Kernel/Tasks/CreateRouter.php index 493f338..50c4d4b 100644 --- a/Aeria/Kernel/Tasks/CreateRouter.php +++ b/Aeria/Kernel/Tasks/CreateRouter.php @@ -5,12 +5,30 @@ use Aeria\Kernel\AbstractClasses\Task; use Aeria\Router\Factory\RouteFactory; - +/** + * This task is in charge of creating the router and its routes. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreateRouter extends Task { public $priority = 9; public $admin_only = false; - + /** + * The main task method. It registers various routes, the default ones + * and the custom ones. + * + * @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) { $args['service']['router']->get( diff --git a/Aeria/Kernel/Tasks/CreateTaxonomy.php b/Aeria/Kernel/Tasks/CreateTaxonomy.php index 0360918..d2acb67 100644 --- a/Aeria/Kernel/Tasks/CreateTaxonomy.php +++ b/Aeria/Kernel/Tasks/CreateTaxonomy.php @@ -4,12 +4,29 @@ use Aeria\Kernel\AbstractClasses\Task; - +/** + * This task is in charge of creating the taxonomies. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreateTaxonomy extends Task { public $priority = 3; public $admin_only = false; - + /** + * The main task method. It registers the needed taxonomies. + * + * @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) { if (isset($args['config']['aeria']['taxonomy'])) { diff --git a/Aeria/Kernel/Tasks/CreateUpdater.php b/Aeria/Kernel/Tasks/CreateUpdater.php index 4bb0e39..d9606e8 100644 --- a/Aeria/Kernel/Tasks/CreateUpdater.php +++ b/Aeria/Kernel/Tasks/CreateUpdater.php @@ -3,12 +3,29 @@ namespace Aeria\Kernel\Tasks; use Aeria\Kernel\AbstractClasses\Task; - +/** + * This task is in charge of creating the updater service. + * + * @category Kernel + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CreateUpdater extends Task { public $priority = 5; public $admin_only = true; - + /** + * The main task method. It registers the updater service and its infos. + * + * @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) { $args['service']['updater']->config( diff --git a/Aeria/Meta/Meta.php b/Aeria/Meta/Meta.php index 605905c..1e16c0b 100755 --- a/Aeria/Meta/Meta.php +++ b/Aeria/Meta/Meta.php @@ -7,12 +7,27 @@ use Aeria\Field\FieldError; use Aeria\Meta\MetaProcessor; use Aeria\RenderEngine\RenderEngine; - +/** + * Meta is in charge of creating, saving and rendering metaboxes + * + * @category Meta + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Meta implements ValidateConfInterface { use ValidateConfTrait; protected $sections; - + /** + * Returns a validation structure for meta configs + * + * @return array the validation structure + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getValidationStructure() : array { return [ @@ -21,7 +36,18 @@ public function getValidationStructure() : array ) ]; } - + /** + * Creates the requested metaboxes + * + * @param array $config the Meta configs + * @param array $sections the sections configuration + * @param RenderEngine $render_service the service in charge of rendering HTML + * + * @return array the field's values, an array containing the gallery's children + * + * @access public + * @since Method available since Release 3.0.0 + */ public function create($config, $sections, $render_service) { $this->validate($config); @@ -36,7 +62,17 @@ public function create($config, $sections, $render_service) ["config" => $config,"sections"=> $sections, "render_service" => $render_service] ); } - + /** + * Validates the meta configuration + * + * @param array $conf the Meta configuration to validate + * + * @return void + * @throws ConfigValidationException in case of an invalid config + * + * @access private + * @since Method available since Release 3.0.0 + */ private function validate($conf) { $exception = $this->isValid($conf); @@ -44,7 +80,16 @@ private function validate($conf) throw $exception; } } - + /** + * Returns the required fields to get a WP nonce + * + * @param WP_Post $post current post object + * + * @return array the nonce fields + * + * @access private + * @since Method available since Release 3.0.0 + */ private static function nonceIDs($post) { return [ @@ -52,7 +97,18 @@ private static function nonceIDs($post) 'field' => 'update_aeria_meta' ]; } - + /** + * Calls the render service to render HTML + * + * @param WP_Post $post the current post object + * @param array $extra other required data to render HTML + * + * @return void + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ static function renderHTML($post, $extra) { $metabox = $extra["args"]["config"]; @@ -60,42 +116,57 @@ static function renderHTML($post, $extra) $render_service = $extra["args"]["render_service"]; $nonceIDs = static::nonceIDs($post); wp_nonce_field($nonceIDs['action'], $nonceIDs['field']); - $processor = new MetaProcessor($post->ID, $metabox, $sections); + $processor = new MetaProcessor($post->ID, $metabox, $sections, $render_service); $metabox["fields"] = $processor->getAdmin(); ?> render('meta_template', - [ - "metabox" => $metabox - ]); + $render_service->render( + 'meta_template', + [ + "metabox" => $metabox + ] + ); } - - public static function save($metabox, $newValues, $validator_service, $query_service, $sections) + /** + * Saves the new metadata to WP + * + * @param array $metabox the metabox configuration + * @param array $new_values the values fetched from $_POST + * @param Validator $validator_service the validation service for fields + * @param Query $query_service the required query service + * @param array $sections the sections configuration + * + * @return void + * @throws ConfigValidationException in case of an invalid config + * + * @access public + * @since Method available since Release 3.0.0 + */ + public static function save($metabox, $new_values, $validator_service, $query_service, $sections, $render_service) { - return function ($post_id,$post) use ($metabox, $newValues, $validator_service, $query_service, $sections) { + return function ($post_id,$post) use ($metabox, $new_values, $validator_service, $query_service, $sections, $render_service) { // Since this function is triggered when a post is created too, I'm gonna skip it in that case. I'm gonna skip it even if the post_Type is not supported. - if ($newValues==[] || !in_array($post->post_type, $metabox["post_type"])) { + if ($new_values==[] || !in_array($post->post_type, $metabox["post_type"])) { return $post_id; } $nonceIDs = static::nonceIDs($post); - $post_type_object = get_post_type_object($newValues['post_type']); + $post_type_object = get_post_type_object($new_values['post_type']); - // TODO: Check if current post type is supported: in the 1.0, the supported fields were hardcoded to ['post'] - if((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) - || (empty($newValues['post_ID']) || empty($newValues['post_type'])) - || (!isset($newValues['post_ID']) || $post_id != $newValues['post_ID']) - || (!check_admin_referer($nonceIDs['action'], $nonceIDs['field'])) - || (!current_user_can($post_type_object->cap->edit_post, $post_id)) - )return $post_id; + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) + || (empty($new_values['post_ID']) || empty($new_values['post_type'])) + || (!isset($new_values['post_ID']) || $post_id != $new_values['post_ID']) + || (!check_admin_referer($nonceIDs['action'], $nonceIDs['field'])) + || (!current_user_can($post_type_object->cap->edit_post, $post_id)) + ) return $post_id; - $processor = new MetaProcessor($post_id, $metabox, $sections, $newValues); + $processor = new MetaProcessor($post_id, $metabox, $sections, $render_service, $new_values); $processor->set( - $validator_service, - $query_service + $validator_service, + $query_service ); FieldError::make($post_id) diff --git a/Aeria/Meta/MetaProcessor.php b/Aeria/Meta/MetaProcessor.php index 1781f72..425353b 100644 --- a/Aeria/Meta/MetaProcessor.php +++ b/Aeria/Meta/MetaProcessor.php @@ -3,14 +3,39 @@ namespace Aeria\Meta; use Aeria\Field\FieldGroupProcessor; - +/** + * MetaProcessor is a wrapper for FieldGroupProcessor + * + * @category Meta + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class MetaProcessor extends FieldGroupProcessor { - public function getType(){ - return "meta"; + /** + * Returns the FieldGroupProcessor type + * + * @return string the type = "meta" + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getType() + { + return "meta"; } - - public function getSavedFields(){ - return get_post_meta($this->id); + /** + * Gets the saved fields from a post + * + * @return array the saved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getSavedFields() + { + return get_post_meta($this->id); } } diff --git a/Aeria/Meta/ServiceProviders/MetaProvider.php b/Aeria/Meta/ServiceProviders/MetaProvider.php index d868e5e..e94838d 100755 --- a/Aeria/Meta/ServiceProviders/MetaProvider.php +++ b/Aeria/Meta/ServiceProviders/MetaProvider.php @@ -5,17 +5,45 @@ use Aeria\Container\Interfaces\ServiceProviderInterface; use Aeria\Meta\Meta; use Aeria\Container\Container; - +/** + * MetaProvider is in charge of registering the Meta service to the container + * + * @category Meta + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class MetaProvider implements ServiceProviderInterface { + /** + * Registers the service to the provided container + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(Container $container) { $container->bind('meta', Meta::class); } + /** + * In charge of booting the service. Meta doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { - return true; + return true; } } diff --git a/Aeria/OptionsPage/OptionsPage.php b/Aeria/OptionsPage/OptionsPage.php index 2cc438a..9396935 100644 --- a/Aeria/OptionsPage/OptionsPage.php +++ b/Aeria/OptionsPage/OptionsPage.php @@ -5,37 +5,72 @@ use Aeria\OptionsPage\OptionsPageProcessor; use Aeria\Field\FieldError; use Aeria\RenderEngine\RenderEngine; - +/** + * OptionsPage is in charge of generating pages in WP's options + * + * @category Options + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class OptionsPage { - private $optionPages = []; - - private static function nonceIDs($config) + private $option_pages = []; + /** + * Returns the required fields to get a WP nonce + * + * @return array the nonce fields + * + * @access private + * @static + * @since Method available since Release 3.0.0 + */ + private static function nonceIDs() { return [ 'action' => 'update-', 'field' => 'update_aeria_settings' ]; } - - public function register($optionPage) + /** + * Registers an options page + * + * @param array $option_page the options page configuration + * + * @return null + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function register($option_page) { // Check if all the required fields are available - if(isset($optionPage["title"]) - &&isset($optionPage["menu_title"]) - &&isset($optionPage["capability"]) - &&isset($optionPage["menu_slug"]) - &&isset($optionPage["config"]) - &&isset($optionPage["sections"]) - &&isset($optionPage["validator_service"]) - &&isset($optionPage["query_service"]) + if(isset($option_page["title"]) + &&isset($option_page["menu_title"]) + &&isset($option_page["capability"]) + &&isset($option_page["menu_slug"]) + &&isset($option_page["config"]) + &&isset($option_page["sections"]) + &&isset($option_page["validator_service"]) + &&isset($option_page["query_service"]) ) - $this->optionPages[]=$optionPage; + $this->optionPages[]=$option_page; return null; } - - public function boot ($aeriaConfig, $render_service) + /** + * Registers the saved options pages to WP + * + * @param array $aeria_config the full configuration for Aeria + * @param RenderEngine $render_service the service in charge of rendering HTML + * + * @return array the nonce fields + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function boot($aeria_config, $render_service) { $default_icon_data = file_get_contents(dirname(__DIR__).'/aeria.svg'); $default_icon = 'data:image/svg+xml;base64,'.base64_encode($default_icon_data); @@ -56,10 +91,10 @@ public function boot ($aeriaConfig, $render_service) "Editor", "manage_options", "aeria_options", - function () use ($aeriaConfig, $render_service) { + function () use ($aeria_config, $render_service) { static::renderHTML( "aeria_editor", - $aeriaConfig, + $aeria_config, $render_service ); } @@ -92,7 +127,8 @@ function () use ($singleOptionPage, $render_service) { $singleOptionPage["config"], $singleOptionPage["validator_service"], $singleOptionPage["query_service"], - $singleOptionPage["sections"] + $singleOptionPage["sections"], + $render_service ); } static::renderHTML( @@ -107,7 +143,22 @@ function () use ($singleOptionPage, $render_service) { ); } } - + /** + * Calls the render service to render HTML + * + * @param string $id the option page ID + * @param array $config the options page configuration + * @param RenderEngine $render_service the service in charge of rendering HTML + * @param Validator $validator_service the validation service for the fields + * @param Query $query_service the required query service + * @param array $sections the sections configuration + * + * @return void + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function renderHTML($id, $config, $render_service, $validator_service = null, $query_service = null, $sections = null) { if ($id == "aeria_editor") { @@ -119,8 +170,8 @@ public static function renderHTML($id, $config, $render_service, $validator_serv ); return null; } - $nonceIDs = static::nonceIDs($config); - $processor = new OptionsPageProcessor($id, $config, $sections); + $nonceIDs = static::nonceIDs(); + $processor = new OptionsPageProcessor($id, $config, $sections, $render_service); $config["fields"] = $processor->getAdmin(); $render_service->render( 'option_template', @@ -131,14 +182,28 @@ public static function renderHTML($id, $config, $render_service, $validator_serv ); } - - public static function save($id, $metabox, $validator_service, $query_service, $sections) + /** + * Saves the new data to WP + * + * @param string $id the options page ID + * @param array $metabox the metabox configuration + * @param Validator $validator_service the validation service for fields + * @param Query $query_service the required query service + * @param array $sections the sections configuration + * + * @return void + * @throws ConfigValidationException in case of an invalid config + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function save($id, $metabox, $validator_service, $query_service, $sections, $render_service) { - if ($_POST==[]) - { - return null; - } - $nonceIDs = static::nonceIDs($metabox); + if ($_POST==[]) { + return null; + } + $nonceIDs = static::nonceIDs(); if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || !check_admin_referer($nonceIDs['action'], $nonceIDs['field']) @@ -146,7 +211,7 @@ public static function save($id, $metabox, $validator_service, $query_service, $ { return null; } - $processor = new OptionsPageProcessor($id, $metabox, $sections, $_POST); + $processor = new OptionsPageProcessor($id, $metabox, $sections, $render_service, $_POST); $processor->set( $validator_service, $query_service diff --git a/Aeria/OptionsPage/OptionsPageProcessor.php b/Aeria/OptionsPage/OptionsPageProcessor.php index 2ede186..6b39df6 100644 --- a/Aeria/OptionsPage/OptionsPageProcessor.php +++ b/Aeria/OptionsPage/OptionsPageProcessor.php @@ -4,14 +4,39 @@ use Aeria\Field\FieldGroupProcessor; - +/** + * OptionsPageProcessor is a wrapper for FieldGroupProcessor + * + * @category Options + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class OptionsPageProcessor extends FieldGroupProcessor { - public function getType(){ - return "options"; + /** + * Returns the FieldGroupProcessor type + * + * @return string the type = "options" + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getType() + { + return "options"; } - - public function getSavedFields(){ - return wp_load_alloptions(); + /** + * Gets the saved options from WP + * + * @return array the saved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getSavedFields() + { + return wp_load_alloptions(); } } diff --git a/Aeria/OptionsPage/ServiceProviders/OptionsPageServiceProvider.php b/Aeria/OptionsPage/ServiceProviders/OptionsPageServiceProvider.php index 994dd53..d4b405e 100644 --- a/Aeria/OptionsPage/ServiceProviders/OptionsPageServiceProvider.php +++ b/Aeria/OptionsPage/ServiceProviders/OptionsPageServiceProvider.php @@ -5,13 +5,43 @@ use Aeria\Container\Interfaces\ServiceProviderInterface; use Aeria\Container\Container; use Aeria\OptionsPage\OptionsPage; - +/** + * OptionsPageServiceProvider is in charge of registering the options service + * to the container + * + * @category Options + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class OptionsPageServiceProvider implements ServiceProviderInterface { + /** + * Registers the service to the provided container + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(Container $container) { $container->bind('options', OptionsPage::class); } + + /** + * In charge of booting the service. Options doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container):bool { return true; diff --git a/Aeria/PostType/Exceptions/AlreadyExistingPostTypeException.php b/Aeria/PostType/Exceptions/AlreadyExistingPostTypeException.php index ba2e959..afdee96 100755 --- a/Aeria/PostType/Exceptions/AlreadyExistingPostTypeException.php +++ b/Aeria/PostType/Exceptions/AlreadyExistingPostTypeException.php @@ -3,7 +3,16 @@ namespace Aeria\PostType\Exceptions; use Exception; - +/** + * AlreadyExistingPostTypeException gets thrown when the user tries to add + * an existent post type + * + * @category PostType + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class AlreadyExistingPostTypeException extends Exception { diff --git a/Aeria/PostType/Exceptions/MissingModelException.php b/Aeria/PostType/Exceptions/MissingModelException.php index 5af4ad0..688d95d 100755 --- a/Aeria/PostType/Exceptions/MissingModelException.php +++ b/Aeria/PostType/Exceptions/MissingModelException.php @@ -3,7 +3,15 @@ namespace Aeria\PostType\Exceptions; use Exception; - +/** + * MissingModelException gets thrown when Aeria is missing the model + * + * @category PostType + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class MissingModelException extends Exception { diff --git a/Aeria/PostType/Exceptions/NoPostTypeException.php b/Aeria/PostType/Exceptions/NoPostTypeException.php index 1f6d3f8..2ad7020 100755 --- a/Aeria/PostType/Exceptions/NoPostTypeException.php +++ b/Aeria/PostType/Exceptions/NoPostTypeException.php @@ -3,7 +3,15 @@ namespace Aeria\PostType\Exceptions; use Exception; - +/** + * NoPostTypeException gets thrown when Aeria looks for an unregistered post type + * + * @category PostType + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class NoPostTypeException extends Exception { diff --git a/Aeria/PostType/Exceptions/WordpressPostTypeException.php b/Aeria/PostType/Exceptions/WordpressPostTypeException.php index 99065df..c0c9bff 100755 --- a/Aeria/PostType/Exceptions/WordpressPostTypeException.php +++ b/Aeria/PostType/Exceptions/WordpressPostTypeException.php @@ -3,16 +3,35 @@ namespace Aeria\PostType\Exceptions; use Exception; - +/** + * WordpressPostTypeException gets thrown when WP throws an exception + * + * @category PostType + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class WordpressPostTypeException extends Exception { - public function __construct(WP_Error $wp_error, string $contextMessage) + /** + * Contructs the exception from the WP one + * + * @param WP_Error $wp_error the WP's exception + * @param string $context_message the message + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct(WP_Error $wp_error, string $context_message) { $code = $wp_error->get_error_code(); $message = " WP_Code: {$error_code}, WP_Message: {$wp_error->get_error_message($code)}, - Context_Message: {$contextMessage} + Context_Message: {$context_message} "; parent::__construct($message, $code); } diff --git a/Aeria/PostType/Interfaces/PostTypeModelInterface.php b/Aeria/PostType/Interfaces/PostTypeModelInterface.php index 48ad4db..96f3b9c 100755 --- a/Aeria/PostType/Interfaces/PostTypeModelInterface.php +++ b/Aeria/PostType/Interfaces/PostTypeModelInterface.php @@ -1,8 +1,27 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface PostTypeModelInterface { + /** + * Registers a post type + * + * @param string $name the post type's name + * @param array $settings the configuration + * + * @return bool succesful or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function registerPostType(string $name, array $settings) : bool; } \ No newline at end of file diff --git a/Aeria/PostType/PostType.php b/Aeria/PostType/PostType.php index 0834003..b914e22 100755 --- a/Aeria/PostType/PostType.php +++ b/Aeria/PostType/PostType.php @@ -12,11 +12,26 @@ }; use Aeria\Config\Traits\ValidateConfTrait; use Aeria\Container\Interfaces\ValidateConfInterface; - +/** + * PostType is the service in charge of registering post types + * + * @category PostType + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class PostType implements ValidateConfInterface { use ValidateConfTrait; - + /** + * Returns a validation structure for post type configs + * + * @return array the validation structure + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getValidationStructure() : array { return [ @@ -25,7 +40,18 @@ public function getValidationStructure() : array ) ]; } - + /** + * Creates the requested post types + * + * @param array $post_type the post type's configuration + * + * @return WP_Post_Type the registered post type object + * @throws AlreadyExistingPostTypeException if the post type already exists + * @throws WordpressPostTypeException if WP fails + * + * @access public + * @since Method available since Release 3.0.0 + */ public function create($post_type) { $this->validate($post_type); @@ -50,7 +76,16 @@ public function create($post_type) return $post_type; } - + /** + * Gets the requested post type object + * + * @param string $post_type the post type ID + * + * @return WP_Post_Type the requested post type + * + * @access public + * @since Method available since Release 3.0.0 + */ public function get(string $post_type) { $post_type_obj = get_post_type_object($post_type); @@ -62,20 +97,49 @@ public function get(string $post_type) return $post_type_obj; } - + /** + * Checks if a post type exists + * + * @param string $post_type the post type ID + * + * @return bool whether it exists or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function exists(string $post_type) { return post_type_exists($post_type); } - + /** + * Validates the post type configuration + * + * @param array $conf the post type's configuration + * + * @return void + * @throws ConfigValidationException if the configuration is invalid + * + * @access private + * @since Method available since Release 3.0.0 + */ private function validate($conf) { - $exeption = $this->isValid($conf); - if (!is_null($exeption)) { - throw $exeption; + $exception = $this->isValid($conf); + if (!is_null($exception)) { + throw $exception; } } - + /** + * Helper function. Removes an element from an array + * + * @param string $key the requested key to delete + * @param array $array the array to work on + * + * @return array the filtered array + * + * @access private + * @since Method available since Release 3.0.0 + */ private function removeKeyFrom(string $key, array $array) { return array_filter( diff --git a/Aeria/PostType/ServiceProviders/PostTypeProvider.php b/Aeria/PostType/ServiceProviders/PostTypeProvider.php index 9f42dda..0878717 100755 --- a/Aeria/PostType/ServiceProviders/PostTypeProvider.php +++ b/Aeria/PostType/ServiceProviders/PostTypeProvider.php @@ -7,16 +7,44 @@ use Aeria\Container\Container; use Aeria\Config\Config; use Aeria\PostType\Models\PostTypeModel; - +/** + * PostTypeProvider is in charge of registering the post type service + * to the container + * + * @category PostType + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class PostTypeProvider implements ServiceProviderInterface { + /** + * Registers the service to the provided container + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(Container $container) { $container->bind('post_type', PostType::class); } - + /** + * In charge of booting the service. PostType doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { - return true; + return true; } } diff --git a/Aeria/Query/Query.php b/Aeria/Query/Query.php index 506375e..b78a5ed 100644 --- a/Aeria/Query/Query.php +++ b/Aeria/Query/Query.php @@ -7,10 +7,19 @@ class Query { protected $queries; - - public function deleteMeta ($post_id, $key) + /** + * Deletes a meta from a post + * + * @param int $post_id required post ID + * @param string $key custom meta's key + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function deleteMeta($post_id, $key) { - global $wpdb; $wpdb->query( $wpdb->prepare( @@ -21,9 +30,18 @@ public function deleteMeta ($post_id, $key) } - public function deleteOption ($key) + /** + * Deletes an option from WP settings + * + * @param string $key custom meta's key + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function deleteOption($key) { - global $wpdb; $wpdb->query( $wpdb->prepare( @@ -31,10 +49,19 @@ public function deleteOption ($key) WHERE option_name LIKE %s", $key."%" ) ); - } - + /** + * Gets the saved post types + * + * @param array $parameters the additional query parameters - check + * WP codex to know more + * + * @return array of the post types + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getPostTypes($parameters) { $searchField = (isset($parameters['s'])) ? $parameters['s'] : null; @@ -53,7 +80,17 @@ public function getPostTypes($parameters) } return $response; } - + /** + * Gets the saved taxonomies + * + * @param array $parameters the additional query parameters - check + * WP codex to know more + * + * @return array of the taxonomies + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getTaxonomies($parameters) { $searchField = (isset($parameters['s'])) ? $parameters['s'] : ""; @@ -62,14 +99,24 @@ public function getTaxonomies($parameters) $taxonomies = get_taxonomies([], 'objects'); $response = []; foreach ($taxonomies as $index => $taxonomy) { - if ((preg_match('/'.$searchField.'/', $taxonomy->name)&&((in_array($postType, $taxonomy->object_type)) || $postType == "") || $searchField=="")){ + if ((preg_match('/'.$searchField.'/', $taxonomy->name)&&((in_array($postType, $taxonomy->object_type)) || $postType == "") || $searchField=="")) { $response[$index]["label"] = $taxonomy->labels->name; $response[$index]["value"] = $taxonomy->name; } } return $response; } - + /** + * Gets the requested posts + * + * @param array $parameters the additional query parameters - check + * WP codex to know more + * + * @return array of the requested posts + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getPosts($parameters) { $searchField = (isset($parameters["s"])) ? $parameters["s"] : null; @@ -113,20 +160,41 @@ public function getPosts($parameters) ]; $posts = get_posts($args); $response=[]; - foreach ($posts as $index => $post){ + foreach ($posts as $index => $post) { $postArray = $post->to_array(); - foreach($postParams as $thePostParam){ + foreach ($postParams as $thePostParam) { $response[$index][$responseParams[$thePostParam]]=$postArray[$thePostParam]; } } return $response; } - - public function register ($name, $querier) + /** + * Registers a new query + * + * @param array $parameters the additional query parameters - check + * WP codex to know more + * + * @return array of the requested posts + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function register($name, $querier) { $this->queries[$name]=$querier; } - + /** + * Overrides php __call. If the function is present in the class prototypes, it + * gets called. + * + * @param string $name the function name + * @param array $args the arguments to be passed to the function + * + * @return mixed the callable return value + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __call($name, $args) { global $wpdb; diff --git a/Aeria/Query/ServiceProviders/QueryServiceProvider.php b/Aeria/Query/ServiceProviders/QueryServiceProvider.php index ef7fc07..37e2e9e 100644 --- a/Aeria/Query/ServiceProviders/QueryServiceProvider.php +++ b/Aeria/Query/ServiceProviders/QueryServiceProvider.php @@ -6,15 +6,42 @@ use Aeria\Container\Container; use Aeria\Query\Query; - - +/** + * QueryServiceProvider is in charge of registering the query service + * to the container + * + * @category Query + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class QueryServiceProvider implements ServiceProviderInterface { + /** + * 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('query', Query::class); } - + /** + * In charge of booting the service. Query doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { return true; diff --git a/Aeria/RenderEngine/AbstractClasses/ViewAbstract.php b/Aeria/RenderEngine/AbstractClasses/ViewAbstract.php index 9035921..fc479c6 100644 --- a/Aeria/RenderEngine/AbstractClasses/ViewAbstract.php +++ b/Aeria/RenderEngine/AbstractClasses/ViewAbstract.php @@ -4,24 +4,68 @@ use Aeria\RenderEngine\Interfaces\Renderable; +/** + * ViewAbstract describes a View class and its methods + * + * @category Render + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ abstract class ViewAbstract implements Renderable { protected $view_path; - + /** + * Renders the php to the current page + * + * @param array $data provides the needed data to the page + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function render(array $data) { include $this->view_path; } - + /** + * Sets the view's path + * + * @param string $path the new path for the view + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function setPath(string $path) { $this->view_path = $path; } + /** + * Gets the view's path + * + * @return string the view path + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getPath():string { return $this->view_path; } - + /** + * This class needs to be implemented in subclasses + * It provides the view's name + * + * @return void + * @throws Exception if the method is not implemented in the subclass + * + * @access public + * @since Method available since Release 3.0.0 + */ public function name():string { throw new Exception("Missing name implementation."); diff --git a/Aeria/RenderEngine/Interfaces/Renderable.php b/Aeria/RenderEngine/Interfaces/Renderable.php index e123d9b..c420c81 100644 --- a/Aeria/RenderEngine/Interfaces/Renderable.php +++ b/Aeria/RenderEngine/Interfaces/Renderable.php @@ -2,13 +2,57 @@ namespace Aeria\RenderEngine\Interfaces; +/** + * Renderable describes how a renderable class is made + * + * @category Render + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface Renderable { - + /** + * Renders the php to the current page + * + * @param array $data provides the needed data to the page + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function render(array $data); - + /** + * Sets the view's path + * + * @param string $path the new path for the view + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function setPath(string $path); + /** + * Gets the view's path + * + * @return string the view path + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getPath():string; - + /** + * This class needs to be implemented in subclasses + * It provides the view's name + * + * @return void + * @throws Exception if the method is not implemented in the subclass + * + * @access public + * @since Method available since Release 3.0.0 + */ public function name():string; } \ No newline at end of file diff --git a/Aeria/RenderEngine/RenderEngine.php b/Aeria/RenderEngine/RenderEngine.php index 33b0054..60ab76e 100644 --- a/Aeria/RenderEngine/RenderEngine.php +++ b/Aeria/RenderEngine/RenderEngine.php @@ -7,21 +7,47 @@ use Aeria\RenderEngine\Exceptions\RendererNotAvailableException; use Aeria\Config\Config; use Aeria\Structure\Traits\DictionaryTrait; - -class RenderEngine +/** + * RenderEngine is in charge of rendering views + * + * @category Render + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class RenderEngine { use DictionaryTrait { DictionaryTrait::__construct as instanciateDictionary; } private $root_paths = []; - + /** + * Constructs the Render service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct() { $this->instanciateDictionary(); $this->addRootPath(dirname(__DIR__, 2)."/Resources/Templates"); } - + /** + * Renders the specified view + * + * @param string $mode is the view name + * @param array $extras are the required data for the view + * + * @return void + * @throws \Exception when the view doesn't exist + * + * @access public + * @since Method available since Release 3.0.0 + */ public function render($mode, $extras) { try{ @@ -33,17 +59,42 @@ public function render($mode, $extras) echo "Unable to render template: ".$mode."-".$e->getMessage(); } } - + /** + * Registers a new view to the RenderEngine + * + * @param Renderable $view the view object + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(Renderable $view) { $this->set($view->name(), $view); } - + /** + * Returns the RenderEngine root paths, i.e. where it looks for views + * + * @return array the root paths + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getRootPaths() { return $this->root_paths; } - + /** + * Adds a new path to the root paths + * + * @param string $root_path the path we want to add + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function addRootPath(string $root_path) { $this->root_paths[]=$root_path; diff --git a/Aeria/RenderEngine/ServiceProviders/RenderEngineServiceProvider.php b/Aeria/RenderEngine/ServiceProviders/RenderEngineServiceProvider.php index edf853f..0ade023 100644 --- a/Aeria/RenderEngine/ServiceProviders/RenderEngineServiceProvider.php +++ b/Aeria/RenderEngine/ServiceProviders/RenderEngineServiceProvider.php @@ -6,13 +6,42 @@ use Aeria\Meta\Meta; use Aeria\Container\Container; use Aeria\RenderEngine\RenderEngine; - +/** + * RenderEngineServiceProvider is in charge of registering the render service + * to the container + * + * @category Render + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class RenderEngineServiceProvider implements ServiceProviderInterface { + /** + * 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('render_engine', RenderEngine::class); } + /** + * In charge of booting the service. RenderEngine doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container):bool { return true; diff --git a/Aeria/RenderEngine/ViewFactory.php b/Aeria/RenderEngine/ViewFactory.php index 3a3f979..06cd96c 100644 --- a/Aeria/RenderEngine/ViewFactory.php +++ b/Aeria/RenderEngine/ViewFactory.php @@ -4,8 +4,27 @@ use Aeria\RenderEngine\Views\CoreView; +/** + * ViewFactory makes CoreView objects from a view path + * + * @category Render + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ViewFactory { + /** + * Creates a CoreView object from a view file + * + * @param string $view_path the file's path + * + * @return CoreView the view object + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function make($view_path) { $core_view = new CoreView(); diff --git a/Aeria/RenderEngine/Views/CoreView.php b/Aeria/RenderEngine/Views/CoreView.php index 4b3d81b..307724b 100644 --- a/Aeria/RenderEngine/Views/CoreView.php +++ b/Aeria/RenderEngine/Views/CoreView.php @@ -4,8 +4,25 @@ use Aeria\RenderEngine\AbstractClasses\ViewAbstract; +/** + * CoreView is a simple view, which renders a php file + * + * @category Render + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class CoreView extends ViewAbstract { + /** + * Returns the view's name, generated by snakecasing the filename + * + * @return string the view name + * + * @access public + * @since Method available since Release 3.0.0 + */ public function name():string { if (preg_match_all( @@ -14,7 +31,7 @@ public function name():string $matches ) ) { - return toSnake($matches[3][0]); + return toSnake(basename($this->view_path, '.php')); } else { throw new Exception("Unable to get filename for file: ".$this->view_path); } diff --git a/Aeria/Router/Controller.php b/Aeria/Router/Controller.php index ace9eb6..627724e 100644 --- a/Aeria/Router/Controller.php +++ b/Aeria/Router/Controller.php @@ -4,16 +4,43 @@ use Aeria\Router\Request; +/** + * Controller describes a controller and its methods + * + * @category Query + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ abstract class Controller { protected $request; - + /** + * Contructs the controller + * + * @param Request $request the controller's request + * + * @return void + * + * @access public + * @final + * @since Method available since Release 3.0.0 + */ public final function __construct(Request $request) { $this->request = $request; } - + /** + * Returns the controller prefix + * + * @return string the prefix = "aeria" + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getPrefix(): string { return 'aeria'; diff --git a/Aeria/Router/ControllerRegister.php b/Aeria/Router/ControllerRegister.php index ec0f692..a9e662e 100644 --- a/Aeria/Router/ControllerRegister.php +++ b/Aeria/Router/ControllerRegister.php @@ -3,26 +3,66 @@ namespace Aeria\Router; use Aeria\Structure\Traits\DictionaryTrait; - +/** + * ControllerRegister manages a register of controllers + * + * @category Router + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ControllerRegister { use DictionaryTrait; - + /** + * Registers a controller to the register + * + * @param string $namespace the controller's namespace + * + * @return void + * @throws \Exception when the controller was already registered + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(string $namespace) { $name = $this->classNameFromNamespace($namespace); if ($this->exists($name)) { - throw new \Exception("The controller named {$name} has been already registered"); + throw new \Exception("The controller named {$name} has been already registered"); } $this->set($name, $namespace); } - + /** + * Helper method that gets the classname + * + * @param string $namespace the controller's namespace + * + * @return void + * + * @access private + * @since Method available since Release 3.0.0 + */ private function classNameFromNamespace(string $namespace): string { $list = explode('\\', $namespace); return $list[\count($list) - 1]; } - + /** + * Calls a method on a controller + * + * @param Request $request the request object + * @param string $name the controller name + * @param string $method the method name + * + * @return mixed the method's response + * @throws \Exception if the controller isn't found + * @throws \Exception if the controller doesn't provide the requested method + * + * @access public + * @since Method available since Release 3.0.0 + */ public function callOn(Request $request, string $name, string $method) { if (!$this->exists($name)) { @@ -36,7 +76,16 @@ public function callOn(Request $request, string $name, string $method) } return $controller->{$method}(); } - + /** + * Get a prefix from a controller + * + * @param string $name the controller's name + * + * @return string the controller prefix + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getControllerPrefix(string $name) { if (!$this->exists($name)) { diff --git a/Aeria/Router/Exceptions/InvalidRouteConfigException.php b/Aeria/Router/Exceptions/InvalidRouteConfigException.php index 3683d7f..aa58626 100644 --- a/Aeria/Router/Exceptions/InvalidRouteConfigException.php +++ b/Aeria/Router/Exceptions/InvalidRouteConfigException.php @@ -2,9 +2,28 @@ namespace Aeria\Router\Exceptions; +/** + * InvalidRouteConfigException gets thrown when the user provides + * an invalid route configuration + * + * @category Router + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class InvalidRouteConfigException extends \Exception { - + /** + * Constructs the exception with a message + * + * @param array $config the route configuration + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct(array $config = []) { $json = json_encode($config); diff --git a/Aeria/Router/Factory/RouteFactory.php b/Aeria/Router/Factory/RouteFactory.php index cfb57e2..feecae6 100644 --- a/Aeria/Router/Factory/RouteFactory.php +++ b/Aeria/Router/Factory/RouteFactory.php @@ -5,15 +5,34 @@ use Aeria\Router\Route; use Aeria\Router\Request; use Aeria\Router\Exceptions\InvalidRouteConfigException; - +/** + * RouteFactory provides Route objects for a route configuration + * + * @category Router + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class RouteFactory { + /** + * Makes a new Route object from a config + * + * @param array $config the route's configuration + * + * @return Route the object + * @throws InvalidRouteConfigException when an invalid config is provided + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function make(array $config) { - if ( - !isset($config['path']) || - !isset($config['method']) || - !isset($config['handler']) + if (!isset($config['path']) + || !isset($config['method']) + || !isset($config['handler']) ) { throw new InvalidRouteConfigException($config); } @@ -36,7 +55,18 @@ function (Request $request) use ($controller_register, $parsed) { } return $route; } - + /** + * Helper method that gets name and method from a handler + * + * @param string $handler the config handler + * + * @return array composed of name and method + * @throws \Exception when it can't find a name and method + * + * @access private + * @static + * @since Method available since Release 3.0.0 + */ private static function getNameAndMethodFromHandler(string $handler) { $match; diff --git a/Aeria/Router/Request.php b/Aeria/Router/Request.php index 8adb8bd..ee2832b 100644 --- a/Aeria/Router/Request.php +++ b/Aeria/Router/Request.php @@ -3,12 +3,29 @@ namespace Aeria\Router; use \WP_REST_Request; - +/** + * Request is a wrapper for WP_REST_Request + * + * @category Router + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Request { public $wp_request; - + /** + * Constructs a new Request + * + * @param WP_REST_Request $wp_request the request + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct(WP_REST_Request $wp_request) { $this->wp_request = $wp_request; diff --git a/Aeria/Router/Route.php b/Aeria/Router/Route.php index d078342..8a2f77a 100644 --- a/Aeria/Router/Route.php +++ b/Aeria/Router/Route.php @@ -3,7 +3,15 @@ namespace Aeria\Router; use Aeria\Router\Request; - +/** + * Route describes a REST route + * + * @category Router + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Route { protected $method; @@ -11,6 +19,20 @@ class Route protected $path; protected $prefix; + /** + * Constructs a new Route + * + * @param string $path the route path + * @param string $method the API method + * @param Closure $callback the API method + * + * @return void + * @throws \Exception if an invalid callback is provided + * @throws \Exception if the provided method isn't accepted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct($path, $method = 'GET', $callback = null) { if (!is_callable($callback)) { @@ -24,7 +46,14 @@ public function __construct($path, $method = 'GET', $callback = null) $this->callback = $callback; $this->prefix = 'aeria'; } - + /** + * Registers the route + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register() { register_rest_route( @@ -40,12 +69,28 @@ public function register() ] ); } - + /** + * Returns the route prefix + * + * @return string the prefix + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getPrefix(): string { return $this->prefix; } - + /** + * Sets the route prefix + * + * @param string $prefix the desired prefix + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function setPrefix(string $prefix) { $this->prefix = $prefix; diff --git a/Aeria/Router/Router.php b/Aeria/Router/Router.php index a43915d..7d0bc4c 100644 --- a/Aeria/Router/Router.php +++ b/Aeria/Router/Router.php @@ -7,68 +7,133 @@ use Aeria\Router\ControllerRegister; use Aeria\Router\Factory\RouteFactory; +/** + * Router handles the registration of routes + * + * @category Router + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Router { private $routes = []; - + /** + * Makes a new GET request + * + * @param string $path the request path + * @param string $handler the function callable + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function get($path, $handler) { $this->register( RouteFactory::make( - [ - 'path' => $path, - 'method' => 'GET', - 'handler' => $handler - ] + [ + 'path' => $path, + 'method' => 'GET', + 'handler' => $handler + ] ) ); } - + /** + * Makes a new POST request + * + * @param string $path the request path + * @param string $handler the function callable + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function post($path, $handler) { $this->register( RouteFactory::make( - [ - 'path' => $path, - 'method' => 'POST', - 'handler' => $handler - ] + [ + 'path' => $path, + 'method' => 'POST', + 'handler' => $handler + ] ) ); } - + /** + * Makes a new PUT request + * + * @param string $path the request path + * @param string $handler the function callable + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function put($path, $handler) { $this->register( RouteFactory::make( - [ - 'path' => $path, - 'method' => 'PUT', - 'handler' => $handler - ] + [ + 'path' => $path, + 'method' => 'PUT', + 'handler' => $handler + ] ) ); } - + /** + * Makes a new DELETE request + * + * @param string $path the request path + * @param string $handler the function callable + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function delete($path, $handler) { $this->register( RouteFactory::make( - [ - 'path' => $path, - 'method' => 'DELETE', - 'handler' => $handler - ] + [ + 'path' => $path, + 'method' => 'DELETE', + 'handler' => $handler + ] ) ); } - + /** + * Registers a new Route object + * + * @param Route $route the new route + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(Route $route) { $this->routes[] = $route; } - + /** + * Registers the routes to WordPress + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot() { $routes=$this->routes; diff --git a/Aeria/Router/ServiceProviders/ControllerServiceProvider.php b/Aeria/Router/ServiceProviders/ControllerServiceProvider.php index f25ceb4..9b4a5fd 100644 --- a/Aeria/Router/ServiceProviders/ControllerServiceProvider.php +++ b/Aeria/Router/ServiceProviders/ControllerServiceProvider.php @@ -5,14 +5,42 @@ use Aeria\Container\Interfaces\ServiceProviderInterface; use Aeria\Container\Container; use Aeria\Router\ControllerRegister; - +/** + * ControllerServiceProvider is in charge of registering the controller service + * to the container + * + * @category Router + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ControllerServiceProvider implements ServiceProviderInterface { + /** + * 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('controller', ControllerRegister::class); } - + /** + * In charge of booting the service. Controller doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { return true; diff --git a/Aeria/Router/ServiceProviders/RouterServiceProvider.php b/Aeria/Router/ServiceProviders/RouterServiceProvider.php index 900edc4..89fec9e 100644 --- a/Aeria/Router/ServiceProviders/RouterServiceProvider.php +++ b/Aeria/Router/ServiceProviders/RouterServiceProvider.php @@ -6,13 +6,42 @@ use Aeria\Container\Container; use Aeria\Router\Router; +/** + * RouterServiceProvider is in charge of registering the router service + * to the container + * + * @category Router + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class RouterServiceProvider implements ServiceProviderInterface { + /** + * 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('router', Router::class); } - + /** + * In charge of booting the service. Router doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { return true; diff --git a/Aeria/Structure/Interfaces/TransientableInterface.php b/Aeria/Structure/Interfaces/TransientableInterface.php index 6df6595..e0456f7 100644 --- a/Aeria/Structure/Interfaces/TransientableInterface.php +++ b/Aeria/Structure/Interfaces/TransientableInterface.php @@ -2,8 +2,38 @@ namespace Aeria\Structure\Interfaces; +/** + * TransientableInterface describes objects that can be saved to a transient + * + * @category Structure + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ interface TransientableInterface { + /** + * Saves the current object to a transient + * + * @param string $key the key to save the object with + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function saveTransient(string $key); + /** + * Decodes a saved transient + * + * @param string $key the key the object was saved with + * + * @return mixed the object + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function decodeTransient(string $key); } diff --git a/Aeria/Structure/Map.php b/Aeria/Structure/Map.php index 115bea7..d7cc677 100755 --- a/Aeria/Structure/Map.php +++ b/Aeria/Structure/Map.php @@ -8,32 +8,79 @@ class Map implements JsonSerializable { protected $fields = []; - + /** + * Constructs the Map + * + * @param array $fields initial fields + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct(/* ?array */ $fields = null) // : void { if ($fields) { $this->load($fields); } } - - public function &all() { + /** + * Returns the complete dictionary + * + * @return array the saved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function &all() + { return $this->fields; } - + /** + * Gets a specific value by key + * + * @param string $key the searched key + * @param mixed $default an optional default value + * + * @return mixed the searched element + * + * @access public + * @since Method available since Release 3.0.0 + */ public function get($key, $default = null) // : mixed { $element =& $this->find($key); return (!is_null($element)) ? $element : $default; } - + /** + * Sets a specific value by its key + * + * @param string $key the value's key + * @param mixed $value the setted value + * + * @return bool whether the value was saved or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function set(string $key, /* mixed */ $value) : bool { $element =& $this->find($key, true); $element = is_callable($value) ? call_user_func($value) : $value; return true; } - + /** + * Deletes a specific value by its key + * + * @param string $key the value's key + * @param bool $compact whether the map has to be compacted + * + * @return mixed the searched element + * + * @access public + * @since Method available since Release 3.0.0 + */ public function delete(string $key, bool $compact = true) : bool { $result = $this->set($key, null); @@ -44,30 +91,71 @@ public function delete(string $key, bool $compact = true) : bool return $result; } - + /** + * Checks if a specific key exists + * + * @param string $key the value's key + * + * @return bool whether the value exists + * + * @access public + * @since Method available since Release 3.0.0 + */ public function exists(string $key) : bool { return !is_null($this->find($key)); } - + /** + * Clears the map + * + * @return bool whether the clearing was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function clear() : bool { $this->fields = []; return true; } - + /** + * Loads the input fields + * + * @param array $fields the fields we want to load + * + * @return bool whether the loading was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function load(array $fields) : bool { $this->fields = $fields; return true; } - + /** + * Merges the inserted fields with the existing ones + * + * @param array $array the fields we want to merge + * + * @return bool whether the merging was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function merge(array $array) : bool { $this->fields = array_replace_recursive($this->fields, $array); return true; } - + /** + * Compacts the map + * + * @return bool whether the compacting was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function compact() : bool { $callback = function ($element) { @@ -78,7 +166,18 @@ public function compact() : bool return true; } - + /** + * Helper function: recursively compacts arrays + * + * @param array $input the array to compact + * @param callable $callback the function to be called on the array + * + * @return array the compacted array + * + * @access protected + * @static + * @since Method available since Release 3.0.0 + */ protected static function compact_array_filter( array $input, /* ?callable */ $callback = null @@ -91,7 +190,17 @@ protected static function compact_array_filter( return array_filter($input, $callback); } - + /** + * Finds pointers to the requested elements + * + * @param string $key_path the key path + * @param bool $create whether the fields have to be editable + * + * @return mixed the found fields + * + * @access public + * @since Method available since Release 3.0.0 + */ public function &find(string $key_path, bool $create = false) // : mixed { if ($create) { @@ -113,7 +222,14 @@ public function &find(string $key_path, bool $create = false) // : mixed return $fields; } - + /** + * Serializes the dictionary into a JSON object + * + * @return array the serialized object + * + * @access public + * @since Method available since Release 3.0.0 + */ public function jsonSerialize() : array { return $this->fields; diff --git a/Aeria/Structure/Node.php b/Aeria/Structure/Node.php index ae3e423..49b8a0f 100644 --- a/Aeria/Structure/Node.php +++ b/Aeria/Structure/Node.php @@ -2,21 +2,56 @@ namespace Aeria\Structure; +/** + * Node describes a Tree node + * + * @category Structure + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ abstract class Node { private $children = []; - + /** + * Adds a child to the Node + * + * @param mixed $child a node that is a child of this one + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function addChild($child) { $this->children[] = $child; } - - public function shouldBeChildOf(Node $possibleParent) + /** + * This method is needed when saving children + * + * @param Node $possible_parent the possible parent we're checking + * + * @return bool whether the node is a possible parent or not + * @throws \Exception if the method wasn't implemented in subclasses + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function shouldBeChildOf(Node $possible_parent) { throw new Exception('You should implement this method!'); } - - public function getChildren () + /** + * Returns the node children + * + * @return array the node's children + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function getChildren() { return $this->children; } diff --git a/Aeria/Structure/RootNode.php b/Aeria/Structure/RootNode.php index c74e952..7507b73 100644 --- a/Aeria/Structure/RootNode.php +++ b/Aeria/Structure/RootNode.php @@ -3,9 +3,18 @@ namespace Aeria\Structure; use Aeria\Structure\Node; +/** + * The RootNode is a node that has no parents + * + * @category Structure + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class RootNode extends Node { - public function shouldBeChildOf(Node $possibleParent) + public function shouldBeChildOf(Node $possible_parent) { return false; } diff --git a/Aeria/Structure/Traits/DictionaryTrait.php b/Aeria/Structure/Traits/DictionaryTrait.php index 571d307..794326d 100755 --- a/Aeria/Structure/Traits/DictionaryTrait.php +++ b/Aeria/Structure/Traits/DictionaryTrait.php @@ -3,56 +3,149 @@ namespace Aeria\Structure\Traits; use Aeria\Structure\Map; - +/** + * This trait gives the possibility of saving a dictionary of key-values + * + * @category Container + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ trait DictionaryTrait { protected $map; - + /** + * Constructs the Map + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct() // : void { $this->map = new Map(); } - + /** + * Returns the complete dictionary + * + * @return Map all the saved values + * + * @access public + * @since Method available since Release 3.0.0 + */ public function &all() : array { return $this->map->all(); } - + /** + * Gets a specific value by key + * + * @param string $key the searched key + * @param mixed $default an optional default value + * + * @return mixed the searched element + * + * @access public + * @since Method available since Release 3.0.0 + */ public function get(string $key, $default = null) // : mixed { return $this->map->get($key, $default); } - + /** + * Sets a specific value by its key + * + * @param string $key the value's key + * @param mixed $value the setted value + * + * @return mixed the searched element + * + * @access public + * @since Method available since Release 3.0.0 + */ public function set(string $key, $value) : bool { return $this->map->set($key, $value); } - + /** + * Deletes a specific value by its key + * + * @param string $key the value's key + * @param mixed $compact whether the map has to be compacted + * + * @return mixed the searched element + * + * @access public + * @since Method available since Release 3.0.0 + */ public function delete(string $key, bool $compact = true) : bool { return $this->map->delete($key, $compact); } - + /** + * Checks if a specific key exists + * + * @param string $key the value's key + * + * @return bool whether the value exists + * + * @access public + * @since Method available since Release 3.0.0 + */ public function exists($key) : bool { return $this->map->exists($key); } - + /** + * Clears the dictionary + * + * @return bool whether the clearing was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function clear() : bool { return $this->map->clear(); } - + /** + * Loads the input fields + * + * @param array $fields the fields we want to load + * + * @return bool whether the loading was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function load($fields) : bool { return $this->map->load($fields); } - + /** + * Merges the inserted fields with the existing ones + * + * @param array $array the fields we want to merge + * + * @return bool whether the merging was done correctly + * + * @access public + * @since Method available since Release 3.0.0 + */ public function merge(array $array) : bool { return $this->map->merge($array); } - + /** + * Serializes the dictionary into a JSON object + * + * @return array the serialized object + * + * @access public + * @since Method available since Release 3.0.0 + */ public function jsonSerialize() : array { return $this->map->jsonSerialize(); diff --git a/Aeria/Structure/Traits/ExtensibleTrait.php b/Aeria/Structure/Traits/ExtensibleTrait.php index a6043db..eff3fbb 100755 --- a/Aeria/Structure/Traits/ExtensibleTrait.php +++ b/Aeria/Structure/Traits/ExtensibleTrait.php @@ -1,12 +1,33 @@ + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ trait ExtensibleTrait { static protected $class_prototypes = []; - + /** + * Overrides php __call. If the function is present in the class prototypes, it + * gets called. + * + * @param string $function_name the function name + * @param array $function_args the arguments to be passed to the function + * + * @return mixed the callable return value + * + * @access public + * @final + * @since Method available since Release 3.0.0 + */ final public function __call(string $function_name, array $function_args) { if (is_callable(static::$class_prototypes[$function_name])) { @@ -15,7 +36,20 @@ final public function __call(string $function_name, array $function_args) return parent::__call($function_name, $function_args); } - + /** + * Overrides php __callStatic. If the function is present in the class prototypes, it + * gets called. + * + * @param string $function_name the function name + * @param array $function_args the arguments to be passed to the function + * + * @return mixed the callable return value + * + * @access public + * @static + * @final + * @since Method available since Release 3.0.0 + */ final public static function __callStatic(string $function_name, array $function_args) { if (is_callable(static::$class_prototypes[$function_name])) { @@ -24,13 +58,32 @@ final public static function __callStatic(string $function_name, array $function return parent::__callStatic($function_name, $function_args); } - + /** + * Extends the saved functions with the provided callable + * + * @param string $method_name the provided method name + * @param callable $callback the callable of the function + * + * @return bool the function was succesfully added + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function extend(string $method_name, callable $callback) : bool { static::$class_prototypes[$method_name] = $callback; return true; } - + /** + * Checks whether the provided methods extend the saved functions + * + * @param array $methods_names the provided method name + * + * @return bool the function was succesfully added + * + * @access public + * @since Method available since Release 3.0.0 + */ public static function extends(array $methods_names) : bool { foreach ($methods_names as $method_name => $callback) { diff --git a/Aeria/Structure/Traits/Transientable.php b/Aeria/Structure/Traits/Transientable.php index ae9c79b..afaa7a6 100644 --- a/Aeria/Structure/Traits/Transientable.php +++ b/Aeria/Structure/Traits/Transientable.php @@ -2,16 +2,43 @@ namespace Aeria\Structure\Traits; +/** + * The Transientable trait allows a class to be saved to a transient + * + * @category Structure + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ trait Transientable { - + /** + * Saves the current object to a transient + * + * @param string $key the key to save the object with + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function saveTransient(string $key) { $serialized = serialize($this); - set_transient($key, $serialized, 600); } - + /** + * Decodes a saved transient + * + * @param string $key the key the object was saved with + * + * @return mixed the object + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function decodeTransient(string $key) { $serialized = get_transient($key); diff --git a/Aeria/Structure/Tree.php b/Aeria/Structure/Tree.php index 8227f3c..ca1ad07 100644 --- a/Aeria/Structure/Tree.php +++ b/Aeria/Structure/Tree.php @@ -5,17 +5,41 @@ use Aeria\Structure\Node; use Aeria\Structure\RootNode; - +/** + * The Tree is a structure composed of nodes + * + * @category Structure + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Tree { protected $root; - + /** + * Constructs a new Tree + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct() { $this->root = new RootNode(); } - + /** + * Inserts a new node to the Tree + * + * @param Node $node the inserted node + * + * @return Tree this tree + * + * @access public + * @since Method available since Release 3.0.0 + */ public function insert(Node $node) { @@ -25,29 +49,57 @@ public function insert(Node $node) } return $this; } - + /** + * Checks if a node has to be children of another one + * + * @param Node $parent the parent node + * @param Node $node the node we're inserting + * + * @return bool whether the adding was done correctly + * + * @access private + * @since Method available since Release 3.0.0 + */ private function recursiveInsert($parent, $node) { - foreach ($parent->getChildren() as $possibleParent) { - if ($node->shouldBeChildOf($possibleParent)) { - $possibleParent->addChild($node); + foreach ($parent->getChildren() as $possible_parent) { + if ($node->shouldBeChildOf($possible_parent)) { + $possible_parent->addChild($node); return true; } } - foreach ($parent->getChildren() as $possibleParent) { - if($this->recursiveInsert($possibleParent, $node)) + foreach ($parent->getChildren() as $possible_parent) { + if($this->recursiveInsert($possible_parent, $node)) return true; } return false; } - + /** + * Executes a method on every node + * + * @param callable $method the function we want to execute + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function executeOnNodes($method) { foreach ($this->recursiveReader($this->root) as $child) { $method($child); } } - + /** + * Recursively reads the children of a node + * + * @param Node $parent the requested parent + * + * @return array the found nodes + * + * @access private + * @since Method available since Release 3.0.0 + */ private function recursiveReader($parent) { $children = []; diff --git a/Aeria/Taxonomy/Exceptions/AlreadyExistingTaxonomyException.php b/Aeria/Taxonomy/Exceptions/AlreadyExistingTaxonomyException.php index 256da50..ad62c8a 100755 --- a/Aeria/Taxonomy/Exceptions/AlreadyExistingTaxonomyException.php +++ b/Aeria/Taxonomy/Exceptions/AlreadyExistingTaxonomyException.php @@ -3,7 +3,16 @@ namespace Aeria\Taxonomy\Exceptions; use Exception; - +/** + * AlreadyExistingTaxonomyException gets thrown when the user tries to add + * an existent taxonomy + * + * @category Taxonomy + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class AlreadyExistingTaxonomyException extends Exception { diff --git a/Aeria/Taxonomy/Exceptions/WordpressTaxonomyException.php b/Aeria/Taxonomy/Exceptions/WordpressTaxonomyException.php index 87db678..d9638f4 100755 --- a/Aeria/Taxonomy/Exceptions/WordpressTaxonomyException.php +++ b/Aeria/Taxonomy/Exceptions/WordpressTaxonomyException.php @@ -4,15 +4,35 @@ use Exception; +/** + * WordpressTaxonomyException gets thrown when WP throws an exception + * + * @category Taxonomy + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class WordpressTaxonomyException extends Exception { - public function __construct(WP_Error $wp_error, string $contextMessage) + /** + * Contructs the exception from the WP one + * + * @param WP_Error $wp_error the WP's exception + * @param string $context_message the message + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct(WP_Error $wp_error, string $context_message) { $code = $wp_error->get_error_code(); $message = " WP_Code: {$error_code}, WP_Message: {$wp_error->get_error_message($code)}, - Context_Message: {$contextMessage} + Context_Message: {$context_message} "; parent::__construct($message, $code); } diff --git a/Aeria/Taxonomy/ServiceProviders/TaxonomyProvider.php b/Aeria/Taxonomy/ServiceProviders/TaxonomyProvider.php index 0678415..0c15a57 100755 --- a/Aeria/Taxonomy/ServiceProviders/TaxonomyProvider.php +++ b/Aeria/Taxonomy/ServiceProviders/TaxonomyProvider.php @@ -6,16 +6,45 @@ use Aeria\Taxonomy\Taxonomy; use Aeria\Container\Container; +/** + * TaxonomyProvider is in charge of registering the taxonomy service + * to the container + * + * @category Taxonomy + * @package Aeria + * @author Jacopo Martinelli + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class TaxonomyProvider implements ServiceProviderInterface { + /** + * Registers the service to the provided container + * + * @param Container $container Aeria's container + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function register(Container $container) { $container->bind('taxonomy', Taxonomy::class); } - + /** + * In charge of booting the service. Taxonomy doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { - return true; + return true; } } diff --git a/Aeria/Taxonomy/Taxonomy.php b/Aeria/Taxonomy/Taxonomy.php index 8c76bb3..35fc700 100755 --- a/Aeria/Taxonomy/Taxonomy.php +++ b/Aeria/Taxonomy/Taxonomy.php @@ -7,10 +7,26 @@ use Aeria\Taxonomy\Exceptions\AlreadyExistingTaxonomyException; use Aeria\Taxonomy\Exceptions\WordpressTaxonomyException; +/** + * Taxonomy is the service in charge of registering post types + * + * @category Taxonomy + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Taxonomy implements ValidateConfInterface { use ValidateConfTrait; - + /** + * Returns a validation structure for taxonomy configs + * + * @return array the validation structure + * + * @access public + * @since Method available since Release 3.0.0 + */ public function getValidationStructure() : array { $namespace = Taxonomy::class; @@ -24,14 +40,32 @@ public function getValidationStructure() : array ) ]; } - + /** + * Checks if a post type exists + * + * @return void + * @throws \Exception if the post type doesn't exist + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ static function validateThatPostTypeExist(string $post_type_name) { if (!post_type_exists($post_type_name)) { - throw new Exception("Post type '{$post_type_name}' do not exsist"); + throw new \Exception("Post type '{$post_type_name}' do not exsist"); } } - + /** + * Creates a new taxonomy + * + * @return WP_Taxonomy the taxonomy + * @throws AlreadyExistingTaxonomyException if the taxonomy already exists + * @throws WordpressTaxonomyException if WP throws an exception + * + * @access public + * @since Method available since Release 3.0.0 + */ public function create($taxonomy) { $this->validate($taxonomy); @@ -57,17 +91,34 @@ public function create($taxonomy) return $taxonomy_obj; } - + /** + * Checks if a taxonomy exists + * + * @return bool whether the taxonomy exists or not + * + * @access public + * @since Method available since Release 3.0.0 + */ public function exists(array $taxonomy) : bool { return taxonomy_exists($taxonomy['taxonomy']); } - + /** + * Validates a taxonomy configuration + * + * @param array $conf the taxonomy configuration + * + * @return void + * @throws ConfigValidationException if the config is invalid + * + * @access private + * @since Method available since Release 3.0.0 + */ private function validate($conf) { - $exeption = $this->isValid($conf); - if (!is_null($exeption)) { - throw $exeption; + $exception = $this->isValid($conf); + if (!is_null($exception)) { + throw $exception; } } } diff --git a/Aeria/Updater/ServiceProviders/UpdaterServiceProvider.php b/Aeria/Updater/ServiceProviders/UpdaterServiceProvider.php index 6f30ea4..2ea8740 100644 --- a/Aeria/Updater/ServiceProviders/UpdaterServiceProvider.php +++ b/Aeria/Updater/ServiceProviders/UpdaterServiceProvider.php @@ -5,14 +5,42 @@ use Aeria\Container\Container; use Aeria\Updater\Updater; - +/** + * UpdaterServiceProvider is in charge of registering the updater service + * to the container + * + * @category PostType + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class UpdaterServiceProvider implements ServiceProviderInterface { + /** + * 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('updater', Updater::class); } - + /** + * In charge of booting the service. Updater doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { return true; diff --git a/Aeria/Updater/Updater.php b/Aeria/Updater/Updater.php index f3ec2a8..220cec2 100644 --- a/Aeria/Updater/Updater.php +++ b/Aeria/Updater/Updater.php @@ -1,147 +1,225 @@ config = $config; - } - - private function getPluginData(){ - if(isset($this->pluginData)) +/** + * The Updater is in charge of checking updates on the GitHub repo + * + * @category Updater + * @package Aeria + * @author Alberto Parziale + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class Updater +{ + /** + * Constructs the Updater object + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct() { - return $this->pluginData; + // define the alternative API for updating checking + add_filter("pre_set_site_transient_update_plugins", array($this, "checkVersion")); + // Define the alternative response for information checking + add_filter("plugins_api", array($this, "setPluginInfo"), 10, 3); + // reactivate plugin + add_filter("upgrader_post_install", array($this, "postInstall"), 10, 3); } + /** + * Saves the provided config + * + * @param array $config the configuration + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function config($config) + { + $this->config = $config; + } + /** + * Gets the plugin data from plugin.php + * + * @return mixed the plugin data + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function getPluginData() + { + if (isset($this->pluginData)) { + return $this->pluginData; + } - include_once ABSPATH.'/wp-admin/includes/plugin.php'; - - $this->pluginData = get_plugin_data( WP_PLUGIN_DIR.'/'.$this->config["slug"]); - - $githubUrl = parse_url($this->pluginData["PluginURI"]); - $githubInfo = explode('/', $githubUrl['path']); - - $this->github = [ - "user" => $githubInfo[1], - "repository" => $githubInfo[2] - ]; - } + include_once ABSPATH.'/wp-admin/includes/plugin.php'; - private function getRepoReleaseInfo() { - // Only do this once - if ( !empty( $this->githubAPIResult ) ) { - return; - } + $this->pluginData = get_plugin_data(WP_PLUGIN_DIR.'/'.$this->config["slug"]); - $transient = get_transient( "{$this->github["user"]}_{$this->github["repository"]}_transient_update"); - if($transient !== false){ - return $transient; - } - // Query the GitHub API - $url = "https://api.github.com/repos/{$this->github["user"]}/{$this->github["repository"]}/releases"; - // We need the access token for private repos - if ( !empty( $this->config["access_token"] ) ) { - $url = add_query_arg( array( "access_token" => $this->config["access_token"] ), $url ); - } + $githubUrl = parse_url($this->pluginData["PluginURI"]); + $githubInfo = explode('/', $githubUrl['path']); - // Get the results - $this->githubAPIResult = wp_remote_retrieve_body( wp_remote_get( $url ) ); - if ( !empty( $this->githubAPIResult ) ) { - $this->githubAPIResult = @json_decode( $this->githubAPIResult ); + $this->github = [ + "user" => $githubInfo[1], + "repository" => $githubInfo[2] + ]; } - // Use only the latest release - if ( is_array( $this->githubAPIResult ) ) { - $this->githubAPIResult = $this->githubAPIResult[0]; + /** + * Gets the release infos from the GitHub repo + * + * @return mixed|void a transient or nothing + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function getRepoReleaseInfo() + { + //Only do this once + if (!empty($this->githubAPIResult)) { + return; + } + + $transient = get_transient("{$this->github["user"]}_{$this->github["repository"]}_transient_update"); + if ($transient !== false) { + return $transient; + } + // Query the GitHub API + $url = "https://api.github.com/repos/{$this->github["user"]}/{$this->github["repository"]}/releases"; + // We need the access token for private repos + if (!empty($this->config["access_token"])) { + $url = add_query_arg(array("access_token" => $this->config["access_token"]), $url); + } + + // Get the results + $this->githubAPIResult = wp_remote_retrieve_body(wp_remote_get($url)); + if (!empty($this->githubAPIResult)) { + $this->githubAPIResult = @json_decode($this->githubAPIResult); + } + // Use only the latest release + if (is_array($this->githubAPIResult)) { + $this->githubAPIResult = $this->githubAPIResult[0]; + } + set_transient("{$this->github["user"]}_{$this->github["repository"]}_transient_update", $this->githubAPIResult, 3.600); } - set_transient( "{$this->github["user"]}_{$this->github["repository"]}_transient_update", $this->githubAPIResult, 3.600 ); - } - - public function checkVersion( $transient ) { - if ( !empty( $transient ) && empty( $transient->checked ) ) + /** + * Compares the current version to the installed one + * + * @param mixed $transient the updates transient + * + * @return mixed the transient + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function checkVersion($transient) { - return $transient; + if (!empty($transient) && empty($transient->checked)) { + return $transient; + } + + // Get plugin & GitHub release information + $this->getPluginData(); + $this->getRepoReleaseInfo(); + + if (!isset($this->githubAPIResult->tag_name)) { + return $transient; + } + $doUpdate = version_compare($this->githubAPIResult->tag_name, $transient->checked[$this->config['slug']]); + + if ($doUpdate == 1) { + $package = $this->githubAPIResult->zipball_url; + // Include the access token for private GitHub repos + if (!empty($this->config["access_token"])) { + $package = add_query_arg(array( "access_token" => $this->config["access_token"]), $package); + } + + $obj = new \StdClass(); + $obj->slug = $this->config["slug"]; + $obj->new_version = $this->githubAPIResult->tag_name; + $obj->url = $this->pluginData["PluginURI"]; + $obj->package = $package; + $obj->plugin = $this->config["slug"]; + $obj->icons = ['1x' => '/wp-content/plugins/aeria/Aeria/aeria-transparent.png']; + $transient->response[$this->config["slug"]] = $obj; + } + return $transient; } - // Get plugin & GitHub release information - $this->getPluginData(); - $this->getRepoReleaseInfo(); - - if(!isset($this->githubAPIResult->tag_name)){ - return $transient; - } - $doUpdate = version_compare( $this->githubAPIResult->tag_name, $transient->checked[$this->config['slug']] ); - - if ( $doUpdate == 1 ) { - $package = $this->githubAPIResult->zipball_url; - // Include the access token for private GitHub repos - if ( !empty( $this->config["access_token"] ) ) { - $package = add_query_arg( array( "access_token" => $this->config["access_token"] ), $package ); - } - - $obj = new \StdClass(); - $obj->slug = $this->config["slug"]; - $obj->new_version = $this->githubAPIResult->tag_name; - $obj->url = $this->pluginData["PluginURI"]; - $obj->package = $package; - $transient->response[$this->config["slug"]] = $obj; + /** + * Sets the plugin infos + * + * @param mixed $false unused parameter sent by the filter + * @param mixed $action unused parameter sent by the filter + * @param mixed $response the updates check response + * + * @return mixed the response for the transient + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function setPluginInfo($false, $action, $response) + { + // Get plugin & GitHub release information + $this->getPluginData(); + $this->getRepoReleaseInfo(); + + // If nothing is found, do nothing + if (empty($response->slug) || $response->slug != $this->config["slug"]) { + return false; + } + // Add our plugin information + $response->last_updated = $this->githubAPIResult->published_at; + $response->slug = $this->config["slug"]; + $response->name = $this->pluginData["Name"]; + $response->plugin_name = $this->pluginData["Name"]; + $response->version = $this->githubAPIResult->tag_name; + $response->author = $this->pluginData["AuthorName"]; + $response->homepage = $this->pluginData["PluginURI"]; + + $response->sections = array( 'description' =>$this->githubAPIResult->body ); + // This is our release download zip file + $downloadLink = $this->githubAPIResult->zipball_url; + // Include the access token for private GitHub repos + if ( !empty( $this->config["access_token"] ) ) { + $downloadLink = add_query_arg( + array( "access_token" => $this->config["access_token"] ), + $downloadLink + ); + } + $response->download_link = $downloadLink; + + return $response; } - return $transient; - } - - public function setPluginInfo( $false, $action, $response ) { - // Get plugin & GitHub release information - $this->getPluginData(); - $this->getRepoReleaseInfo(); - - // If nothing is found, do nothing - if ( empty( $response->slug ) || $response->slug != $this->config["slug"] ) { - return false; - } - // Add our plugin information - $response->last_updated = $this->githubAPIResult->published_at; - $response->slug = $this->config["slug"]; - $response->name = $this->pluginData["Name"]; - $response->plugin_name = $this->pluginData["Name"]; - $response->version = $this->githubAPIResult->tag_name; - $response->author = $this->pluginData["AuthorName"]; - $response->homepage = $this->pluginData["PluginURI"]; - - $response->sections = array( 'description' =>$this->githubAPIResult->body ); - // This is our release download zip file - $downloadLink = $this->githubAPIResult->zipball_url; - // Include the access token for private GitHub repos - if ( !empty( $this->config["access_token"] ) ) { - $downloadLink = add_query_arg( - array( "access_token" => $this->config["access_token"] ), - $downloadLink - ); + /** + * Reactivates the plugin after installation + * + * @param mixed $true unused parameter sent by the filter + * @param mixed $hook_extra unused parameter sent by the filter + * @param mixed $result the result of the update + * + * @return mixed the response for the transient + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function postInstall($true, $hook_extra, $result) + { + global $wp_filesystem; + // Move & Activate + $proper_destination = WP_PLUGIN_DIR.'/'.$this->config['proper_folder_name']; + $wp_filesystem->move($result['destination'], $proper_destination); + $result['destination'] = $proper_destination; + $activate = activate_plugin(WP_PLUGIN_DIR.'/'.$this->config['slug']); + // Output the update message + $fail = __('The plugin has been updated, but could not be reactivated. Please reactivate it manually.', 'github_plugin_updater'); + $success = __('Plugin reactivated successfully.', 'github_plugin_updater'); + echo is_wp_error($activate) ? $fail : $success; + return $result; } - $response->download_link = $downloadLink; - - return $response; - } - - - public function postInstall( $true, $hook_extra, $result ) { - global $wp_filesystem; - // Move & Activate - $proper_destination = WP_PLUGIN_DIR.'/'.$this->config['proper_folder_name']; - $wp_filesystem->move( $result['destination'], $proper_destination ); - $result['destination'] = $proper_destination; - $activate = activate_plugin( WP_PLUGIN_DIR.'/'.$this->config['slug'] ); - // Output the update message - $fail = __( 'The plugin has been updated, but could not be reactivated. Please reactivate it manually.', 'github_plugin_updater' ); - $success = __( 'Plugin reactivated successfully.', 'github_plugin_updater' ); - echo is_wp_error( $activate ) ? $fail : $success; - return $result; - } } diff --git a/Aeria/Validator/Exceptions/InvalidValidatorException.php b/Aeria/Validator/Exceptions/InvalidValidatorException.php index d43ea73..85860ec 100644 --- a/Aeria/Validator/Exceptions/InvalidValidatorException.php +++ b/Aeria/Validator/Exceptions/InvalidValidatorException.php @@ -3,7 +3,16 @@ namespace Aeria\Validator\Exceptions; use Exception; - +/** + * InvalidValidatorException gets thrown when the user tries to add + * an invalid validator + * + * @category Validator + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class InvalidValidatorException extends Exception { diff --git a/Aeria/Validator/ServiceProviders/ValidatorServiceProvider.php b/Aeria/Validator/ServiceProviders/ValidatorServiceProvider.php index 26fe727..301f136 100644 --- a/Aeria/Validator/ServiceProviders/ValidatorServiceProvider.php +++ b/Aeria/Validator/ServiceProviders/ValidatorServiceProvider.php @@ -5,14 +5,42 @@ use Aeria\Container\Container; use Aeria\Validator\Validator; - +/** + * ValidatorServiceProvider is in charge of registering the validator service + * to the container + * + * @category Validator + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class ValidatorServiceProvider implements ServiceProviderInterface { + /** + * 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('validator', Validator::class); } - + /** + * In charge of booting the service. Validator doesn't need any additional operation. + * + * @param Container $container Aeria's container + * + * @return bool true: service booted + * + * @access public + * @since Method available since Release 3.0.0 + */ public function boot(Container $container): bool { return true; diff --git a/Aeria/Validator/Types/Callables/AbstractValidator.php b/Aeria/Validator/Types/Callables/AbstractValidator.php index 4de539b..a5da387 100644 --- a/Aeria/Validator/Types/Callables/AbstractValidator.php +++ b/Aeria/Validator/Types/Callables/AbstractValidator.php @@ -2,17 +2,43 @@ namespace Aeria\Validator\Types\Callables; -abstract class AbstractValidator +/** + * AbstractValidator describes a callable validator + * + * @category Validator + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +abstract class AbstractValidator { - protected static $_key; - protected static $_message; + protected static $key; + protected static $message; + /** + * Returns the validator key + * + * @return string the key + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getKey() { - return static::$_key; - } - + return static::$key; + } + /** + * Returns the validator message + * + * @return string the message + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getMessage() { - return static::$_message; + return static::$message; } } \ No newline at end of file diff --git a/Aeria/Validator/Types/Callables/IsEmailValidator.php b/Aeria/Validator/Types/Callables/IsEmailValidator.php index c343d8f..7ae34a0 100644 --- a/Aeria/Validator/Types/Callables/IsEmailValidator.php +++ b/Aeria/Validator/Types/Callables/IsEmailValidator.php @@ -4,17 +4,35 @@ use Aeria\Validator\Types\Callables\AbstractValidator; +/** + * IsEmailValidator describes an email validator + * + * @category Validator + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class IsEmailValidator extends AbstractValidator { - protected static $_key="isEmail"; - protected static $_message="Please insert a valid email. "; - - public static function getValidator(){ - return function ($field) - { - if(filter_var($field, FILTER_VALIDATE_EMAIL)) { + protected static $key="isEmail"; + protected static $message="Please insert a valid email. "; + /** + * Returns the validator + * + * @return Closure the validator function + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function getValidator() + { + return function ($field) { + if (filter_var($field, FILTER_VALIDATE_EMAIL)) { return ["status" => false]; - }return ["status" => true,"message" => "Please insert a valid email. "]; + } + return ["status" => true,"message" => "Please insert a valid email. "]; }; } } \ No newline at end of file diff --git a/Aeria/Validator/Types/RegEx/AbstractRegExValidator.php b/Aeria/Validator/Types/RegEx/AbstractRegExValidator.php index c5266de..d3b91dd 100644 --- a/Aeria/Validator/Types/RegEx/AbstractRegExValidator.php +++ b/Aeria/Validator/Types/RegEx/AbstractRegExValidator.php @@ -2,23 +2,57 @@ namespace Aeria\Validator\Types\RegEx; -abstract class AbstractRegExValidator +/** + * AbstractRegExValidator describes a validator based on RegExes + * + * @category Validator + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +abstract class AbstractRegExValidator { - protected static $_key; - protected static $_message; - protected static $_validator; + protected static $key; + protected static $message; + protected static $validator; + /** + * Returns the validator key + * + * @return string the key + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getKey() { - return static::$_key; + return static::$key; } - + /** + * Returns the validator + * + * @return Closure the validator function + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getValidator() { - return static::$_validator; + return static::$validator; } - + /** + * Returns the validator message + * + * @return string the message + * + * @access public + * @static + * @since Method available since Release 3.0.0 + */ public static function getMessage() { - return static::$_message; + return static::$message; } } \ No newline at end of file diff --git a/Aeria/Validator/Types/RegEx/IsShortValidator.php b/Aeria/Validator/Types/RegEx/IsShortValidator.php index 674d13f..e40baf7 100644 --- a/Aeria/Validator/Types/RegEx/IsShortValidator.php +++ b/Aeria/Validator/Types/RegEx/IsShortValidator.php @@ -4,9 +4,18 @@ use Aeria\Validator\Types\RegEx\AbstractRegExValidator; +/** + * IsShortValidator describes a string length validator + * + * @category Validator + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class IsShortValidator extends AbstractRegExValidator { - protected static $_key="isShort"; - protected static $_message="Please, insert a longer value."; - protected static $_validator="/^.{4,}$/"; + protected static $key="isShort"; + protected static $message="Please, insert a longer value."; + protected static $validator="/^.{4,}$/"; } \ No newline at end of file diff --git a/Aeria/Validator/Validator.php b/Aeria/Validator/Validator.php index 3a419b2..b0b4b3b 100644 --- a/Aeria/Validator/Validator.php +++ b/Aeria/Validator/Validator.php @@ -6,41 +6,88 @@ use Aeria\Validator\Types\Callables\IsEmailValidator; use Aeria\Validator\Types\RegEx\IsShortValidator; +/** + * Validator is the service in charge of validating fields + * + * @category Validator + * @package Aeria + * @author Simone Montali + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ class Validator { private $validators = []; private $coreValidators = [ IsEmailValidator::class, IsShortValidator::class ]; - + /** + * Constructs the service + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function __construct() { - foreach($this->coreValidators as $validator){ + foreach ($this->coreValidators as $validator) { $this->register($validator::getKey(), $validator::getValidator(), $validator::getMessage()); } } - - public function register($name, $newValidator,$message=null) + /** + * Registers a new validator + * + * @param string $name the validator name + * @param mixed $new_validator the validator to add + * @param string $message the error message + * + * @return void + * @throws InvalidValidatorException if the validator is wrong + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function register($name, $new_validator,$message=null) { - if (is_callable($newValidator)) { - $this->validators[$name] = $newValidator; - } elseif (preg_match($newValidator, null) !== false) { - $this->validators[$name] = function ($field) use ($newValidator, $message) { - $isValid["status"] = (bool)preg_match($newValidator, $field); + if (is_callable($new_validator)) { + $this->validators[$name] = $new_validator; + } elseif (preg_match($new_validator, null) !== false) { + $this->validators[$name] = function ($field) use ($new_validator, $message) { + $isValid["status"] = (bool)preg_match($new_validator, $field); if ($isValid["status"] == false) { - $isValid["message"] = ($message!=null) ? $message : "The RegEx ".$newValidator." was not satisfied. "; + $isValid["message"] = ($message!=null) ? $message : "The RegEx ".$new_validator." was not satisfied. "; } return $isValid; }; } else { - throw new InvalidValidatorException("The " . $name . " validator contains a wrong condition: " . $newValidator); + throw new InvalidValidatorException("The " . $name . " validator contains a wrong condition: " . $new_validator); } } - + /** + * Registers a validator + * + * @param AbstractValidator $validator the new validator + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ public function registerValidatorClass($validator) { $this->register($validator::getKey(), $validator::getValidator(), $validator::getMessage()); } - + /** + * Validates a field with a list of validators + * + * @param mixed $field the field to validate + * @param mixed $validations the required validations + * + * @return array the result of the validation + * + * @access public + * @since Method available since Release 3.0.0 + */ public function validate($field, $validations) { $validators=$this->validatorsToArray($validations); @@ -62,8 +109,19 @@ public function validate($field, $validations) return $validation; } - - public function validateByID ($full_id, $value, $metaboxes) + /** + * Validates a field by its ID + * + * @param string $full_id the field's ID + * @param mixed $value the field's value + * @param array $metaboxes the meta configuration + * + * @return array the results of the validation + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function validateByID($full_id, $value, $metaboxes) { foreach ($metaboxes as $id => $metabox) { $meta_id_length = strlen($id); @@ -82,17 +140,27 @@ public function validateByID ($full_id, $value, $metaboxes) ]; } foreach ($metaboxes[$metabox_id]['fields'] as $index => $field) { - if ($field['id'] == $field_id){ + if ($field['id'] == $field_id) { $validators = array_key_exists("validators", $field) ? $field['validators'] : ""; } } return $this->validate($value, $validators); } - private function validatorsToArray ($validators) + + /** + * Transforms a string of validators to an array + * + * @param string $validators the input validators + * + * @return array the validators + * + * @access private + * @since Method available since Release 3.0.0 + */ + private function validatorsToArray($validators) { if (is_array($validators)) { return $validators; } return explode("|", $validators); - } } diff --git a/Aeria/aeria-transparent.png b/Aeria/aeria-transparent.png new file mode 100644 index 0000000..1015c70 Binary files /dev/null and b/Aeria/aeria-transparent.png differ diff --git a/Aeria/helpers.php b/Aeria/helpers.php index 40fb6b8..b24be1f 100755 --- a/Aeria/helpers.php +++ b/Aeria/helpers.php @@ -8,60 +8,90 @@ if (!function_exists('dump')) { - function dump(...$args) - { - $message = implode( - "\n\n", - array_map( - function($value) { - return var_export($value, true); - }, - $args - ) - ); - $is_cli = in_array(php_sapi_name(), [ 'cli', 'cli-server' ]); - if (!$is_cli) { - $message = preg_replace( - [ - '/\<\;\!\-\-begin\-\-\>\;.+?\/\*end\*\//', - '/\/\*begin\*\/.+?\<\;\!\-\-end\-\-\>\;/', - '/array\ \;\(\\)/', - ], - [ - '', - '', - 'array ( )', - ], - highlight_string( - "\n\n", - true - ) - ); - } - echo $message; - } + /** + * Dumps the provided arguments + * + * @param mixed ...$args the dumpable args + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + function dump(...$args) + { + $message = implode( + "\n\n", + array_map( + function ($value) { + return var_export($value, true); + }, + $args + ) + ); + $is_cli = in_array(php_sapi_name(), [ 'cli', 'cli-server' ]); + if (!$is_cli) { + $message = preg_replace( + [ + '/\<\;\!\-\-begin\-\-\>\;.+?\/\*end\*\//', + '/\/\*begin\*\/.+?\<\;\!\-\-end\-\-\>\;/', + '/array\ \;\(\\)/', + ], + [ + '', + '', + 'array ( )', + ], + highlight_string( + "\n\n", + true + ) + ); + } + echo $message; + } } if (!function_exists('dd')) { - function dd(...$args) - { - dump(...$args); - die(); - } + /** + * Dumps the provided arguments than dies + * + * @param mixed ...$args the dumpable args + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ + function dd(...$args) + { + dump(...$args); + die(); + } } if (!function_exists('toSnake')) { - function toSnake($convertibleText) + /** + * Converts camelCase to snake_case + * + * @param string $convertible_text the text to convert + * + * @return string the converted text + * + * @access public + * @since Method available since Release 3.0.0 + */ + function toSnake($convertible_text) { - $convertibleText = preg_replace('/\s+/u', '', ucwords($convertibleText)); + $convertible_text = preg_replace('/\s+/u', '', ucwords($convertible_text)); return strtolower( preg_replace( '/(.)(?=[A-Z])/u', '$1' . '_', - $convertibleText + $convertible_text ) ); } @@ -69,6 +99,16 @@ function toSnake($convertibleText) if (!function_exists('aeria')) { + /** + * Returns Aeria's instance + * + * @param string $abstract the requested service + * + * @return mixed the service or Aeria's instance + * + * @access public + * @since Method available since Release 3.0.0 + */ function aeria(/* ?string */ $abstract = null) { if (is_null($abstract)) { @@ -76,13 +116,23 @@ function aeria(/* ?string */ $abstract = null) } return Aeria::getInstance()->make($abstract); } - + /** + * Returns Aeria's fields + * + * @param WP_Post $post the current post + * + * @return array the retrieved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ function get_aeria_fields($post) { $aeria = aeria(); $meta_service = $aeria->make('meta'); $metaboxes = $aeria->make('config')->get('aeria.meta', []); $sections = $aeria->make('config')->get('aeria.section', []); + $render_service = $aeria->make('render_engine'); $fields = []; foreach ($metaboxes as $name => $data) { $metabox = array_merge( @@ -92,52 +142,94 @@ function get_aeria_fields($post) if( !in_array($post->post_type, $metabox["post_type"])){ continue; } - $processor = new MetaProcessor($post->ID, $metabox, $sections); + $processor = new MetaProcessor($post->ID, $metabox, $sections, $render_service); $fields[$name] = $processor->get(); } return $fields; } - + /** + * Returns an Aeria field + * + * @param WP_Post $post the current post + * @param string $metabox the metabox ID + * @param string $id the field's ID + * + * @return array the retrieved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ function get_aeria_field($post, $metabox, $id) { $aeria = aeria(); $metaboxes = $aeria->make('config')->get('aeria.meta', []); $sections = $aeria->make('config')->get('aeria.section', []); + $render_service = $aeria->make('render_engine'); $metaboxes[$metabox]['id'] = $metabox; - $processor = new MetaProcessor($post->ID, $metaboxes[$metabox], $sections); + $processor = new MetaProcessor($post->ID, $metaboxes[$metabox], $sections, $render_service); return ($processor->get()[$id]); } - + /** + * Returns an Aeria metabox's fields + * + * @param WP_Post $post the current post + * @param string $metabox the metabox ID + * + * @return array the retrieved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ function get_aeria_metabox($post, $metabox) { $aeria = aeria(); $meta_service = $aeria->make('meta'); $metaboxes = $aeria->make('config')->get('aeria.meta', []); $sections = $aeria->make('config')->get('aeria.section', []); + $render_service = $aeria->make('render_engine'); $fields = []; $metabox = array_merge( ['id' => $metabox], $metaboxes[$metabox] ); - $processor = new MetaProcessor($post->ID, $metabox, $sections); + $processor = new MetaProcessor($post->ID, $metabox, $sections, $render_service); $fields = $processor->get(); return $fields; } - - function get_aeria_options($optionPage) + /** + * Returns Aeria's options + * + * @param string $option_page the page we're checking + * + * @return array the retrieved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ + function get_aeria_options($option_page) { $aeria = aeria(); $options = $aeria->make('config')->get('aeria.options', []); $sections = $aeria->make('config')->get('aeria.section', []); + $render_service = $aeria->make('render_engine'); $optionPage = array_merge( ['id' => $optionPage], $options[$optionPage] ); - $processor = new OptionsPageProcessor($optionPage['id'], $optionPage, $sections); + $processor = new OptionsPageProcessor($optionPage['id'], $optionPage, $sections, $render_service); return $processor->get(); } - + /** + * Saves Aeria's provided fields + * + * @param array $saving_data the data we're saving + * + * @return void + * + * @access public + * @since Method available since Release 3.0.0 + */ function save_aeria_fields(array $saving_data) { foreach ($saving_data['fields'] as $field => $value) { @@ -147,19 +239,29 @@ function save_aeria_fields(array $saving_data) - + /** + * Flattens an array + * + * @param array $to_be_normalized the array we want to normalize + * @param int $times the times to normalize the array + * + * @return array the retrieved fields + * + * @access public + * @since Method available since Release 3.0.0 + */ function array_flat(array $to_be_normalized, $times = -1) { $pivot = []; foreach ($to_be_normalized as $key => $value) { - if (is_array($value)) { - $res_val = $times > 1 || $times == -1 - ? array_flat($value, $times == -1 ? $times : $times - 1) - : $value; - $pivot = array_merge($pivot, $res_val); - } else { - $pivot[$key] = $value; - } + if (is_array($value)) { + $res_val = $times > 1 || $times == -1 + ? array_flat($value, $times == -1 ? $times : $times - 1) + : $value; + $pivot = array_merge($pivot, $res_val); + } else { + $pivot[$key] = $value; + } } return $pivot; } diff --git a/Resources/Config/options-maps.json b/Resources/Config/options-maps.json new file mode 100644 index 0000000..e1178e4 --- /dev/null +++ b/Resources/Config/options-maps.json @@ -0,0 +1,21 @@ +{ + "name": "map_options", + "spec": { + "title": "Aeria Map Options", + "menu_slug": "map_options", + "context": "normal", + "fields": [ + { + "type": "text", + "id": "api_key", + "label": "Google Maps API key", + "description": "You can request your API key like explained on the Google Cloud docs.", + "size": "half", + "placeholder": "API Key", + "required": true + } + ] + }, + "kind": "options" + } + \ No newline at end of file diff --git a/aeria.php b/aeria.php index f65af47..4227d5b 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.2 + * Version: 3.0.3 * Author: Caffeina * Author URI: https://caffeina.com * Text Domain: aeria diff --git a/assets/js/aeria-editor.js b/assets/js/aeria-editor.js index c2f9f1a..00341f4 100644 --- a/assets/js/aeria-editor.js +++ b/assets/js/aeria-editor.js @@ -1,16 +1,16 @@ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/js/",n(n.s=258)}([function(e,t,n){"use strict";e.exports=n(168)},function(e,t,n){"use strict";function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}n.d(t,"a",function(){return r})},function(e,t,n){e.exports=n(177)()},function(e,t,n){"use strict";var r=n(5),o=n(1);var i=n(16),a=n(50);function u(e,t,n){return(u=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&Object(a.a)(o,n.prototype),o}).apply(null,arguments)}function s(e){var t="function"==typeof Map?new Map:void 0;return(s=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,Object(i.a)(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Object(a.a)(r,e)})(e)}n.d(t,"a",function(){return $}),n.d(t,"b",function(){return G}),n.d(t,"c",function(){return h}),n.d(t,"d",function(){return K});var l=function(e){var t,n;function r(t){var n;return n=e.call(this,"An error occurred. See https://github.com/styled-components/polished/blob/master/src/internalHelpers/errors.md#"+t+" for more information.")||this,Object(o.a)(n)}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n,r}(s(Error));function c(e,t){return e.substr(-t.length)===t}var f=/^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;function p(e,t){if("string"!=typeof e)return t?[e,void 0]:e;var n=e.match(f);return t?n?[parseFloat(e),n[2]]:[e,void 0]:n?parseFloat(e):e}var d=function(e){return function(t,n){void 0===n&&(n="16px");var r=t,o=n;if("string"==typeof t){if(!c(t,"px"))throw new l(69,e,t);r=p(t)}if("string"==typeof n){if(!c(n,"px"))throw new l(70,e,n);o=p(n)}if("string"==typeof r)throw new l(71,t,e);if("string"==typeof o)throw new l(72,n,e);return""+r/o+e}};var h=d("rem");function m(e){return Math.round(255*e)}function y(e,t,n){return m(e)+","+m(t)+","+m(n)}function b(e,t,n,r){if(void 0===r&&(r=y),0===t)return r(n,n,n);var o=(e%360+360)%360/60,i=(1-Math.abs(2*n-1))*t,a=i*(1-Math.abs(o%2-1)),u=0,s=0,l=0;o>=0&&o<1?(u=i,s=a):o>=1&&o<2?(u=a,s=i):o>=2&&o<3?(s=i,l=a):o>=3&&o<4?(s=a,l=i):o>=4&&o<5?(u=a,l=i):o>=5&&o<6&&(u=i,l=a);var c=n-i/2;return r(u+c,s+c,l+c)}var v={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"};var g=/^#[a-fA-F0-9]{6}$/,w=/^#[a-fA-F0-9]{8}$/,x=/^#[a-fA-F0-9]{3}$/,O=/^#[a-fA-F0-9]{4}$/,_=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,E=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([-+]?[0-9]*[.]?[0-9]+)\s*\)$/i,k=/^hsl\(\s*(\d{0,3}[.]?[0-9]+)\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/i,S=/^hsla\(\s*(\d{0,3}[.]?[0-9]+)\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*([-+]?[0-9]*[.]?[0-9]+)\s*\)$/i;function C(e){if("string"!=typeof e)throw new l(3);var t=function(e){if("string"!=typeof e)return e;var t=e.toLowerCase();return v[t]?"#"+v[t]:e}(e);if(t.match(g))return{red:parseInt(""+t[1]+t[2],16),green:parseInt(""+t[3]+t[4],16),blue:parseInt(""+t[5]+t[6],16)};if(t.match(w)){var n=parseFloat((parseInt(""+t[7]+t[8],16)/255).toFixed(2));return{red:parseInt(""+t[1]+t[2],16),green:parseInt(""+t[3]+t[4],16),blue:parseInt(""+t[5]+t[6],16),alpha:n}}if(t.match(x))return{red:parseInt(""+t[1]+t[1],16),green:parseInt(""+t[2]+t[2],16),blue:parseInt(""+t[3]+t[3],16)};if(t.match(O)){var r=parseFloat((parseInt(""+t[4]+t[4],16)/255).toFixed(2));return{red:parseInt(""+t[1]+t[1],16),green:parseInt(""+t[2]+t[2],16),blue:parseInt(""+t[3]+t[3],16),alpha:r}}var o=_.exec(t);if(o)return{red:parseInt(""+o[1],10),green:parseInt(""+o[2],10),blue:parseInt(""+o[3],10)};var i=E.exec(t);if(i)return{red:parseInt(""+i[1],10),green:parseInt(""+i[2],10),blue:parseInt(""+i[3],10),alpha:parseFloat(""+i[4])};var a=k.exec(t);if(a){var u="rgb("+b(parseInt(""+a[1],10),parseInt(""+a[2],10)/100,parseInt(""+a[3],10)/100)+")",s=_.exec(u);if(!s)throw new l(4,t,u);return{red:parseInt(""+s[1],10),green:parseInt(""+s[2],10),blue:parseInt(""+s[3],10)}}var c=S.exec(t);if(c){var f="rgb("+b(parseInt(""+c[1],10),parseInt(""+c[2],10)/100,parseInt(""+c[3],10)/100)+")",p=_.exec(f);if(!p)throw new l(4,t,f);return{red:parseInt(""+p[1],10),green:parseInt(""+p[2],10),blue:parseInt(""+p[3],10),alpha:parseFloat(""+c[4])}}throw new l(5)}function j(e){return function(e){var t,n=e.red/255,r=e.green/255,o=e.blue/255,i=Math.max(n,r,o),a=Math.min(n,r,o),u=(i+a)/2;if(i===a)return void 0!==e.alpha?{hue:0,saturation:0,lightness:u,alpha:e.alpha}:{hue:0,saturation:0,lightness:u};var s=i-a,l=u>.5?s/(2-i-a):s/(i+a);switch(i){case n:t=(r-o)/s+(r=1?R(e,t,n):"rgba("+b(e,t,n)+","+r+")";if("object"==typeof e&&void 0===t&&void 0===n&&void 0===r)return e.alpha>=1?R(e.hue,e.saturation,e.lightness):"rgba("+b(e.hue,e.saturation,e.lightness)+","+e.alpha+")";throw new l(2)}function L(e,t,n){if("number"==typeof e&&"number"==typeof t&&"number"==typeof n)return T("#"+A(e)+A(t)+A(n));if("object"==typeof e&&void 0===t&&void 0===n)return T("#"+A(e.red)+A(e.green)+A(e.blue));throw new l(6)}function M(e,t,n,r){if("string"==typeof e&&"number"==typeof t){var o=C(e);return"rgba("+o.red+","+o.green+","+o.blue+","+t+")"}if("number"==typeof e&&"number"==typeof t&&"number"==typeof n&&"number"==typeof r)return r>=1?L(e,t,n):"rgba("+e+","+t+","+n+","+r+")";if("object"==typeof e&&void 0===t&&void 0===n&&void 0===r)return e.alpha>=1?L(e.red,e.green,e.blue):"rgba("+e.red+","+e.green+","+e.blue+","+e.alpha+")";throw new l(7)}var N=function(e){return"number"==typeof e.red&&"number"==typeof e.green&&"number"==typeof e.blue&&("number"!=typeof e.alpha||void 0===e.alpha)},z=function(e){return"number"==typeof e.red&&"number"==typeof e.green&&"number"==typeof e.blue&&"number"==typeof e.alpha},B=function(e){return"number"==typeof e.hue&&"number"==typeof e.saturation&&"number"==typeof e.lightness&&("number"!=typeof e.alpha||void 0===e.alpha)},U=function(e){return"number"==typeof e.hue&&"number"==typeof e.saturation&&"number"==typeof e.lightness&&"number"==typeof e.alpha};function V(e){if("object"!=typeof e)throw new l(8);if(z(e))return M(e);if(N(e))return L(e);if(U(e))return F(e);if(B(e))return D(e);throw new l(8)}function W(e){return function e(t,n,r){return function(){var o=r.concat(Array.prototype.slice.call(arguments));return o.length>=n?t.apply(this,o):e(t,n,o)}}(e,e.length,[])}function H(e,t,n){return Math.max(e,Math.min(t,n))}function q(e,t){if("transparent"===t)return t;var n=j(t);return V(Object(r.a)({},n,{lightness:H(0,1,n.lightness-parseFloat(e))}))}var $=W(q);function Y(e,t){if("transparent"===t)return t;var n=j(t);return V(Object(r.a)({},n,{lightness:H(0,1,n.lightness+parseFloat(e))}))}var G=W(Y);function Z(e,t){if("transparent"===t)return t;var n=C(t),o="number"==typeof n.alpha?n.alpha:1;return M(Object(r.a)({},n,{alpha:H(0,1,(100*o-100*parseFloat(e))/100)}))}var K=W(Z)},function(e,t,n){"use strict";(function(e){n.d(t,"b",function(){return ot}),n.d(t,"c",function(){return we}),n.d(t,"a",function(){return Ze});var r=n(110),o=n.n(r),i=n(158),a=n.n(i),u=n(0),s=n.n(u),l=n(85),c=n(111),f=n(41),p=(n(2),n(159)),d=n(164),h=function(e,t){for(var n=[e[0]],r=0,o=t.length;r=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},x=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},O=function(e){return"object"===(void 0===e?"undefined":m(e))&&e.constructor===Object},_=Object.freeze([]),E=Object.freeze({});function k(e){return"function"==typeof e}function S(e){return e.displayName||e.name||"Component"}function C(e){return e&&"string"==typeof e.styledComponentId}var j=void 0!==e&&(e.env.REACT_APP_SC_ATTR||e.env.SC_ATTR)||"data-styled",T="undefined"!=typeof window&&"HTMLElement"in window,A="boolean"==typeof SC_DISABLE_SPEEDY&&SC_DISABLE_SPEEDY||void 0!==e&&(e.env.REACT_APP_SC_DISABLE_SPEEDY||e.env.SC_DISABLE_SPEEDY)||!1,P={};var I=function(e){function t(n){y(this,t);for(var r=arguments.length,o=Array(r>1?r-1:0),i=1;i0?" Additional arguments: "+o.join(", "):"")));return x(a)}return g(t,e),t}(Error),R=/^[^\S\n]*?\/\* sc-component-id:\s*(\S+)\s+\*\//gm,D=function(e){var t=""+(e||""),n=[];return t.replace(R,function(e,t,r){return n.push({componentId:t,matchIndex:r}),e}),n.map(function(e,r){var o=e.componentId,i=e.matchIndex,a=n[r+1];return{componentId:o,cssFromDOM:a?t.slice(i,a.matchIndex):t.slice(i)}})},F=/^\s*\/\/.*$/gm,L=new o.a({global:!1,cascade:!0,keyframe:!1,prefix:!1,compress:!1,semicolon:!0}),M=new o.a({global:!1,cascade:!0,keyframe:!1,prefix:!0,compress:!1,semicolon:!1}),N=[],z=function(e){if(-2===e){var t=N;return N=[],t}},B=a()(function(e){N.push(e)}),U=void 0,V=void 0,W=void 0,H=function(e,t,n){return t>0&&-1!==n.slice(0,t).indexOf(V)&&n.slice(t-V.length,t)!==V?"."+U:e};M.use([function(e,t,n){2===e&&n.length&&n[0].lastIndexOf(V)>0&&(n[0]=n[0].replace(W,H))},B,z]),L.use([B,z]);var q=function(e){return L("",e)};function $(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"&",o=e.join("").replace(F,""),i=t&&n?n+" "+t+" { "+o+" }":o;return U=r,V=t,W=new RegExp("\\"+V+"\\b","g"),M(n||!t?"":t,i)}var Y=function(){return n.nc},G=function(e,t,n){n&&((e[t]||(e[t]=Object.create(null)))[n]=!0)},Z=function(e,t){e[t]=Object.create(null)},K=function(e){return function(t,n){return void 0!==e[t]&&e[t][n]}},X=function(e){var t="";for(var n in e)t+=Object.keys(e[n]).join(" ")+" ";return t.trim()},Q=function(e){if(e.sheet)return e.sheet;for(var t=document.styleSheets.length,n=0;n"+e()+""}},re=function(e,t){return function(){var n,r=((n={})[j]=X(t),n["data-styled-version"]="4.3.2",n),o=Y();return o&&(r.nonce=o),s.a.createElement("style",v({},r,{dangerouslySetInnerHTML:{__html:e()}}))}},oe=function(e){return function(){return Object.keys(e)}},ie=function(e){return document.createTextNode(ee(e))},ae=function e(t,n){var r=void 0===t?Object.create(null):t,o=void 0===n?Object.create(null):n,i=function(e){var t=o[e];return void 0!==t?t:o[e]=[""]},a=function(){var e="";for(var t in o){var n=o[t][0];n&&(e+=ee(t)+n)}return e};return{clone:function(){var t=function(e){var t=Object.create(null);for(var n in e)t[n]=v({},e[n]);return t}(r),n=Object.create(null);for(var i in o)n[i]=[o[i][0]];return e(t,n)},css:a,getIds:oe(o),hasNameForId:K(r),insertMarker:i,insertRules:function(e,t,n){i(e)[0]+=t.join(" "),G(r,e,n)},removeRules:function(e){var t=o[e];void 0!==t&&(t[0]="",Z(r,e))},sealed:!1,styleTag:null,toElement:re(a,r),toHTML:ne(a,r)}},ue=function(e,t,n,r,o){if(T&&!n){var i=function(e,t,n){var r=document.createElement("style");r.setAttribute(j,""),r.setAttribute("data-styled-version","4.3.2");var o=Y();if(o&&r.setAttribute("nonce",o),r.appendChild(document.createTextNode("")),e&&!t)e.appendChild(r);else{if(!t||!e||!t.parentNode)throw new I(6);t.parentNode.insertBefore(r,n?t:t.nextSibling)}return r}(e,t,r);return A?function(e,t){var n=Object.create(null),r=Object.create(null),o=void 0!==t,i=!1,a=function(t){var o=r[t];return void 0!==o?o:(r[t]=ie(t),e.appendChild(r[t]),n[t]=Object.create(null),r[t])},u=function(){var e="";for(var t in r)e+=r[t].data;return e};return{clone:function(){throw new I(5)},css:u,getIds:oe(r),hasNameForId:K(n),insertMarker:a,insertRules:function(e,r,u){for(var s=a(e),l=[],c=r.length,f=0;f0&&(i=!0,t().insertRules(e+"-import",l))},removeRules:function(a){var u=r[a];if(void 0!==u){var s=ie(a);e.replaceChild(s,u),r[a]=s,Z(n,a),o&&i&&t().removeRules(a+"-import")}},sealed:!1,styleTag:e,toElement:re(u,n),toHTML:ne(u,n)}}(i,o):function(e,t){var n=Object.create(null),r=Object.create(null),o=[],i=void 0!==t,a=!1,u=function(e){var t=r[e];return void 0!==t?t:(r[e]=o.length,o.push(0),Z(n,e),r[e])},s=function(){var t=Q(e).cssRules,n="";for(var i in r){n+=ee(i);for(var a=r[i],u=te(o,a),s=u-o[a];s0&&(a=!0,t().insertRules(r+"-import",h)),o[c]+=d,G(n,r,l)},removeRules:function(u){var s=r[u];if(void 0!==s){var l=o[s];!function(e,t,n){for(var r=t-n,o=t;o>r;o-=1)e.deleteRule(o)}(Q(e),te(o,s)-1,l),o[s]=0,Z(n,u),i&&a&&t().removeRules(u+"-import")}},sealed:!1,styleTag:e,toElement:re(s,n),toHTML:ne(s,n)}}(i,o)}return ae()},se=/\s+/,le=void 0;le=T?A?40:1e3:-1;var ce=0,fe=void 0,pe=function(){function e(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:T?document.head:null,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];y(this,e),this.getImportRuleTag=function(){var e=t.importRuleTag;if(void 0!==e)return e;var n=t.tags[0];return t.importRuleTag=ue(t.target,n?n.styleTag:null,t.forceServer,!0)},ce+=1,this.id=ce,this.forceServer=r,this.target=r?null:n,this.tagMap={},this.deferred={},this.rehydratedNames={},this.ignoreRehydratedNames={},this.tags=[],this.capacity=1,this.clones=[]}return e.prototype.rehydrate=function(){if(!T||this.forceServer)return this;var e=[],t=[],n=!1,r=document.querySelectorAll("style["+j+'][data-styled-version="4.3.2"]'),o=r.length;if(!o)return this;for(var i=0;i0&&void 0!==arguments[0]&&arguments[0];fe=new e(void 0,t).rehydrate()},e.prototype.clone=function(){var t=new e(this.target,this.forceServer);return this.clones.push(t),t.tags=this.tags.map(function(e){for(var n=e.getIds(),r=e.clone(),o=0;o1?t-1:0),r=1;r=4;)t=1540483477*(65535&(t=255&e.charCodeAt(o)|(255&e.charCodeAt(++o))<<8|(255&e.charCodeAt(++o))<<16|(255&e.charCodeAt(++o))<<24))+((1540483477*(t>>>16)&65535)<<16),r=1540483477*(65535&r)+((1540483477*(r>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),n-=4,++o;switch(n){case 3:r^=(255&e.charCodeAt(o+2))<<16;case 2:r^=(255&e.charCodeAt(o+1))<<8;case 1:r=1540483477*(65535&(r^=255&e.charCodeAt(o)))+((1540483477*(r>>>16)&65535)<<16)}return((r=1540483477*(65535&(r^=r>>>13))+((1540483477*(r>>>16)&65535)<<16))^r>>>15)>>>0}var Oe=52,_e=function(e){return String.fromCharCode(e+(e>25?39:97))};function Ee(e){var t="",n=void 0;for(n=e;n>Oe;n=Math.floor(n/Oe))t=_e(n%Oe)+t;return _e(n%Oe)+t}function ke(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:E,r=!!n&&e.theme===n.theme;return e.theme&&!r?e.theme:t||n.theme},Pe=/[[\].#*$><+~=|^:(),"'`-]+/g,Ie=/(^-|-$)/g;function Re(e){return e.replace(Pe,"-").replace(Ie,"")}function De(e){return"string"==typeof e&&!0}var Fe={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDerivedStateFromProps:!0,propTypes:!0,type:!0},Le={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},Me=((Se={})[c.ForwardRef]={$$typeof:!0,render:!0},Se),Ne=Object.defineProperty,ze=Object.getOwnPropertyNames,Be=Object.getOwnPropertySymbols,Ue=void 0===Be?function(){return[]}:Be,Ve=Object.getOwnPropertyDescriptor,We=Object.getPrototypeOf,He=Object.prototype,qe=Array.prototype;function $e(e,t,n){if("string"!=typeof t){var r=We(t);r&&r!==He&&$e(e,r,n);for(var o=qe.concat(ze(t),Ue(t)),i=Me[e.$$typeof]||Fe,a=Me[t.$$typeof]||Fe,u=o.length,s=void 0,l=void 0;u--;)if(l=o[u],!(Le[l]||n&&n[l]||a&&a[l]||i&&i[l])&&(s=Ve(t,l)))try{Ne(e,l,s)}catch(e){}return e}return e}var Ye=Object(u.createContext)(),Ge=Ye.Consumer,Ze=function(e){function t(n){y(this,t);var r=x(this,e.call(this,n));return r.getContext=Object(f.a)(r.getContext.bind(r)),r.renderInner=r.renderInner.bind(r),r}return g(t,e),t.prototype.render=function(){return this.props.children?s.a.createElement(Ye.Consumer,null,this.renderInner):null},t.prototype.renderInner=function(e){var t=this.getContext(this.props.theme,e);return s.a.createElement(Ye.Provider,{value:t},s.a.Children.only(this.props.children))},t.prototype.getTheme=function(e,t){if(k(e))return e(t);if(null===e||Array.isArray(e)||"object"!==(void 0===e?"undefined":m(e)))throw new I(8);return v({},t,e)},t.prototype.getContext=function(e,t){return this.getTheme(e,t)},t}(u.Component),Ke=(function(){function e(){y(this,e),this.masterSheet=pe.master,this.instance=this.masterSheet.clone(),this.sealed=!1}e.prototype.seal=function(){if(!this.sealed){var e=this.masterSheet.clones.indexOf(this.instance);this.masterSheet.clones.splice(e,1),this.sealed=!0}},e.prototype.collectStyles=function(e){if(this.sealed)throw new I(2);return s.a.createElement(Qe,{sheet:this.instance},e)},e.prototype.getStyleTags=function(){return this.seal(),this.instance.toHTML()},e.prototype.getStyleElement=function(){return this.seal(),this.instance.toReactElements()},e.prototype.interleaveWithNodeStream=function(e){throw new I(3)}}(),Object(u.createContext)()),Xe=Ke.Consumer,Qe=function(e){function t(n){y(this,t);var r=x(this,e.call(this,n));return r.getContext=Object(f.a)(r.getContext),r}return g(t,e),t.prototype.getContext=function(e,t){if(e)return e;if(t)return new pe(t);throw new I(4)},t.prototype.render=function(){var e=this.props,t=e.children,n=e.sheet,r=e.target;return s.a.createElement(Ke.Provider,{value:this.getContext(n,r)},t)},t}(u.Component),Je={};var et=function(e){function t(){y(this,t);var n=x(this,e.call(this));return n.attrs={},n.renderOuter=n.renderOuter.bind(n),n.renderInner=n.renderInner.bind(n),n}return g(t,e),t.prototype.render=function(){return s.a.createElement(Xe,null,this.renderOuter)},t.prototype.renderOuter=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:pe.master;return this.styleSheet=e,this.props.forwardedComponent.componentStyle.isStatic?this.renderInner():s.a.createElement(Ge,null,this.renderInner)},t.prototype.renderInner=function(e){var t=this.props.forwardedComponent,n=t.componentStyle,r=t.defaultProps,o=(t.displayName,t.foldedComponentIds),i=t.styledComponentId,a=t.target,s=void 0;s=n.isStatic?this.generateAndInjectStyles(E,this.props):this.generateAndInjectStyles(Ae(this.props,e,r)||E,this.props);var l=this.props.as||this.attrs.as||a,c=De(l),f={},d=v({},this.attrs,this.props),h=void 0;for(h in d)"forwardedComponent"!==h&&"as"!==h&&("forwardedRef"===h?f.ref=d[h]:"forwardedAs"===h?f.as=d[h]:c&&!Object(p.a)(h)||(f[h]=d[h]));return this.props.style&&this.attrs.style&&(f.style=v({},this.attrs.style,this.props.style)),f.className=Array.prototype.concat(o,this.props.className,i,this.attrs.className,s).filter(Boolean).join(" "),Object(u.createElement)(l,f)},t.prototype.buildExecutionContext=function(e,t,n){var r=this,o=v({},t,{theme:e});return n.length?(this.attrs={},n.forEach(function(e){var t,n=e,i=!1,a=void 0,u=void 0;for(u in k(n)&&(n=n(o),i=!0),n)a=n[u],i||!k(a)||(t=a)&&t.prototype&&t.prototype.isReactComponent||C(a)||(a=a(o)),r.attrs[u]=a,o[u]=a}),o):o},t.prototype.generateAndInjectStyles=function(e,t){var n=t.forwardedComponent,r=n.attrs,o=n.componentStyle;n.warnTooManyClasses;return o.isStatic&&!r.length?o.generateAndInjectStyles(E,this.styleSheet):o.generateAndInjectStyles(this.buildExecutionContext(e,t,r),this.styleSheet)},t}(u.Component);function tt(e,t,n){var r=C(e),o=!De(e),i=t.displayName,a=void 0===i?function(e){return De(e)?"styled."+e:"Styled("+S(e)+")"}(e):i,u=t.componentId,l=void 0===u?function(e,t,n){var r="string"!=typeof t?"sc":Re(t),o=(Je[r]||0)+1;Je[r]=o;var i=r+"-"+e.generateName(r+o);return n?n+"-"+i:i}(Te,t.displayName,t.parentComponentId):u,c=t.ParentComponent,f=void 0===c?et:c,p=t.attrs,h=void 0===p?_:p,m=t.displayName&&t.componentId?Re(t.displayName)+"-"+t.componentId:t.componentId||l,y=r&&e.attrs?Array.prototype.concat(e.attrs,h).filter(Boolean):h,b=new Te(r?e.componentStyle.rules.concat(n):n,y,m),g=void 0,x=function(e,t){return s.a.createElement(f,v({},e,{forwardedComponent:g,forwardedRef:t}))};return x.displayName=a,(g=s.a.forwardRef(x)).displayName=a,g.attrs=y,g.componentStyle=b,g.foldedComponentIds=r?Array.prototype.concat(e.foldedComponentIds,e.styledComponentId):_,g.styledComponentId=m,g.target=r?e.target:e,g.withComponent=function(e){var r=t.componentId,o=w(t,["componentId"]),i=r&&r+"-"+(De(e)?e:Re(S(e)));return tt(e,v({},o,{attrs:y,componentId:i,ParentComponent:f}),n)},Object.defineProperty(g,"defaultProps",{get:function(){return this._foldedDefaultProps},set:function(t){this._foldedDefaultProps=r?Object(d.a)(e.defaultProps,t):t}}),g.toString=function(){return"."+g.styledComponentId},o&&$e(g,e,{attrs:!0,componentStyle:!0,displayName:!0,foldedComponentIds:!0,styledComponentId:!0,target:!0,withComponent:!0}),g}var nt=function(e){return function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:E;if(!Object(c.isValidElementType)(n))throw new I(1,String(n));var o=function(){return t(n,r,we.apply(void 0,arguments))};return o.withConfig=function(o){return e(t,n,v({},r,o))},o.attrs=function(o){return e(t,n,v({},r,{attrs:Array.prototype.concat(r.attrs,o).filter(Boolean)}))},o}(tt,e)};["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","circle","clipPath","defs","ellipse","foreignObject","g","image","line","linearGradient","marker","mask","path","pattern","polygon","polyline","radialGradient","rect","stop","svg","text","tspan"].forEach(function(e){nt[e]=nt(e)});var rt=function(){function e(t,n){y(this,e),this.rules=t,this.componentId=n,this.isStatic=ke(t,_),pe.master.hasId(n)||pe.master.deferredInject(n,[])}return e.prototype.createStyles=function(e,t){var n=$(ge(this.rules,e,t),"");t.inject(this.componentId,n)},e.prototype.removeStyles=function(e){var t=this.componentId;e.hasId(t)&&e.remove(t)},e.prototype.renderStyles=function(e,t){this.removeStyles(t),this.createStyles(e,t)},e}();function ot(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;ro;)oe(e,n=r[o++],t[n]);return e},ae=function(e){var t=Y.call(this,e=E(e,!0));return!(this===Q&&i(Z,e)&&!i(K,e))&&(!(t||!i(this,e)||!i(Z,e)||i(this,M)&&this[M][e])||t)},ue=function(e,t){if(e=_(e),t=E(t,!0),e!==Q||!i(Z,t)||i(K,t)){var n=B(e,t);return!n||!i(Z,t)||i(e,M)&&e[M][t]||(n.enumerable=!0),n}},se=function(e){for(var t,n=V(_(e)),r=[],o=0;n.length>o;)i(Z,t=n[o++])||i(c,t)||r.push(t);return r},le=function(e){for(var t,n=e===Q,r=V(n?K:_(e)),o=[],a=0;r.length>a;)!i(Z,t=r[a++])||n&&!i(Q,t)||o.push(Z[t]);return o};a||(l((W=function(){if(this instanceof W)throw TypeError("Symbol is not a constructor");var e=void 0===arguments[0]?void 0:String(arguments[0]),t=h(e),n=function(e){this===Q&&n.call(K,e),i(this,M)&&i(this[M],t)&&(this[M][t]=!1),te(this,t,k(1,e))};return u&&ee&&te(Q,t,{configurable:!0,set:n}),ne(t,e)}).prototype,"toString",function(){return z(this).tag}),P.f=ae,A.f=oe,T.f=ue,C.f=j.f=se,D.f=le,u&&(U(W.prototype,"description",{configurable:!0,get:function(){return z(this).description}}),s||l(Q,"propertyIsEnumerable",ae,{unsafe:!0})),y.f=function(e){return ne(m(e),e)}),r({global:!0,wrap:!0,forced:!a,sham:!a},{Symbol:W});for(var ce=R(X),fe=0;ce.length>fe;)b(ce[fe++]);r({target:"Symbol",stat:!0,forced:!a},{for:function(e){return i(G,e+="")?G[e]:G[e]=W(e)},keyFor:function(e){if(!re(e))throw TypeError(e+" is not a symbol");for(var t in G)if(G[t]===e)return t},useSetter:function(){ee=!0},useSimple:function(){ee=!1}}),r({target:"Object",stat:!0,forced:!a,sham:!u},{create:function(e,t){return void 0===t?S(e):ie(S(e),t)},defineProperty:oe,defineProperties:ie,getOwnPropertyDescriptor:ue}),r({target:"Object",stat:!0,forced:!a},{getOwnPropertyNames:se,getOwnPropertySymbols:le}),r({target:"Object",stat:!0,forced:f(function(){D.f(1)})},{getOwnPropertySymbols:function(e){return D.f(O(e))}}),H&&r({target:"JSON",stat:!0,forced:!a||f(function(){var e=W();return"[null]"!=q([e])||"{}"!=q({a:e})||"{}"!=q(Object(e))})},{stringify:function(e){for(var t,n,r=[e],o=1;arguments.length>o;)r.push(arguments[o++]);if(n=t=r[1],(x(t)||void 0!==e)&&!re(e))return g(t)||(t=function(e,t){if("function"==typeof n&&(t=n.call(this,e,t)),!re(t))return t}),r[1]=t,q.apply(H,r)}}),W.prototype[$]||I(W.prototype,$,W.prototype.valueOf),d(W,"Symbol"),c[M]=!0},function(e,t,n){var r=n(48),o=n(185),i=Object.prototype;o!==i.toString&&r(i,"toString",o,{unsafe:!0})},function(e,t,n){"use strict";var r=n(34),o=n(102),i=n(64),a=n(58),u=n(133),s=a.set,l=a.getterFor("Array Iterator");e.exports=u(Array,"Array",function(e,t){s(this,{type:"Array Iterator",target:r(e),index:0,kind:t})},function(){var e=l(this),t=e.target,n=e.kind,r=e.index++;return!t||r>=t.length?(e.target=void 0,{value:void 0,done:!0}):"keys"==n?{value:r,done:!1}:"values"==n?{value:t[r],done:!1}:{value:[r,t[r]],done:!1}},"values"),i.Arguments=i.Array,o("keys"),o("values"),o("entries")},function(e,t,n){"use strict";var r=n(15),o=n(26),i=n(17),a=n(27),u=n(22),s=n(29).f,l=n(119),c=i.Symbol;if(o&&"function"==typeof c&&(!("description"in c.prototype)||void 0!==c().description)){var f={},p=function(){var e=arguments.length<1||void 0===arguments[0]?void 0:String(arguments[0]),t=this instanceof p?new c(e):void 0===e?c():c(e);return""===e&&(f[t]=!0),t};l(p,c);var d=p.prototype=c.prototype;d.constructor=p;var h=d.toString,m="Symbol(test)"==String(c("test")),y=/^Symbol\((.*)\)[^)]+$/;s(d,"description",{configurable:!0,get:function(){var e=u(this)?this.valueOf():this,t=h.call(e);if(a(f,e))return"";var n=m?t.slice(7,-1):t.replace(y,"$1");return""===n?void 0:n}}),r({global:!0,forced:!0},{Symbol:p})}},function(e,t,n){n(126)("iterator")},function(e,t,n){"use strict";var r=n(187),o=n(58),i=n(133),a=o.set,u=o.getterFor("String Iterator");i(String,"String",function(e){a(this,{type:"String Iterator",string:String(e),index:0})},function(){var e,t=u(this),n=t.string,o=t.index;return o>=n.length?{value:void 0,done:!0}:(e=r(n,o,!0),t.index+=e.length,{value:e,done:!1})})},function(e,t,n){var r=n(17),o=n(137),i=n(8),a=n(35),u=n(18),s=u("iterator"),l=u("toStringTag"),c=i.values;for(var f in o){var p=r[f],d=p&&p.prototype;if(d){if(d[s]!==c)try{a(d,s,c)}catch(e){d[s]=c}if(d[l]||a(d,l,f),o[f])for(var h in i)if(d[h]!==i[h])try{a(d,h,i[h])}catch(e){d[h]=i[h]}}}},function(e,t,n){var r=n(15),o=n(20),i=n(36),a=n(103),u=n(135);r({target:"Object",stat:!0,forced:o(function(){a(1)}),sham:!u},{getPrototypeOf:function(e){return a(i(e))}})},function(e,t,n){n(15)({target:"Object",stat:!0},{setPrototypeOf:n(136)})},function(e,t,n){var r=n(17),o=n(47).f,i=n(35),a=n(48),u=n(94),s=n(119),l=n(122);e.exports=function(e,t){var n,c,f,p,d,h=e.target,m=e.global,y=e.stat;if(n=m?r:y?r[h]||u(h,{}):(r[h]||{}).prototype)for(c in t){if(p=t[c],f=e.noTargetGet?(d=o(n,c))&&d.value:n[c],!l(m?c:h+(y?".":"#")+c,e.forced)&&void 0!==f){if(typeof p==typeof f)continue;s(p,f)}(e.sham||f&&f.sham)&&i(p,"sham",!0),a(n,c,p,e)}}},function(e,t,n){"use strict";function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}n.d(t,"a",function(){return r})},function(e,t,n){(function(t){var n="object",r=function(e){return e&&e.Math==Math&&e};e.exports=r(typeof globalThis==n&&globalThis)||r(typeof window==n&&window)||r(typeof self==n&&self)||r(typeof t==n&&t)||Function("return this")()}).call(this,n(33))},function(e,t,n){var r=n(17),o=n(56),i=n(74),a=n(123),u=r.Symbol,s=o("wks");e.exports=function(e){return s[e]||(s[e]=a&&u[e]||(a?u:i)("Symbol."+e))}},function(e,t,n){"use strict";var r=n(4),o=n(3),i=Object(r.c)(["font-size:",";letter-spacing:0.01em;font-weight:bold;"],Object(o.c)("16px")),a=Object(r.c)(["font-size:",";letter-spacing:0.01em;"],Object(o.c)("15px")),u=(Object(r.c)([""," font-weight:bold;"],a),Object(r.c)(["font-size:",";letter-spacing:0.06em;text-transform:uppercase;font-weight:bold;"],Object(o.c)("13px"))),s=Object(r.c)(["font-size:",";letter-spacing:0.01em;text-transform:uppercase;font-weight:bold;"],Object(o.c)("11px")),l=Object(r.c)(["font-size:",";"],Object(o.c)("15px"));n.d(t,"c",function(){return i}),n.d(t,"d",function(){return a}),n.d(t,"e",function(){return u}),n.d(t,"b",function(){return s}),n.d(t,"a",function(){return l})},function(e,t){e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t,n){"use strict";var r=n(15),o=n(20),i=n(77),a=n(22),u=n(36),s=n(45),l=n(60),c=n(101),f=n(61),p=n(18)("isConcatSpreadable"),d=!o(function(){var e=[];return e[p]=!1,e.concat()[0]!==e}),h=f("concat"),m=function(e){if(!a(e))return!1;var t=e[p];return void 0!==t?!!t:i(e)};r({target:"Array",proto:!0,forced:!d||!h},{concat:function(e){var t,n,r,o,i,a=u(this),f=c(a,0),p=0;for(t=-1,r=arguments.length;t9007199254740991)throw TypeError("Maximum allowed index exceeded");for(n=0;n=9007199254740991)throw TypeError("Maximum allowed index exceeded");l(f,p++,i)}return f.length=p,f}})},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,n){(function(e,n){var r=200,o="__lodash_hash_undefined__",i=9007199254740991,a="[object Arguments]",u="[object Boolean]",s="[object Date]",l="[object Function]",c="[object GeneratorFunction]",f="[object Map]",p="[object Number]",d="[object Object]",h="[object RegExp]",m="[object Set]",y="[object String]",b="[object Symbol]",v="[object ArrayBuffer]",g="[object DataView]",w="[object Float32Array]",x="[object Float64Array]",O="[object Int8Array]",_="[object Int16Array]",E="[object Int32Array]",k="[object Uint8Array]",S="[object Uint8ClampedArray]",C="[object Uint16Array]",j="[object Uint32Array]",T=/\w*$/,A=/^\[object .+?Constructor\]$/,P=/^(?:0|[1-9]\d*)$/,I={};I[a]=I["[object Array]"]=I[v]=I[g]=I[u]=I[s]=I[w]=I[x]=I[O]=I[_]=I[E]=I[f]=I[p]=I[d]=I[h]=I[m]=I[y]=I[b]=I[k]=I[S]=I[C]=I[j]=!0,I["[object Error]"]=I[l]=I["[object WeakMap]"]=!1;var R="object"==typeof e&&e&&e.Object===Object&&e,D="object"==typeof self&&self&&self.Object===Object&&self,F=R||D||Function("return this")(),L=t&&!t.nodeType&&t,M=L&&"object"==typeof n&&n&&!n.nodeType&&n,N=M&&M.exports===L;function z(e,t){return e.set(t[0],t[1]),e}function B(e,t){return e.add(t),e}function U(e,t,n,r){var o=-1,i=e?e.length:0;for(r&&i&&(n=e[++o]);++o-1},Se.prototype.set=function(e,t){var n=this.__data__,r=Pe(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},Ce.prototype.clear=function(){this.__data__={hash:new ke,map:new(de||Se),string:new ke}},Ce.prototype.delete=function(e){return Le(this,e).delete(e)},Ce.prototype.get=function(e){return Le(this,e).get(e)},Ce.prototype.has=function(e){return Le(this,e).has(e)},Ce.prototype.set=function(e,t){return Le(this,e).set(e,t),this},je.prototype.clear=function(){this.__data__=new Se},je.prototype.delete=function(e){return this.__data__.delete(e)},je.prototype.get=function(e){return this.__data__.get(e)},je.prototype.has=function(e){return this.__data__.has(e)},je.prototype.set=function(e,t){var n=this.__data__;if(n instanceof Se){var o=n.__data__;if(!de||o.length-1&&e%1==0&&e-1&&e%1==0&&e<=i}(e.length)&&!Ye(e)}var $e=ce||function(){return!1};function Ye(e){var t=Ge(e)?ee.call(e):"";return t==l||t==c}function Ge(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Ze(e){return qe(e)?Te(e):function(e){if(!Ue(e))return fe(e);var t=[];for(var n in Object(e))J.call(e,n)&&"constructor"!=n&&t.push(n);return t}(e)}n.exports=function(e){return Ie(e,!0,!0)}}).call(this,n(33),n(141)(e))},function(e,t,n){"use strict";var r=n(146),o=n(208),i=Object.prototype.toString;function a(e){return"[object Array]"===i.call(e)}function u(e){return null!==e&&"object"==typeof e}function s(e){return"[object Function]"===i.call(e)}function l(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),a(e))for(var n=0,r=e.length;n1;)try{return c.stringifyByChunk(e,r,n)}catch(e){n=Math.floor(n/2)}return c.stringifyByChar(e)}function p(e,t){for(var n=0;n *{padding:","}"],c.a,f.e,Object(l.c)("160px"),Object(l.c)("50px"),Object(l.c)("40px"),function(e){return e.theme.palette.white},function(e){return e.theme.palette.primary},function(e){return e.theme.palette.primaryDark},function(e){return e.theme.palette.primaryLight},Object(l.c)("1px"));function d(){return(d=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:this.active.collection;return this.refs[e].sort(_)}}]),e}();function _(e,t){var n=e.node.sortableInfo.index,r=t.node.sortableInfo.index;return n-r}var E=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t1?t-1:0),r=1;r2&&void 0!==arguments[2]?arguments[2]:{left:0,top:0};if(e){var r={left:n.left+e.offsetLeft,top:n.top+e.offsetTop};return e.parentNode===t?r:B(e.parentNode,t,r)}}function U(e){var t=e.lockOffset,n=e.width,r=e.height,o=t,i=t,a="px";if("string"==typeof t){var u=/^[+-]?\d*(?:\.\d*)?(px|%)$/.exec(t);x(null!==u,'lockOffset value should be a number or a string of a number followed by "px" or "%". Given %s',t),o=parseFloat(t),i=parseFloat(t),a=u[1]}return x(isFinite(o)&&isFinite(i),"lockOffset value should be a finite. Given %s",t),"%"===a&&(o=o*n/100,i=i*r/100),{x:o,y:i}}function V(e){return e instanceof HTMLElement?function(e){var t=window.getComputedStyle(e),n=/(auto|scroll)/;return["overflow","overflowX","overflowY"].find(function(e){return n.test(t[e])})}(e)?e:V(e.parentNode):null}var W={TAB:9,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40},H={Anchor:"A",Button:"BUTTON",Canvas:"CANVAS",Input:"INPUT",Option:"OPTION",Textarea:"TEXTAREA",Select:"SELECT"};function q(e){var n,o,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{withRef:!1};return o=n=function(n){function o(){return p(this,o),b(this,v(o).apply(this,arguments))}return w(o,n),h(o,[{key:"componentDidMount",value:function(){var e=r.findDOMNode(this);e.sortableHandle=!0}},{key:"getWrappedInstance",value:function(){return x(a.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableHandle() call"),this.refs.wrappedInstance}},{key:"render",value:function(){var n=a.withRef?"wrappedInstance":null;return t.createElement(e,i({ref:n},this.props))}}]),o}(t.Component),c(n,"displayName",M("sortableHandle",e)),o}function $(e){return null!=e.sortableHandle}var Y=function(){function e(t,n){p(this,e),this.container=t,this.onScrollCallback=n}return h(e,[{key:"clear",value:function(){clearInterval(this.interval),this.interval=null}},{key:"update",value:function(e){var t=this,n=e.translate,r=e.minTranslate,o=e.maxTranslate,i=e.width,a=e.height,u={x:0,y:0},s={x:1,y:1},l={x:10,y:10},c=this.container,f=c.scrollTop,p=c.scrollLeft,d=c.scrollHeight,h=c.scrollWidth,m=c.clientHeight,y=c.clientWidth,b=0===f,v=d-f-m==0,g=0===p,w=h-p-y==0;n.y>=o.y-a/2&&!v?(u.y=1,s.y=l.y*Math.abs((o.y-a/2-n.y)/a)):n.x>=o.x-i/2&&!w?(u.x=1,s.x=l.x*Math.abs((o.x-i/2-n.x)/i)):n.y<=r.y+a/2&&!b?(u.y=-1,s.y=l.y*Math.abs((n.y-a/2-r.y)/a)):n.x<=r.x+i/2&&!g&&(u.x=-1,s.x=l.x*Math.abs((n.x-i/2-r.x)/i)),this.interval&&(this.clear(),this.isAutoScrolling=!1),0===u.x&&0===u.y||(this.interval=setInterval(function(){t.isAutoScrolling=!0;var e={left:s.x*u.x,top:s.y*u.y};t.container.scrollTop+=e.top,t.container.scrollLeft+=e.left,t.onScrollCallback(e)},5))}}]),e}(),G={axis:n.oneOf(["x","y","xy"]),contentWindow:n.any,disableAutoscroll:n.bool,distance:n.number,getContainer:n.func,getHelperDimensions:n.func,helperClass:n.string,helperContainer:n.oneOfType([n.func,"undefined"==typeof HTMLElement?n.any:n.instanceOf(HTMLElement)]),hideSortableGhost:n.bool,keyboardSortingTransitionDuration:n.number,lockAxis:n.string,lockOffset:n.oneOfType([n.number,n.string,n.arrayOf(n.oneOfType([n.number,n.string]))]),lockToContainerEdges:n.bool,onSortEnd:n.func,onSortMove:n.func,onSortOver:n.func,onSortStart:n.func,pressDelay:n.number,pressThreshold:n.number,shouldCancelStart:n.func,transitionDuration:n.number,updateBeforeSortStart:n.func,useDragHandle:n.bool,useWindowAsScrollContainer:n.bool},Z={axis:"y",disableAutoscroll:!1,distance:0,getHelperDimensions:function(e){var t=e.node;return{height:t.offsetHeight,width:t.offsetWidth}},hideSortableGhost:!0,lockOffset:"50%",lockToContainerEdges:!1,pressDelay:0,pressThreshold:5,shouldCancelStart:function(e){return-1!==[H.Input,H.Textarea,H.Select,H.Option,H.Button].indexOf(e.target.tagName)||!!D(e.target,function(e){return"true"===e.contentEditable})},transitionDuration:300,useWindowAsScrollContainer:!1},K=Object.keys(G);function X(e){var o,a,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{withRef:!1};return a=o=function(n){function o(e){var t;return p(this,o),t=b(this,v(o).call(this,e)),c(y(y(t)),"handleStart",function(e){var n=t.props,r=n.distance,o=n.shouldCancelStart;if(2!==e.button&&!o(e)){t.touched=!0,t.position=z(e);var i=D(e.target,function(e){return null!=e.sortableInfo});if(i&&i.sortableInfo&&t.nodeIsChild(i)&&!t.state.sorting){var a=t.props.useDragHandle,u=i.sortableInfo,s=u.index,l=u.collection,c=u.disabled;if(c)return;if(a&&!D(e.target,$))return;t.manager.active={collection:l,index:s},function(e){return e.touches&&e.touches.length||e.changedTouches&&e.changedTouches.length}(e)||e.target.tagName!==H.Anchor||e.preventDefault(),r||(0===t.props.pressDelay?t.handlePress(e):t.pressTimer=setTimeout(function(){return t.handlePress(e)},t.props.pressDelay))}}}),c(y(y(t)),"nodeIsChild",function(e){return e.sortableInfo.manager===t.manager}),c(y(y(t)),"handleMove",function(e){var n=t.props,r=n.distance,o=n.pressThreshold;if(!t.state.sorting&&t.touched&&!t._awaitingUpdateBeforeSortStart){var i=z(e),a={x:t.position.x-i.x,y:t.position.y-i.y},u=Math.abs(a.x)+Math.abs(a.y);t.delta=a,r||o&&!(u>=o)?r&&u>=r&&t.manager.isActive()&&t.handlePress(e):(clearTimeout(t.cancelTimer),t.cancelTimer=setTimeout(t.cancel,0))}}),c(y(y(t)),"handleEnd",function(){t.touched=!1,t.cancel()}),c(y(y(t)),"cancel",function(){var e=t.props.distance,n=t.state.sorting;n||(e||clearTimeout(t.pressTimer),t.manager.active=null)}),c(y(y(t)),"handlePress",function(e){try{var n=t.manager.getActive(),r=function(){if(n){var r=function(){var n,r,o,l,y,b,v=d.sortableInfo.index,g=(n=d,{bottom:L((r=window.getComputedStyle(n)).marginBottom),left:L(r.marginLeft),right:L(r.marginRight),top:L(r.marginTop)}),w=t.scrollContainer.getBoundingClientRect(),x=a({collection:h,index:v,node:d});if(t.node=d,t.margin=g,t.width=x.width,t.height=x.height,t.marginOffset={x:t.margin.left+t.margin.right,y:Math.max(t.margin.top,t.margin.bottom)},t.boundingClientRect=d.getBoundingClientRect(),t.containerBoundingRect=w,t.index=v,t.newIndex=v,t.axis={x:i.indexOf("x")>=0,y:i.indexOf("y")>=0},t.offsetEdge=B(d,t.container),t.initialOffset=z(m?f({},e,{pageX:t.boundingClientRect.left,pageY:t.boundingClientRect.top}):e),t.initialScroll={left:t.scrollContainer.scrollLeft,top:t.scrollContainer.scrollTop},t.initialWindowScroll={left:window.pageXOffset,top:window.pageYOffset},t.helper=t.helperContainer.appendChild((l="input, textarea, select, canvas, [contenteditable]",y=(o=d).querySelectorAll(l),b=o.cloneNode(!0),C(b.querySelectorAll(l)).forEach(function(e,t){"file"!==e.type&&(e.value=y[t].value),"radio"===e.type&&e.name&&(e.name="__sortableClone__".concat(e.name)),e.tagName===H.Canvas&&y[t].width>0&&y[t].height>0&&e.getContext("2d").drawImage(y[t],0,0)}),b)),P(t.helper,{boxSizing:"border-box",height:"".concat(t.height,"px"),left:"".concat(t.boundingClientRect.left-g.left,"px"),pointerEvents:"none",position:"fixed",top:"".concat(t.boundingClientRect.top-g.top,"px"),width:"".concat(t.width,"px")}),m&&t.helper.focus(),s&&(t.sortableGhost=d,P(d,{opacity:0,visibility:"hidden"})),t.minTranslate={},t.maxTranslate={},m){var O=p?{top:0,left:0,width:t.contentWindow.innerWidth,height:t.contentWindow.innerHeight}:t.containerBoundingRect,_=O.top,E=O.left,k=O.width,S=O.height,j=_+S,A=E+k;t.axis.x&&(t.minTranslate.x=E-t.boundingClientRect.left,t.maxTranslate.x=A-(t.boundingClientRect.left+t.width)),t.axis.y&&(t.minTranslate.y=_-t.boundingClientRect.top,t.maxTranslate.y=j-(t.boundingClientRect.top+t.height))}else t.axis.x&&(t.minTranslate.x=(p?0:w.left)-t.boundingClientRect.left-t.width/2,t.maxTranslate.x=(p?t.contentWindow.innerWidth:w.left+w.width)-t.boundingClientRect.left-t.width/2),t.axis.y&&(t.minTranslate.y=(p?0:w.top)-t.boundingClientRect.top-t.height/2,t.maxTranslate.y=(p?t.contentWindow.innerHeight:w.top+w.height)-t.boundingClientRect.top-t.height/2);u&&u.split(" ").forEach(function(e){return t.helper.classList.add(e)}),t.listenerNode=e.touches?d:t.contentWindow,m?(t.listenerNode.addEventListener("wheel",t.handleKeyEnd,!0),t.listenerNode.addEventListener("mousedown",t.handleKeyEnd,!0),t.listenerNode.addEventListener("keydown",t.handleKeyDown)):(T.move.forEach(function(e){return t.listenerNode.addEventListener(e,t.handleSortMove,!1)}),T.end.forEach(function(e){return t.listenerNode.addEventListener(e,t.handleSortEnd,!1)})),t.setState({sorting:!0,sortingIndex:v}),c&&c({node:d,index:v,collection:h,isKeySorting:m},e),m&&t.keyMove(0)},o=t.props,i=o.axis,a=o.getHelperDimensions,u=o.helperClass,s=o.hideSortableGhost,l=o.updateBeforeSortStart,c=o.onSortStart,p=o.useWindowAsScrollContainer,d=n.node,h=n.collection,m=t.manager.isKeySorting,y=function(){if("function"==typeof l){t._awaitingUpdateBeforeSortStart=!0;var n=function(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)}(function(){var t=d.sortableInfo.index;return Promise.resolve(l({collection:h,index:t,node:d,isKeySorting:m},e)).then(function(){})},function(e,n){if(t._awaitingUpdateBeforeSortStart=!1,e)throw n;return n});if(n&&n.then)return n.then(function(){})}}();return y&&y.then?y.then(r):r()}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}),c(y(y(t)),"handleSortMove",function(e){var n=t.props.onSortMove;"function"==typeof e.preventDefault&&e.preventDefault(),t.updateHelperPosition(e),t.animateNodes(),t.autoscroll(),n&&n(e)}),c(y(y(t)),"handleSortEnd",function(e){var n=t.props,r=n.hideSortableGhost,o=n.onSortEnd,i=t.manager,a=i.active.collection,u=i.isKeySorting,s=t.manager.refs[a];t.listenerNode&&(u?(t.listenerNode.removeEventListener("wheel",t.handleKeyEnd,!0),t.listenerNode.removeEventListener("mousedown",t.handleKeyEnd,!0),t.listenerNode.removeEventListener("keydown",t.handleKeyDown)):(T.move.forEach(function(e){return t.listenerNode.removeEventListener(e,t.handleSortMove)}),T.end.forEach(function(e){return t.listenerNode.removeEventListener(e,t.handleSortEnd)}))),t.helper.parentNode.removeChild(t.helper),r&&t.sortableGhost&&P(t.sortableGhost,{opacity:"",visibility:""});for(var l=0,c=s.length;lr)){t.prevIndex=i,t.newIndex=o;var a=function(e,t,n){return et?e-1:e>n&&em?m/2:this.height/2,width:this.width>h?h/2:this.width/2},b=s&&d>this.index&&d<=l,v=s&&d=l,g={x:0,y:0},w=a[c].edgeOffset;w||(w=B(p,this.container),a[c].edgeOffset=w,s&&(a[c].boundingClientRect=N(p,o)));var x=c0&&a[c-1];x&&!x.edgeOffset&&(x.edgeOffset=B(x.node,this.container),s&&(x.boundingClientRect=N(x.node,o))),d!==this.index?(t&&R(p,t),this.axis.x?this.axis.y?v||dthis.containerBoundingRect.width-y.width&&x&&(g.x=x.edgeOffset.left-w.left,g.y=x.edgeOffset.top-w.top),null===this.newIndex&&(this.newIndex=d)):(b||d>this.index&&(u.left+i.left+y.width>=w.left&&u.top+i.top+y.height>=w.top||u.top+i.top+y.height>=w.top+m))&&(g.x=-(this.width+this.marginOffset.x),w.left+g.xthis.index&&u.left+i.left+y.width>=w.left?(g.x=-(this.width+this.marginOffset.x),this.newIndex=d):(v||dthis.index&&u.top+i.top+y.height>=w.top?(g.y=-(this.height+this.marginOffset.y),this.newIndex=d):(v||d1&&void 0!==arguments[1]?arguments[1]:{withRef:!1};return a=o=function(n){function o(){return p(this,o),b(this,v(o).apply(this,arguments))}return w(o,n),h(o,[{key:"componentDidMount",value:function(){this.register()}},{key:"componentDidUpdate",value:function(e){this.node&&(e.index!==this.props.index&&(this.node.sortableInfo.index=this.props.index),e.disabled!==this.props.disabled&&(this.node.sortableInfo.disabled=this.props.disabled)),e.collection!==this.props.collection&&(this.unregister(e.collection),this.register())}},{key:"componentWillUnmount",value:function(){this.unregister()}},{key:"register",value:function(){var e=this.props,t=e.collection,n=e.disabled,o=e.index,i=r.findDOMNode(this);i.sortableInfo={collection:t,disabled:n,index:o,manager:this.context.manager},this.node=i,this.ref={node:i},this.context.manager.add(t,this.ref)}},{key:"unregister",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props.collection;this.context.manager.remove(e,this.ref)}},{key:"getWrappedInstance",value:function(){return x(u.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableElement() call"),this.refs.wrappedInstance}},{key:"render",value:function(){var n=u.withRef?"wrappedInstance":null;return t.createElement(e,i({ref:n},j(this.props,J)))}}]),o}(t.Component),c(o,"displayName",M("sortableElement",e)),c(o,"contextTypes",{manager:n.object.isRequired}),c(o,"propTypes",Q),c(o,"defaultProps",{collection:0}),a}e.SortableContainer=X,e.sortableContainer=X,e.SortableElement=ee,e.sortableElement=ee,e.SortableHandle=q,e.sortableHandle=q,e.arrayMove=function(e,t,n){return"undefined"!=typeof console&&console.warn("Deprecation warning: arrayMove will no longer be exported by 'react-sortable-hoc' in the next major release. Please install the `array-move` package locally instead. https://www.npmjs.com/package/array-move"),(e=e.slice()).splice(n<0?e.length+n:n,0,e.splice(t,1)[0]),e},Object.defineProperty(e,"__esModule",{value:!0})}(t,n(0),n(2),n(25))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){var r=n(71),o=n(72);e.exports=function(e){return r(o(e))}},function(e,t,n){var r=n(26),o=n(29),i=n(54);e.exports=r?function(e,t,n){return o.f(e,t,i(1,n))}:function(e,t,n){return e[t]=n,e}},function(e,t,n){var r=n(72);e.exports=function(e){return Object(r(e))}},function(e,t,n){"use strict";var r=n(15),o=n(79),i=n(61),a=o(1);r({target:"Array",proto:!0,forced:!i("map")},{map:function(e){return a(this,e,arguments[1])}})},function(e,t,n){var r=n(15),o=n(182);r({target:"Array",stat:!0,forced:!n(132)(function(e){Array.from(e)})},{from:o})},function(e,t,n){"use strict";var r=n(48),o=n(28),i=n(20),a=n(186),u=/./.toString,s=RegExp.prototype,l=i(function(){return"/a/b"!=u.call({source:"a",flags:"b"})}),c="toString"!=u.name;(l||c)&&r(RegExp.prototype,"toString",function(){var e=o(this),t=String(e.source),n=e.flags;return"/"+t+"/"+String(void 0===n&&e instanceof RegExp&&!("flags"in s)?a.call(e):n)},{unsafe:!0})},function(e,t,n){var r=n(17),o=n(137),i=n(188),a=n(35);for(var u in o){var s=r[u],l=s&&s.prototype;if(l&&l.forEach!==i)try{a(l,"forEach",i)}catch(e){l.forEach=i}}},function(e,t,n){"use strict";function r(e,t){if(e.length!==t.length)return!1;for(var n=0;n0?o(r(e),9007199254740991):0}},function(e,t,n){var r=n(15),o=n(195);r({target:"Object",stat:!0,forced:Object.assign!==o},{assign:o})},function(e,t,n){var r=n(26),o=n(70),i=n(54),a=n(34),u=n(55),s=n(27),l=n(117),c=Object.getOwnPropertyDescriptor;t.f=r?c:function(e,t){if(e=a(e),t=u(t,!0),l)try{return c(e,t)}catch(e){}if(s(e,t))return i(!o.f.call(e,t),e[t])}},function(e,t,n){var r=n(17),o=n(56),i=n(35),a=n(27),u=n(94),s=n(118),l=n(58),c=l.get,f=l.enforce,p=String(s).split("toString");o("inspectSource",function(e){return s.call(e)}),(e.exports=function(e,t,n,o){var s=!!o&&!!o.unsafe,l=!!o&&!!o.enumerable,c=!!o&&!!o.noTargetGet;"function"==typeof n&&("string"!=typeof t||a(n,"name")||i(n,"name",t),f(n).source=p.join("string"==typeof t?t:"")),e!==r?(s?!c&&e[t]&&(l=!0):delete e[t],l?e[t]=n:i(e,t,n)):l?e[t]=n:u(t,n)})(Function.prototype,"toString",function(){return"function"==typeof this&&c(this).source||s.call(this)})},function(e,t,n){var r=n(15),o=n(36),i=n(63);r({target:"Object",stat:!0,forced:n(20)(function(){i(1)})},{keys:function(e){return i(o(e))}})},function(e,t,n){"use strict";function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}n.d(t,"a",function(){return r})},function(e,t,n){"use strict";var r=n(0),o=n.n(r).a.createContext();t.a=o},function(e,t,n){"use strict";var r=n(4),o=Object(r.c)(["overflow:visible;width:auto;margin:0;padding:0;text-align:inherit;color:inherit;border:none;background:transparent;line-height:normal;-webkit-font-smoothing:inherit;-moz-osx-font-smoothing:inherit;-webkit-appearance:none;"]);t.a=o},function(e,t,n){"use strict";function r(e){this.name=e||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}r.prototype={push:function(e){this.emit("data",e)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(e){this.emit("error",e)}return!0},error:function(e){return!this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit("error",e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(e,t){if(this._listeners[e])for(var n=0;n "+e:e}},e.exports=r},function(e,t){e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t,n){var r=n(22);e.exports=function(e,t){if(!r(e))return e;var n,o;if(t&&"function"==typeof(n=e.toString)&&!r(o=n.call(e)))return o;if("function"==typeof(n=e.valueOf)&&!r(o=n.call(e)))return o;if(!t&&"function"==typeof(n=e.toString)&&!r(o=n.call(e)))return o;throw TypeError("Can't convert object to primitive value")}},function(e,t,n){var r=n(17),o=n(94),i=n(57),a=r["__core-js_shared__"]||o("__core-js_shared__",{});(e.exports=function(e,t){return a[e]||(a[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.1.3",mode:i?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},function(e,t){e.exports=!1},function(e,t,n){var r,o,i,a=n(173),u=n(17),s=n(22),l=n(35),c=n(27),f=n(73),p=n(59),d=u.WeakMap;if(a){var h=new d,m=h.get,y=h.has,b=h.set;r=function(e,t){return b.call(h,e,t),t},o=function(e){return m.call(h,e)||{}},i=function(e){return y.call(h,e)}}else{var v=f("state");p[v]=!0,r=function(e,t){return l(e,v,t),t},o=function(e){return c(e,v)?e[v]:{}},i=function(e){return c(e,v)}}e.exports={set:r,get:o,has:i,enforce:function(e){return i(e)?o(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!s(t)||(n=o(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}}},function(e,t){e.exports={}},function(e,t,n){"use strict";var r=n(55),o=n(29),i=n(54);e.exports=function(e,t,n){var a=r(t);a in e?o.f(e,a,i(0,n)):e[a]=n}},function(e,t,n){var r=n(20),o=n(18)("species");e.exports=function(e){return!r(function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},1!==t[e](Boolean).foo})}},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var s,l=[],c=!1,f=-1;function p(){c&&s&&(c=!1,s.length?l=s.concat(l):f=-1,l.length&&d())}function d(){if(!c){var e=u(p);c=!0;for(var t=l.length;t;){for(s=l,l=[];++f1)for(var n=1;n=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function d(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.a.CancelToken.source(),r=n.token,o=n.cancel,i=new Promise(function(n,o){var i=t.headers,a=p(t,["headers"]),u=c({headers:c({"Content-Type":"application/json"},i||{}),url:e,method:"GET",mode:"cors",cancelToken:r},a);return s()(u).then(function(e){200===e.status?n(e.data):o(e)}).catch(function(e){s.a.isCancel(e)?console.log("Request canceled"):o(e)})});return i.cancel=o,i}function h(e,t,n,r,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void n(e)}u.done?t(s):Promise.resolve(s).then(r,o)}function m(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){h(i,r,o,a,u,"next",e)}function u(e){h(i,r,o,a,u,"throw",e)}a(void 0)})}}function y(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var b=function e(t){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),y(this,"cleanFetch",function(){n.lastFetch&&n.lastFetch.cancel&&n.lastFetch.cancel()}),y(this,"isEmpty",function(e){var t={status:!1};return e&&!a()(e)||(t.status=!0,t.message="Il campo deve essere compilato"),t}),y(this,"remoteValidation",function(){var e=m(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n.lastFetch=d("".concat(n.validationUrl,"&field=").concat(t)),e.abrupt("return",n.lastFetch.then(function(e){return n.lastFetch=void 0,delete e.value,e}).catch(function(e){}));case 2:case"end":return e.stop()}},e)}));return function(t){return e.apply(this,arguments)}}()),y(this,"validate",function(){var e=m(regeneratorRuntime.mark(function e(t){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n.cleanFetch(),!n.isRequired){e.next=5;break}if(!(r=n.isEmpty(t)).status){e.next=5;break}return e.abrupt("return",r.message);case 5:if(!n.validators){e.next=11;break}return e.next=8,n.remoteValidation(t);case 8:if(!(r=e.sent).status){e.next=11;break}return e.abrupt("return",r.message.join(", "));case 11:return e.abrupt("return",void 0);case 12:case"end":return e.stop()}},e)}));return function(t){return e.apply(this,arguments)}}()),this.isRequired=t.required||!1,this.validators=t.validators||!1,this.validationUrl="/wp-json/aeria/validate?validators=".concat(this.validators)};function v(e){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function g(){return(g=Object.assign||function(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function ee(e,t){for(var n=0;n-1&&(e.editor=tinymce.editors[t],e.editor.on("blur",function(n){return e.handleChangeInput(tinymce.editors[t].getContent())}),window&&window.dispatchEvent(new CustomEvent("aeriaInitWysiwyg",{detail:e.editor})))},1e3)}},{key:"render",value:function(){var e=this.props.options;if(!e)return null;var t="".concat(this.props.parentID,"-").concat(e.id),n=e.value,r=e.defaultValue,i=void 0===r?"":r;return o.a.createElement($,{label:e.label,tooltip:e.description},o.a.createElement(Pe,{id:t,name:t,value:n||i,error:e.error,onChange:this.handleChangeInput,onBlur:this.props.handleBlur}))}}])&&Re(n.prototype,i),a&&Re(n,a),t}())||Te,Ne=(n(108),n(37),n(154),n(162)),ze=n.n(Ne);function Be(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var Ue=n(5);function Ve(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);tr&&(r=(t=t.trim()).charCodeAt(0)),r){case 38:return t.replace(m,"$1"+e.trim());case 58:return e.trim()+t.replace(m,"$1"+e.trim());default:if(0<1*n&&0s.charCodeAt(8))break;case 115:a=a.replace(s,"-webkit-"+s)+";"+a;break;case 207:case 102:a=a.replace(s,"-webkit-"+(102u.charCodeAt(0)&&(u=u.trim()),u=[u],0d)&&(z=(V=V.replace(" ",":")).length),0=4;)t=1540483477*(65535&(t=255&e.charCodeAt(o)|(255&e.charCodeAt(++o))<<8|(255&e.charCodeAt(++o))<<16|(255&e.charCodeAt(++o))<<24))+((1540483477*(t>>>16)&65535)<<16),r=1540483477*(65535&r)+((1540483477*(r>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),n-=4,++o;switch(n){case 3:r^=(255&e.charCodeAt(o+2))<<16;case 2:r^=(255&e.charCodeAt(o+1))<<8;case 1:r=1540483477*(65535&(r^=255&e.charCodeAt(o)))+((1540483477*(r>>>16)&65535)<<16)}return r=1540483477*(65535&(r^=r>>>13))+((1540483477*(r>>>16)&65535)<<16),((r^=r>>>15)>>>0).toString(36)},ft=n(85),pt=n(86),dt=/[A-Z]|^ms/g,ht=/_EMO_([^_]+?)_([^]*?)_EMO_/g,mt=function(e){return 45===e.charCodeAt(1)},yt=Object(pt.a)(function(e){return mt(e)?e:e.replace(dt,"-$&").toLowerCase()}),bt=function(e,t){if(null==t||"boolean"==typeof t)return"";switch(e){case"animation":case"animationName":"string"==typeof t&&(t=t.replace(ht,function(e,t,n){return gt={name:t,styles:n,next:gt},t}))}return 1===ft.a[e]||mt(e)||"number"!=typeof t||0===t?t:t+"px"};function vt(e,t,n,r){if(null==n)return"";if(void 0!==n.__emotion_styles)return n;switch(typeof n){case"boolean":return"";case"object":if(1===n.anim)return gt={name:n.name,styles:n.styles,next:gt},n.name;if(void 0!==n.styles){var o=n.next;if(void 0!==o)for(;void 0!==o;)gt={name:o.name,styles:o.styles,next:gt},o=o.next;return n.styles}return function(e,t,n){var r="";if(Array.isArray(n))for(var o=0;o-1}function zt(e){return Nt(e)?window.pageYOffset:e.scrollTop}function Bt(e,t){Nt(e)?window.scrollTo(0,t):e.scrollTop=t}function Ut(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:200,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ft,o=zt(e),i=t-o,a=10,u=0;!function t(){var s,l=i*((s=(s=u+=a)/n-1)*s*s+1)+o;Bt(e,l),u=d)return{placement:"bottom",maxHeight:t};if(_>=d&&!a)return i&&Ut(s,E,160),{placement:"bottom",maxHeight:t};if(!a&&_>=r||a&&x>=r)return i&&Ut(s,E,160),{placement:"bottom",maxHeight:a?x-v:_-v};if("auto"===o||a){var S=t,C=a?w:O;return C>=r&&(S=Math.min(C-v-u.controlHeight,t)),{placement:"top",maxHeight:S}}if("bottom"===o)return Bt(s,E),{placement:"bottom",maxHeight:t};break;case"top":if(w>=d)return{placement:"top",maxHeight:t};if(O>=d&&!a)return i&&Ut(s,k,160),{placement:"top",maxHeight:t};if(!a&&O>=r||a&&w>=r){var j=t;return(!a&&O>=r||a&&w>=r)&&(j=a?w-g:O-g),i&&Ut(s,k,160),{placement:"top",maxHeight:j}}return{placement:"bottom",maxHeight:t};default:throw new Error('Invalid placement provided "'.concat(o,'".'))}return l}var $t=function(e){return"auto"===e?"bottom":e},Yt=function(e){function t(){var e,n;qe(this,t);for(var r=arguments.length,o=new Array(r),i=0;i0,h=c-f-l,m=!1;h>t&&n.isBottom&&(i&&i(e),n.isBottom=!1),d&&n.isTop&&(u&&u(e),n.isTop=!1),d&&t>h?(o&&!n.isBottom&&o(e),p.scrollTop=c,m=!0,n.isBottom=!0):!d&&-t>l&&(a&&!n.isTop&&a(e),p.scrollTop=0,m=!0,n.isTop=!0),m&&n.cancelScroll(e)}),We(Object(Ke.a)(Object(Ke.a)(n)),"onWheel",function(e){n.handleEventDelta(e,e.deltaY)}),We(Object(Ke.a)(Object(Ke.a)(n)),"onTouchStart",function(e){n.touchStart=e.changedTouches[0].clientY}),We(Object(Ke.a)(Object(Ke.a)(n)),"onTouchMove",function(e){var t=n.touchStart-e.changedTouches[0].clientY;n.handleEventDelta(e,t)}),We(Object(Ke.a)(Object(Ke.a)(n)),"getScrollTarget",function(e){n.scrollTarget=e}),n}return et(t,r["Component"]),Ye(t,[{key:"componentDidMount",value:function(){this.startListening(this.scrollTarget)}},{key:"componentWillUnmount",value:function(){this.stopListening(this.scrollTarget)}},{key:"startListening",value:function(e){e&&(e.scrollHeight<=e.clientHeight||("function"==typeof e.addEventListener&&e.addEventListener("wheel",this.onWheel,!1),"function"==typeof e.addEventListener&&e.addEventListener("touchstart",this.onTouchStart,!1),"function"==typeof e.addEventListener&&e.addEventListener("touchmove",this.onTouchMove,!1)))}},{key:"stopListening",value:function(e){e.scrollHeight<=e.clientHeight||("function"==typeof e.removeEventListener&&e.removeEventListener("wheel",this.onWheel,!1),"function"==typeof e.removeEventListener&&e.removeEventListener("touchstart",this.onTouchStart,!1),"function"==typeof e.removeEventListener&&e.removeEventListener("touchmove",this.onTouchMove,!1))}},{key:"render",value:function(){return o.a.createElement(In,{innerRef:this.getScrollTarget},this.props.children)}}]),t}(),qn=function(e){function t(){return qe(this,t),Xe(this,Object(Qe.a)(t).apply(this,arguments))}return et(t,r["Component"]),Ye(t,[{key:"render",value:function(){var e=this.props,t=e.isEnabled,n=Be(e,["isEnabled"]);return t?o.a.createElement(Hn,n):this.props.children}}]),t}();We(qn,"defaultProps",{isEnabled:!0});var $n=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.isSearchable,r=t.isMulti,o=t.label,i=t.isDisabled;switch(e){case"menu":return"Use Up and Down to choose options".concat(i?"":", press Enter to select the currently focused option",", press Escape to exit the menu, press Tab to select the option and exit the menu.");case"input":return"".concat(o||"Select"," is focused ").concat(n?",type to refine list":"",", press Down to open the menu, ").concat(r?" press left to focus selected values":"");case"value":return"Use left and right to toggle between focused values, press Backspace to remove the currently focused value"}},Yn=function(e,t){var n=t.value,r=t.isDisabled;if(n)switch(e){case"deselect-option":case"pop-value":case"remove-value":return"option ".concat(n,", deselected.");case"select-option":return"option ".concat(n,r?" is disabled. Select another option.":", selected.")}},Gn=function(e){return!!e.isDisabled},Zn={clearIndicator:dn,container:function(e){var t=e.isDisabled;return{label:"container",direction:e.isRtl?"rtl":null,pointerEvents:t?"none":null,position:"relative"}},control:function(e){var t=e.isDisabled,n=e.isFocused,r=e.theme,o=r.colors,i=r.borderRadius,a=r.spacing;return{label:"control",alignItems:"center",backgroundColor:t?o.neutral5:o.neutral0,borderColor:t?o.neutral10:n?o.primary:o.neutral20,borderRadius:i,borderStyle:"solid",borderWidth:1,boxShadow:n?"0 0 0 1px ".concat(o.primary):null,cursor:"default",display:"flex",flexWrap:"wrap",justifyContent:"space-between",minHeight:a.controlHeight,outline:"0 !important",position:"relative",transition:"all 100ms","&:hover":{borderColor:n?o.primary:o.neutral30}}},dropdownIndicator:pn,group:function(e){var t=e.theme.spacing;return{paddingBottom:2*t.baseUnit,paddingTop:2*t.baseUnit}},groupHeading:function(e){var t=e.theme.spacing;return{label:"group",color:"#999",cursor:"default",display:"block",fontSize:"75%",fontWeight:"500",marginBottom:"0.25em",paddingLeft:3*t.baseUnit,paddingRight:3*t.baseUnit,textTransform:"uppercase"}},indicatorsContainer:function(){return{alignItems:"center",alignSelf:"stretch",display:"flex",flexShrink:0}},indicatorSeparator:function(e){var t=e.isDisabled,n=e.theme,r=n.spacing.baseUnit,o=n.colors;return{label:"indicatorSeparator",alignSelf:"stretch",backgroundColor:t?o.neutral10:o.neutral20,marginBottom:2*r,marginTop:2*r,width:1}},input:function(e){var t=e.isDisabled,n=e.theme,r=n.spacing,o=n.colors;return{margin:r.baseUnit/2,paddingBottom:r.baseUnit/2,paddingTop:r.baseUnit/2,visibility:t?"hidden":"visible",color:o.neutral80}},loadingIndicator:function(e){var t=e.isFocused,n=e.size,r=e.theme,o=r.colors,i=r.spacing.baseUnit;return{label:"loadingIndicator",color:t?o.neutral60:o.neutral20,display:"flex",padding:2*i,transition:"color 150ms",alignSelf:"center",fontSize:n,lineHeight:1,marginRight:n,textAlign:"center",verticalAlign:"middle"}},loadingMessage:Kt,menu:function(e){var t,n=e.placement,r=e.theme,o=r.borderRadius,i=r.spacing,a=r.colors;return We(t={label:"menu"},function(e){return e?{bottom:"top",top:"bottom"}[e]:"bottom"}(n),"100%"),We(t,"backgroundColor",a.neutral0),We(t,"borderRadius",o),We(t,"boxShadow","0 0 0 1px hsla(0, 0%, 0%, 0.1), 0 4px 11px hsla(0, 0%, 0%, 0.1)"),We(t,"marginBottom",i.menuGutter),We(t,"marginTop",i.menuGutter),We(t,"position","absolute"),We(t,"width","100%"),We(t,"zIndex",1),t},menuList:function(e){var t=e.maxHeight,n=e.theme.spacing.baseUnit;return{maxHeight:t,overflowY:"auto",paddingBottom:n,paddingTop:n,position:"relative",WebkitOverflowScrolling:"touch"}},menuPortal:function(e){var t=e.rect,n=e.offset,r=e.position;return{left:t.left,position:r,top:n,width:t.width,zIndex:1}},multiValue:function(e){var t=e.theme,n=t.spacing,r=t.borderRadius;return{label:"multiValue",backgroundColor:t.colors.neutral10,borderRadius:r/2,display:"flex",margin:n.baseUnit/2,minWidth:0}},multiValueLabel:function(e){var t=e.theme,n=t.borderRadius,r=t.colors,o=e.cropWithEllipsis;return{borderRadius:n/2,color:r.neutral80,fontSize:"85%",overflow:"hidden",padding:3,paddingLeft:6,textOverflow:o?"ellipsis":null,whiteSpace:"nowrap"}},multiValueRemove:function(e){var t=e.theme,n=t.spacing,r=t.borderRadius,o=t.colors;return{alignItems:"center",borderRadius:r/2,backgroundColor:e.isFocused&&o.dangerLight,display:"flex",paddingLeft:n.baseUnit,paddingRight:n.baseUnit,":hover":{backgroundColor:o.dangerLight,color:o.danger}}},noOptionsMessage:Zt,option:function(e){var t=e.isDisabled,n=e.isFocused,r=e.isSelected,o=e.theme,i=o.spacing,a=o.colors;return{label:"option",backgroundColor:r?a.primary:n?a.primary25:"transparent",color:t?a.neutral20:r?a.neutral0:"inherit",cursor:"default",display:"block",fontSize:"inherit",padding:"".concat(2*i.baseUnit,"px ").concat(3*i.baseUnit,"px"),width:"100%",userSelect:"none",WebkitTapHighlightColor:"rgba(0, 0, 0, 0)",":active":{backgroundColor:!t&&(r?a.primary:a.primary50)}}},placeholder:function(e){var t=e.theme,n=t.spacing;return{label:"placeholder",color:t.colors.neutral50,marginLeft:n.baseUnit/2,marginRight:n.baseUnit/2,position:"absolute",top:"50%",transform:"translateY(-50%)"}},singleValue:function(e){var t=e.isDisabled,n=e.theme,r=n.spacing,o=n.colors;return{label:"singleValue",color:t?o.neutral40:o.neutral80,marginLeft:r.baseUnit/2,marginRight:r.baseUnit/2,maxWidth:"calc(100% - ".concat(2*r.baseUnit,"px)"),overflow:"hidden",position:"absolute",textOverflow:"ellipsis",whiteSpace:"nowrap",top:"50%",transform:"translateY(-50%)"}},valueContainer:function(e){var t=e.theme.spacing;return{alignItems:"center",display:"flex",flex:1,flexWrap:"wrap",padding:"".concat(t.baseUnit/2,"px ").concat(2*t.baseUnit,"px"),WebkitOverflowScrolling:"touch",position:"relative",overflow:"hidden"}}};var Kn,Xn={borderRadius:4,colors:{primary:"#2684FF",primary75:"#4C9AFF",primary50:"#B2D4FF",primary25:"#DEEBFF",danger:"#DE350B",dangerLight:"#FFBDAD",neutral0:"hsl(0, 0%, 100%)",neutral5:"hsl(0, 0%, 95%)",neutral10:"hsl(0, 0%, 90%)",neutral20:"hsl(0, 0%, 80%)",neutral30:"hsl(0, 0%, 70%)",neutral40:"hsl(0, 0%, 60%)",neutral50:"hsl(0, 0%, 50%)",neutral60:"hsl(0, 0%, 40%)",neutral70:"hsl(0, 0%, 30%)",neutral80:"hsl(0, 0%, 20%)",neutral90:"hsl(0, 0%, 10%)"},spacing:{baseUnit:4,controlHeight:38,menuGutter:8}},Qn={backspaceRemovesValue:!0,blurInputOnSelect:Vt(),captureMenuScroll:!Vt(),closeMenuOnSelect:!0,closeMenuOnScroll:!1,components:{},controlShouldRenderValue:!0,escapeClearsValue:!1,filterOption:function(e,t){var n=He({ignoreCase:!0,ignoreAccents:!0,stringify:jn,trim:!0,matchFrom:"any"},Kn),r=n.ignoreCase,o=n.ignoreAccents,i=n.stringify,a=n.trim,u=n.matchFrom,s=a?Cn(t):t,l=a?Cn(i(e)):i(e);return r&&(s=s.toLowerCase(),l=l.toLowerCase()),o&&(s=Sn(s),l=Sn(l)),"start"===u?l.substr(0,s.length)===s:l.indexOf(s)>-1},formatGroupLabel:function(e){return e.label},getOptionLabel:function(e){return e.label},getOptionValue:function(e){return e.value},isDisabled:!1,isLoading:!1,isMulti:!1,isRtl:!1,isSearchable:!0,isOptionDisabled:Gn,loadingMessage:function(){return"Loading..."},maxMenuHeight:300,minMenuHeight:140,menuIsOpen:!1,menuPlacement:"bottom",menuPosition:"absolute",menuShouldBlockScroll:!1,menuShouldScrollIntoView:!function(){try{return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}catch(e){return!1}}(),noOptionsMessage:function(){return"No options"},openMenuOnFocus:!1,openMenuOnClick:!0,options:[],pageSize:5,placeholder:"Select...",screenReaderStatus:function(e){var t=e.count;return"".concat(t," result").concat(1!==t?"s":""," available")},styles:{},tabIndex:"0",tabSelectsValue:!0},Jn=1,er=function(e){function t(e){var n;qe(this,t),n=Xe(this,Object(Qe.a)(t).call(this,e)),We(Object(Ke.a)(Object(Ke.a)(n)),"state",{ariaLiveSelection:"",ariaLiveContext:"",focusedOption:null,focusedValue:null,inputIsHidden:!1,isFocused:!1,menuOptions:{render:[],focusable:[]},selectValue:[]}),We(Object(Ke.a)(Object(Ke.a)(n)),"blockOptionHover",!1),We(Object(Ke.a)(Object(Ke.a)(n)),"isComposing",!1),We(Object(Ke.a)(Object(Ke.a)(n)),"clearFocusValueOnUpdate",!1),We(Object(Ke.a)(Object(Ke.a)(n)),"commonProps",void 0),We(Object(Ke.a)(Object(Ke.a)(n)),"components",void 0),We(Object(Ke.a)(Object(Ke.a)(n)),"hasGroups",!1),We(Object(Ke.a)(Object(Ke.a)(n)),"initialTouchX",0),We(Object(Ke.a)(Object(Ke.a)(n)),"initialTouchY",0),We(Object(Ke.a)(Object(Ke.a)(n)),"inputIsHiddenAfterUpdate",void 0),We(Object(Ke.a)(Object(Ke.a)(n)),"instancePrefix",""),We(Object(Ke.a)(Object(Ke.a)(n)),"openAfterFocus",!1),We(Object(Ke.a)(Object(Ke.a)(n)),"scrollToFocusedOptionOnUpdate",!1),We(Object(Ke.a)(Object(Ke.a)(n)),"userIsDragging",void 0),We(Object(Ke.a)(Object(Ke.a)(n)),"controlRef",null),We(Object(Ke.a)(Object(Ke.a)(n)),"getControlRef",function(e){n.controlRef=e}),We(Object(Ke.a)(Object(Ke.a)(n)),"focusedOptionRef",null),We(Object(Ke.a)(Object(Ke.a)(n)),"getFocusedOptionRef",function(e){n.focusedOptionRef=e}),We(Object(Ke.a)(Object(Ke.a)(n)),"menuListRef",null),We(Object(Ke.a)(Object(Ke.a)(n)),"getMenuListRef",function(e){n.menuListRef=e}),We(Object(Ke.a)(Object(Ke.a)(n)),"inputRef",null),We(Object(Ke.a)(Object(Ke.a)(n)),"getInputRef",function(e){n.inputRef=e}),We(Object(Ke.a)(Object(Ke.a)(n)),"cacheComponents",function(e){n.components=En({components:e})}),We(Object(Ke.a)(Object(Ke.a)(n)),"focus",n.focusInput),We(Object(Ke.a)(Object(Ke.a)(n)),"blur",n.blurInput),We(Object(Ke.a)(Object(Ke.a)(n)),"onChange",function(e,t){var r=n.props;(0,r.onChange)(e,He({},t,{name:r.name}))}),We(Object(Ke.a)(Object(Ke.a)(n)),"setValue",function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"set-value",r=arguments.length>2?arguments[2]:void 0,o=n.props,i=o.closeMenuOnSelect,a=o.isMulti;n.onInputChange("",{action:"set-value"}),i&&(n.inputIsHiddenAfterUpdate=!a,n.onMenuClose()),n.clearFocusValueOnUpdate=!0,n.onChange(e,{action:t,option:r})}),We(Object(Ke.a)(Object(Ke.a)(n)),"selectOption",function(e){var t=n.props,r=t.blurInputOnSelect,o=t.isMulti,i=n.state.selectValue;if(o)if(n.isOptionSelected(e,i)){var a=n.getOptionValue(e);n.setValue(i.filter(function(e){return n.getOptionValue(e)!==a}),"deselect-option",e),n.announceAriaLiveSelection({event:"deselect-option",context:{value:n.getOptionLabel(e)}})}else n.isOptionDisabled(e,i)?n.announceAriaLiveSelection({event:"select-option",context:{value:n.getOptionLabel(e),isDisabled:!0}}):(n.setValue([].concat(Ve(i),[e]),"select-option",e),n.announceAriaLiveSelection({event:"select-option",context:{value:n.getOptionLabel(e)}}));else n.isOptionDisabled(e,i)?n.announceAriaLiveSelection({event:"select-option",context:{value:n.getOptionLabel(e),isDisabled:!0}}):(n.setValue(e,"select-option"),n.announceAriaLiveSelection({event:"select-option",context:{value:n.getOptionLabel(e)}}));r&&n.blurInput()}),We(Object(Ke.a)(Object(Ke.a)(n)),"removeValue",function(e){var t=n.state.selectValue,r=n.getOptionValue(e),o=t.filter(function(e){return n.getOptionValue(e)!==r});n.onChange(o.length?o:null,{action:"remove-value",removedValue:e}),n.announceAriaLiveSelection({event:"remove-value",context:{value:e?n.getOptionLabel(e):""}}),n.focusInput()}),We(Object(Ke.a)(Object(Ke.a)(n)),"clearValue",function(){var e=n.props.isMulti;n.onChange(e?[]:null,{action:"clear"})}),We(Object(Ke.a)(Object(Ke.a)(n)),"popValue",function(){var e=n.state.selectValue,t=e[e.length-1],r=e.slice(0,e.length-1);n.announceAriaLiveSelection({event:"pop-value",context:{value:t?n.getOptionLabel(t):""}}),n.onChange(r.length?r:null,{action:"pop-value",removedValue:t})}),We(Object(Ke.a)(Object(Ke.a)(n)),"getOptionLabel",function(e){return n.props.getOptionLabel(e)}),We(Object(Ke.a)(Object(Ke.a)(n)),"getOptionValue",function(e){return n.props.getOptionValue(e)}),We(Object(Ke.a)(Object(Ke.a)(n)),"getStyles",function(e,t){var r=Zn[e](t);r.boxSizing="border-box";var o=n.props.styles[e];return o?o(r,t):r}),We(Object(Ke.a)(Object(Ke.a)(n)),"getElementId",function(e){return"".concat(n.instancePrefix,"-").concat(e)}),We(Object(Ke.a)(Object(Ke.a)(n)),"getActiveDescendentId",function(){var e=n.props.menuIsOpen,t=n.state,r=t.menuOptions,o=t.focusedOption;if(o&&e){var i=r.focusable.indexOf(o),a=r.render[i];return a&&a.key}}),We(Object(Ke.a)(Object(Ke.a)(n)),"announceAriaLiveSelection",function(e){var t=e.event,r=e.context;n.setState({ariaLiveSelection:Yn(t,r)})}),We(Object(Ke.a)(Object(Ke.a)(n)),"announceAriaLiveContext",function(e){var t=e.event,r=e.context;n.setState({ariaLiveContext:$n(t,He({},r,{label:n.props["aria-label"]}))})}),We(Object(Ke.a)(Object(Ke.a)(n)),"onMenuMouseDown",function(e){0===e.button&&(e.stopPropagation(),e.preventDefault(),n.focusInput())}),We(Object(Ke.a)(Object(Ke.a)(n)),"onMenuMouseMove",function(e){n.blockOptionHover=!1}),We(Object(Ke.a)(Object(Ke.a)(n)),"onControlMouseDown",function(e){var t=n.props.openMenuOnClick;n.state.isFocused?n.props.menuIsOpen?"INPUT"!==e.target.tagName&&n.onMenuClose():t&&n.openMenu("first"):(t&&(n.openAfterFocus=!0),n.focusInput()),"INPUT"!==e.target.tagName&&e.preventDefault()}),We(Object(Ke.a)(Object(Ke.a)(n)),"onDropdownIndicatorMouseDown",function(e){if(!(e&&"mousedown"===e.type&&0!==e.button||n.props.isDisabled)){var t=n.props,r=t.isMulti,o=t.menuIsOpen;n.focusInput(),o?(n.inputIsHiddenAfterUpdate=!r,n.onMenuClose()):n.openMenu("first"),e.preventDefault(),e.stopPropagation()}}),We(Object(Ke.a)(Object(Ke.a)(n)),"onClearIndicatorMouseDown",function(e){e&&"mousedown"===e.type&&0!==e.button||(n.clearValue(),e.stopPropagation(),n.openAfterFocus=!1,"touchend"===e.type?n.focusInput():setTimeout(function(){return n.focusInput()}))}),We(Object(Ke.a)(Object(Ke.a)(n)),"onScroll",function(e){"boolean"==typeof n.props.closeMenuOnScroll?e.target instanceof HTMLElement&&Nt(e.target)&&n.props.onMenuClose():"function"==typeof n.props.closeMenuOnScroll&&n.props.closeMenuOnScroll(e)&&n.props.onMenuClose()}),We(Object(Ke.a)(Object(Ke.a)(n)),"onCompositionStart",function(){n.isComposing=!0}),We(Object(Ke.a)(Object(Ke.a)(n)),"onCompositionEnd",function(){n.isComposing=!1}),We(Object(Ke.a)(Object(Ke.a)(n)),"onTouchStart",function(e){var t=e.touches.item(0);t&&(n.initialTouchX=t.clientX,n.initialTouchY=t.clientY,n.userIsDragging=!1)}),We(Object(Ke.a)(Object(Ke.a)(n)),"onTouchMove",function(e){var t=e.touches.item(0);if(t){var r=Math.abs(t.clientX-n.initialTouchX),o=Math.abs(t.clientY-n.initialTouchY);n.userIsDragging=r>5||o>5}}),We(Object(Ke.a)(Object(Ke.a)(n)),"onTouchEnd",function(e){n.userIsDragging||(n.controlRef&&!n.controlRef.contains(e.target)&&n.menuListRef&&!n.menuListRef.contains(e.target)&&n.blurInput(),n.initialTouchX=0,n.initialTouchY=0)}),We(Object(Ke.a)(Object(Ke.a)(n)),"onControlTouchEnd",function(e){n.userIsDragging||n.onControlMouseDown(e)}),We(Object(Ke.a)(Object(Ke.a)(n)),"onClearIndicatorTouchEnd",function(e){n.userIsDragging||n.onClearIndicatorMouseDown(e)}),We(Object(Ke.a)(Object(Ke.a)(n)),"onDropdownIndicatorTouchEnd",function(e){n.userIsDragging||n.onDropdownIndicatorMouseDown(e)}),We(Object(Ke.a)(Object(Ke.a)(n)),"handleInputChange",function(e){var t=e.currentTarget.value;n.inputIsHiddenAfterUpdate=!1,n.onInputChange(t,{action:"input-change"}),n.onMenuOpen()}),We(Object(Ke.a)(Object(Ke.a)(n)),"onInputFocus",function(e){var t=n.props,r=t.isSearchable,o=t.isMulti;n.props.onFocus&&n.props.onFocus(e),n.inputIsHiddenAfterUpdate=!1,n.announceAriaLiveContext({event:"input",context:{isSearchable:r,isMulti:o}}),n.setState({isFocused:!0}),(n.openAfterFocus||n.props.openMenuOnFocus)&&n.openMenu("first"),n.openAfterFocus=!1}),We(Object(Ke.a)(Object(Ke.a)(n)),"onInputBlur",function(e){n.menuListRef&&n.menuListRef.contains(document.activeElement)?n.inputRef.focus():(n.props.onBlur&&n.props.onBlur(e),n.onInputChange("",{action:"input-blur"}),n.onMenuClose(),n.setState({focusedValue:null,isFocused:!1}))}),We(Object(Ke.a)(Object(Ke.a)(n)),"onOptionHover",function(e){n.blockOptionHover||n.state.focusedOption===e||n.setState({focusedOption:e})}),We(Object(Ke.a)(Object(Ke.a)(n)),"shouldHideSelectedOptions",function(){var e=n.props,t=e.hideSelectedOptions,r=e.isMulti;return void 0===t?r:t}),We(Object(Ke.a)(Object(Ke.a)(n)),"onKeyDown",function(e){var t=n.props,r=t.isMulti,o=t.backspaceRemovesValue,i=t.escapeClearsValue,a=t.inputValue,u=t.isClearable,s=t.isDisabled,l=t.menuIsOpen,c=t.onKeyDown,f=t.tabSelectsValue,p=t.openMenuOnFocus,d=n.state,h=d.focusedOption,m=d.focusedValue,y=d.selectValue;if(!(s||"function"==typeof c&&(c(e),e.defaultPrevented))){switch(n.blockOptionHover=!0,e.key){case"ArrowLeft":if(!r||a)return;n.focusValue("previous");break;case"ArrowRight":if(!r||a)return;n.focusValue("next");break;case"Delete":case"Backspace":if(a)return;if(m)n.removeValue(m);else{if(!o)return;r?n.popValue():u&&n.clearValue()}break;case"Tab":if(n.isComposing)return;if(e.shiftKey||!l||!f||!h||p&&n.isOptionSelected(h,y))return;n.selectOption(h);break;case"Enter":if(229===e.keyCode)break;if(l){if(!h)return;if(n.isComposing)return;n.selectOption(h);break}return;case"Escape":l?(n.inputIsHiddenAfterUpdate=!1,n.onInputChange("",{action:"menu-close"}),n.onMenuClose()):u&&i&&n.clearValue();break;case" ":if(a)return;if(!l){n.openMenu("first");break}if(!h)return;n.selectOption(h);break;case"ArrowUp":l?n.focusOption("up"):n.openMenu("last");break;case"ArrowDown":l?n.focusOption("down"):n.openMenu("first");break;case"PageUp":if(!l)return;n.focusOption("pageup");break;case"PageDown":if(!l)return;n.focusOption("pagedown");break;case"Home":if(!l)return;n.focusOption("first");break;case"End":if(!l)return;n.focusOption("last");break;default:return}e.preventDefault()}});var r=e.value;n.cacheComponents=Object(tt.a)(n.cacheComponents,rn).bind(Object(Ke.a)(Object(Ke.a)(n))),n.cacheComponents(e.components),n.instancePrefix="react-select-"+(n.props.instanceId||++Jn);var o=Mt(r),i=e.menuIsOpen?n.buildMenuOptions(e,o):{render:[],focusable:[]};return n.state.menuOptions=i,n.state.selectValue=o,n}return et(t,r["Component"]),Ye(t,[{key:"componentDidMount",value:function(){this.startListeningComposition(),this.startListeningToTouch(),this.props.closeMenuOnScroll&&document&&document.addEventListener&&document.addEventListener("scroll",this.onScroll,!0),this.props.autoFocus&&this.focusInput()}},{key:"componentWillReceiveProps",value:function(e){var t=this.props,n=t.options,r=t.value,o=t.menuIsOpen,i=t.inputValue;if(this.cacheComponents(e.components),e.value!==r||e.options!==n||e.menuIsOpen!==o||e.inputValue!==i){var a=Mt(e.value),u=e.menuIsOpen?this.buildMenuOptions(e,a):{render:[],focusable:[]},s=this.getNextFocusedValue(a),l=this.getNextFocusedOption(u.focusable);this.setState({menuOptions:u,selectValue:a,focusedOption:l,focusedValue:s})}null!=this.inputIsHiddenAfterUpdate&&(this.setState({inputIsHidden:this.inputIsHiddenAfterUpdate}),delete this.inputIsHiddenAfterUpdate)}},{key:"componentDidUpdate",value:function(e){var t,n,r,o,i,a=this.props,u=a.isDisabled,s=a.menuIsOpen,l=this.state.isFocused;(l&&!u&&e.isDisabled||l&&s&&!e.menuIsOpen)&&this.focusInput(),this.menuListRef&&this.focusedOptionRef&&this.scrollToFocusedOptionOnUpdate&&(t=this.menuListRef,n=this.focusedOptionRef,r=t.getBoundingClientRect(),o=n.getBoundingClientRect(),i=n.offsetHeight/3,o.bottom+i>r.bottom?Bt(t,Math.min(n.offsetTop+n.clientHeight-t.offsetHeight+i,t.scrollHeight)):o.top-i-1&&(a=u)}this.scrollToFocusedOptionOnUpdate=!(o&&this.menuListRef),this.inputIsHiddenAfterUpdate=!1,this.onMenuOpen(),this.setState({focusedValue:null,focusedOption:n.focusable[a]}),this.announceAriaLiveContext({event:"menu"})}},{key:"focusValue",value:function(e){var t=this.props,n=t.isMulti,r=t.isSearchable,o=this.state,i=o.selectValue,a=o.focusedValue;if(n){this.setState({focusedOption:null});var u=i.indexOf(a);a||(u=-1,this.announceAriaLiveContext({event:"value"}));var s=i.length-1,l=-1;if(i.length){switch(e){case"previous":l=0===u?0:-1===u?s:u-1;break;case"next":u>-1&&u0&&void 0!==arguments[0]?arguments[0]:"first",t=this.props.pageSize,n=this.state,r=n.focusedOption,o=n.menuOptions.focusable;if(o.length){var i=0,a=o.indexOf(r);r||(a=-1,this.announceAriaLiveContext({event:"menu"})),"up"===e?i=a>0?a-1:o.length-1:"down"===e?i=(a+1)%o.length:"pageup"===e?(i=a-t)<0&&(i=0):"pagedown"===e?(i=a+t)>o.length-1&&(i=o.length-1):"last"===e&&(i=o.length-1),this.scrollToFocusedOptionOnUpdate=!0,this.setState({focusedOption:o[i],focusedValue:null}),this.announceAriaLiveContext({event:"menu",context:{isDisabled:Gn(o[i])}})}}},{key:"getTheme",value:function(){return this.props.theme?"function"==typeof this.props.theme?this.props.theme(Xn):He({},Xn,this.props.theme):Xn}},{key:"getCommonProps",value:function(){var e=this.clearValue,t=this.getStyles,n=this.setValue,r=this.selectOption,o=this.props,i=o.classNamePrefix,a=o.isMulti,u=o.isRtl,s=o.options,l=this.state.selectValue,c=this.hasValue();return{cx:function(e,t,n){var r=[n];if(t&&e)for(var o in t)t.hasOwnProperty(o)&&t[o]&&r.push("".concat(Lt(e,o)));return r.filter(function(e){return e}).map(function(e){return String(e).trim()}).join(" ")}.bind(null,i),clearValue:e,getStyles:t,getValue:function(){return l},hasValue:c,isMulti:a,isRtl:u,options:s,selectOption:r,setValue:n,selectProps:o,theme:this.getTheme()}}},{key:"getNextFocusedValue",value:function(e){if(this.clearFocusValueOnUpdate)return this.clearFocusValueOnUpdate=!1,null;var t=this.state,n=t.focusedValue,r=t.selectValue.indexOf(n);if(r>-1){if(e.indexOf(n)>-1)return n;if(r-1?t:e[0]}},{key:"hasValue",value:function(){return this.state.selectValue.length>0}},{key:"hasOptions",value:function(){return!!this.state.menuOptions.render.length}},{key:"countOptions",value:function(){return this.state.menuOptions.focusable.length}},{key:"isClearable",value:function(){var e=this.props,t=e.isClearable,n=e.isMulti;return void 0===t?n:t}},{key:"isOptionDisabled",value:function(e,t){return"function"==typeof this.props.isOptionDisabled&&this.props.isOptionDisabled(e,t)}},{key:"isOptionSelected",value:function(e,t){var n=this;if(t.indexOf(e)>-1)return!0;if("function"==typeof this.props.isOptionSelected)return this.props.isOptionSelected(e,t);var r=this.getOptionValue(e);return t.some(function(e){return n.getOptionValue(e)===r})}},{key:"filterOption",value:function(e,t){return!this.props.filterOption||this.props.filterOption(e,t)}},{key:"formatOptionLabel",value:function(e,t){if("function"==typeof this.props.formatOptionLabel){var n=this.props.inputValue,r=this.state.selectValue;return this.props.formatOptionLabel(e,{context:t,inputValue:n,selectValue:r})}return this.getOptionLabel(e)}},{key:"formatGroupLabel",value:function(e){return this.props.formatGroupLabel(e)}},{key:"startListeningComposition",value:function(){document&&document.addEventListener&&(document.addEventListener("compositionstart",this.onCompositionStart,!1),document.addEventListener("compositionend",this.onCompositionEnd,!1))}},{key:"stopListeningComposition",value:function(){document&&document.removeEventListener&&(document.removeEventListener("compositionstart",this.onCompositionStart),document.removeEventListener("compositionend",this.onCompositionEnd))}},{key:"startListeningToTouch",value:function(){document&&document.addEventListener&&(document.addEventListener("touchstart",this.onTouchStart,!1),document.addEventListener("touchmove",this.onTouchMove,!1),document.addEventListener("touchend",this.onTouchEnd,!1))}},{key:"stopListeningToTouch",value:function(){document&&document.removeEventListener&&(document.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("touchend",this.onTouchEnd))}},{key:"buildMenuOptions",value:function(e,t){var n=this,r=e.inputValue,o=void 0===r?"":r,i=e.options,a=function(e,r){var i=n.isOptionDisabled(e,t),a=n.isOptionSelected(e,t),u=n.getOptionLabel(e),s=n.getOptionValue(e);if(!(n.shouldHideSelectedOptions()&&a||!n.filterOption({label:u,value:s,data:e},o))){var l=i?void 0:function(){return n.onOptionHover(e)},c=i?void 0:function(){return n.selectOption(e)},f="".concat(n.getElementId("option"),"-").concat(r);return{innerProps:{id:f,onClick:c,onMouseMove:l,onMouseOver:l,tabIndex:-1},data:e,isDisabled:i,isSelected:a,key:f,label:u,type:"option",value:s}}};return i.reduce(function(e,t,r){if(t.options){n.hasGroups||(n.hasGroups=!0);var o=t.options.map(function(t,n){var o=a(t,"".concat(r,"-").concat(n));return o&&e.focusable.push(t),o}).filter(Boolean);if(o.length){var i="".concat(n.getElementId("group"),"-").concat(r);e.render.push({type:"group",key:i,data:t,options:o})}}else{var u=a(t,"".concat(r));u&&(e.render.push(u),e.focusable.push(t))}return e},{render:[],focusable:[]})}},{key:"constructAriaLiveMessage",value:function(){var e=this.state,t=e.ariaLiveContext,n=e.selectValue,r=e.focusedValue,o=e.focusedOption,i=this.props,a=i.options,u=i.menuIsOpen,s=i.inputValue,l=i.screenReaderStatus,c=r?function(e){var t=e.focusedValue,n=e.getOptionLabel,r=e.selectValue;return"value ".concat(n(t)," focused, ").concat(r.indexOf(t)+1," of ").concat(r.length,".")}({focusedValue:r,getOptionLabel:this.getOptionLabel,selectValue:n}):"",f=o&&u?function(e){var t=e.focusedOption,n=e.getOptionLabel,r=e.options;return"option ".concat(n(t)," focused").concat(t.isDisabled?" disabled":"",", ").concat(r.indexOf(t)+1," of ").concat(r.length,".")}({focusedOption:o,getOptionLabel:this.getOptionLabel,options:a}):"",p=function(e){var t=e.inputValue,n=e.screenReaderMessage;return"".concat(n).concat(t?" for search term "+t:"",".")}({inputValue:s,screenReaderMessage:l({count:this.countOptions()})});return"".concat(c," ").concat(f," ").concat(p," ").concat(t)}},{key:"renderInput",value:function(){var e=this.props,t=e.isDisabled,n=e.isSearchable,r=e.inputId,i=e.inputValue,a=e.tabIndex,u=this.components.Input,s=this.state.inputIsHidden,l=r||this.getElementId("input");if(!n)return o.a.createElement(Pn,{id:l,innerRef:this.getInputRef,onBlur:this.onInputBlur,onChange:Ft,onFocus:this.onInputFocus,readOnly:!0,disabled:t,tabIndex:a,value:""});var c={"aria-autocomplete":"list","aria-label":this.props["aria-label"],"aria-labelledby":this.props["aria-labelledby"]},f=this.commonProps,p=f.cx,d=f.theme,h=f.selectProps;return o.a.createElement(u,Object(Ue.a)({autoCapitalize:"none",autoComplete:"off",autoCorrect:"off",cx:p,getStyles:this.getStyles,id:l,innerRef:this.getInputRef,isDisabled:t,isHidden:s,onBlur:this.onInputBlur,onChange:this.handleInputChange,onFocus:this.onInputFocus,selectProps:h,spellCheck:"false",tabIndex:a,theme:d,type:"text",value:i},c))}},{key:"renderPlaceholderOrValue",value:function(){var e=this,t=this.components,n=t.MultiValue,r=t.MultiValueContainer,i=t.MultiValueLabel,a=t.MultiValueRemove,u=t.SingleValue,s=t.Placeholder,l=this.commonProps,c=this.props,f=c.controlShouldRenderValue,p=c.isDisabled,d=c.isMulti,h=c.inputValue,m=c.placeholder,y=this.state,b=y.selectValue,v=y.focusedValue,g=y.isFocused;if(!this.hasValue()||!f)return h?null:o.a.createElement(s,Object(Ue.a)({},l,{key:"placeholder",isDisabled:p,isFocused:g}),m);if(d)return b.map(function(t){var u=t===v;return o.a.createElement(n,Object(Ue.a)({},l,{components:{Container:r,Label:i,Remove:a},isFocused:u,isDisabled:p,key:e.getOptionValue(t),removeProps:{onClick:function(){return e.removeValue(t)},onTouchEnd:function(){return e.removeValue(t)},onMouseDown:function(e){e.preventDefault(),e.stopPropagation()}},data:t}),e.formatOptionLabel(t,"value"))});if(h)return null;var w=b[0];return o.a.createElement(u,Object(Ue.a)({},l,{data:w,isDisabled:p}),this.formatOptionLabel(w,"value"))}},{key:"renderClearIndicator",value:function(){var e=this.components.ClearIndicator,t=this.commonProps,n=this.props,r=n.isDisabled,i=n.isLoading,a=this.state.isFocused;if(!this.isClearable()||!e||r||!this.hasValue()||i)return null;var u={onMouseDown:this.onClearIndicatorMouseDown,onTouchEnd:this.onClearIndicatorTouchEnd,"aria-hidden":"true"};return o.a.createElement(e,Object(Ue.a)({},t,{innerProps:u,isFocused:a}))}},{key:"renderLoadingIndicator",value:function(){var e=this.components.LoadingIndicator,t=this.commonProps,n=this.props,r=n.isDisabled,i=n.isLoading,a=this.state.isFocused;if(!e||!i)return null;return o.a.createElement(e,Object(Ue.a)({},t,{innerProps:{"aria-hidden":"true"},isDisabled:r,isFocused:a}))}},{key:"renderIndicatorSeparator",value:function(){var e=this.components,t=e.DropdownIndicator,n=e.IndicatorSeparator;if(!t||!n)return null;var r=this.commonProps,i=this.props.isDisabled,a=this.state.isFocused;return o.a.createElement(n,Object(Ue.a)({},r,{isDisabled:i,isFocused:a}))}},{key:"renderDropdownIndicator",value:function(){var e=this.components.DropdownIndicator;if(!e)return null;var t=this.commonProps,n=this.props.isDisabled,r=this.state.isFocused,i={onMouseDown:this.onDropdownIndicatorMouseDown,onTouchEnd:this.onDropdownIndicatorTouchEnd,"aria-hidden":"true"};return o.a.createElement(e,Object(Ue.a)({},t,{innerProps:i,isDisabled:n,isFocused:r}))}},{key:"renderMenu",value:function(){var e=this,t=this.components,n=t.Group,r=t.GroupHeading,i=t.Menu,a=t.MenuList,u=t.MenuPortal,s=t.LoadingMessage,l=t.NoOptionsMessage,c=t.Option,f=this.commonProps,p=this.state,d=p.focusedOption,h=p.menuOptions,m=this.props,y=m.captureMenuScroll,b=m.inputValue,v=m.isLoading,g=m.loadingMessage,w=m.minMenuHeight,x=m.maxMenuHeight,O=m.menuIsOpen,_=m.menuPlacement,E=m.menuPosition,k=m.menuPortalTarget,S=m.menuShouldBlockScroll,C=m.menuShouldScrollIntoView,j=m.noOptionsMessage,T=m.onMenuScrollToTop,A=m.onMenuScrollToBottom;if(!O)return null;var P,I=function(t){var n=d===t.data;return t.innerRef=n?e.getFocusedOptionRef:void 0,o.a.createElement(c,Object(Ue.a)({},f,t,{isFocused:n}),e.formatOptionLabel(t.data,"menu"))};if(this.hasOptions())P=h.render.map(function(t){if("group"===t.type){t.type;var i=Be(t,["type"]),a="".concat(t.key,"-heading");return o.a.createElement(n,Object(Ue.a)({},f,i,{Heading:r,headingProps:{id:a},label:e.formatGroupLabel(t.data)}),t.options.map(function(e){return I(e)}))}if("option"===t.type)return I(t)});else if(v){var R=g({inputValue:b});if(null===R)return null;P=o.a.createElement(s,f,R)}else{var D=j({inputValue:b});if(null===D)return null;P=o.a.createElement(l,f,D)}var F={minMenuHeight:w,maxMenuHeight:x,menuPlacement:_,menuPosition:E,menuShouldScrollIntoView:C},L=o.a.createElement(Yt,Object(Ue.a)({},f,F),function(t){var n=t.ref,r=t.placerProps,u=r.placement,s=r.maxHeight;return o.a.createElement(i,Object(Ue.a)({},f,F,{innerRef:n,innerProps:{onMouseDown:e.onMenuMouseDown,onMouseMove:e.onMenuMouseMove},isLoading:v,placement:u}),o.a.createElement(qn,{isEnabled:y,onTopArrive:T,onBottomArrive:A},o.a.createElement(Wn,{isEnabled:S},o.a.createElement(a,Object(Ue.a)({},f,{innerRef:e.getMenuListRef,isLoading:v,maxHeight:s}),P))))});return k||"fixed"===E?o.a.createElement(u,Object(Ue.a)({},f,{appendTo:k,controlElement:this.controlRef,menuPlacement:_,menuPosition:E}),L):L}},{key:"renderFormField",value:function(){var e=this,t=this.props,n=t.delimiter,r=t.isDisabled,i=t.isMulti,a=t.name,u=this.state.selectValue;if(a&&!r){if(i){if(n){var s=u.map(function(t){return e.getOptionValue(t)}).join(n);return o.a.createElement("input",{name:a,type:"hidden",value:s})}var l=u.length>0?u.map(function(t,n){return o.a.createElement("input",{key:"i-".concat(n),name:a,type:"hidden",value:e.getOptionValue(t)})}):o.a.createElement("input",{name:a,type:"hidden"});return o.a.createElement("div",null,l)}var c=u[0]?this.getOptionValue(u[0]):"";return o.a.createElement("input",{name:a,type:"hidden",value:c})}}},{key:"renderLiveRegion",value:function(){return this.state.isFocused?o.a.createElement(An,{"aria-live":"polite"},o.a.createElement("p",{id:"aria-selection-event"}," ",this.state.ariaLiveSelection),o.a.createElement("p",{id:"aria-context"}," ",this.constructAriaLiveMessage())):null}},{key:"render",value:function(){var e=this.components,t=e.Control,n=e.IndicatorsContainer,r=e.SelectContainer,i=e.ValueContainer,a=this.props,u=a.className,s=a.id,l=a.isDisabled,c=a.menuIsOpen,f=this.state.isFocused,p=this.commonProps=this.getCommonProps();return o.a.createElement(r,Object(Ue.a)({},p,{className:u,innerProps:{id:s,onKeyDown:this.onKeyDown},isDisabled:l,isFocused:f}),this.renderLiveRegion(),o.a.createElement(t,Object(Ue.a)({},p,{innerRef:this.getControlRef,innerProps:{onMouseDown:this.onControlMouseDown,onTouchEnd:this.onControlTouchEnd},isDisabled:l,isFocused:f,menuIsOpen:c}),o.a.createElement(i,Object(Ue.a)({},p,{isDisabled:l}),this.renderPlaceholderOrValue(),this.renderInput()),o.a.createElement(n,Object(Ue.a)({},p,{isDisabled:l}),this.renderClearIndicator(),this.renderLoadingIndicator(),this.renderIndicatorSeparator(),this.renderDropdownIndicator())),this.renderMenu(),this.renderFormField())}}]),t}();We(er,"defaultProps",Qn);var tr,nr,rr,or,ir,ar,ur={defaultInputValue:"",defaultMenuIsOpen:!1,defaultValue:null},sr=function(e){var t,n;return n=t=function(t){function n(){var e,t;qe(this,n);for(var r=arguments.length,o=new Array(r),i=0;i1?n-1:0),o=1;o=n.max)n.props.onChange({error:"Non puoi aggiungere altri elementi, numero massimo di elementi ".concat(max),disabled:!0},n.props.index);else{var o=[].concat(Vo(n.props.options.children),[xo()(r)]);n.props.onChange({value:t+1,children:o,error:"",disabled:!1},n.props.index)}}),Yo(qo(n),"deleteChild",function(e){var t=n.props.options.value;if(t<=n.min)n.props.onChange({error:"You can't delete another element, the minimum is ".concat(n.min),disabled:!1},n.props.index);else{var r=Vo(n.props.options.children);r.splice(e,1),n.props.onChange({value:t-1,children:r,error:"",disabled:!1},n.props.index)}}),Yo(qo(n),"onSortEnd",function(e){var t=e.oldIndex,r=e.newIndex,o=Vo(n.props.options.children);n.props.onChange({children:Object(Xr.arrayMove)(o,t,r)},n.props.index)}),Yo(qo(n),"onChangeChild",function(e,t){var r=Vo(n.props.options.children);r[t]=xo()(e.fields),n.props.onChange({children:r},n.props.index)});var r=e.options;return n.min=r.min||0,n.max=r.max||null,n.ensureInitialValue(r),n}var n,i,a;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&$o(e,t)}(t,r["PureComponent"]),n=t,(i=[{key:"ensureInitialValue",value:function(e){var t=e.value,n=e.fields,r=t||0,o=Vo(this.props.options.children||[]),i=r;if(this.min&&r0?a.map(function(t,n){var r=i[t];return r?o.a.createElement(Bi,{key:"".concat(r.id,"-").concat(n),type:r,onClick:e.onClick}):o.a.createElement("pre",{key:"".concat(n)},"Missing SectionsTypes")}):o.a.createElement("pre",null,"Missing SectionsTypes")))}}])&&Wi(n.prototype,i),a&&Wi(n,a),t}(),Gi=n(51),Zi=j.d.div.withConfig({displayName:"StyledContainerButton",componentId:"sc-1k9l9z9-0"})([""," border-top:0;width:100%;display:flex;padding:",";justify-content:center;align-items:center;box-sizing:border-box;"],F,Object(T.c)("20px")),Ki=function(e){var t=e.label,n=e.onClick;return o.a.createElement(Zi,null,o.a.createElement(kr.a,{withIcon:"add",onClick:n},t))};Ki.propTypes={label:C.a.string,onClick:C.a.func};var Xi=Ki,Qi=n(88),Ji=n.n(Qi),ea=j.d.div.withConfig({displayName:"StyledCta",componentId:"sc-1iujxdq-0"})(["display:flex;flex-direction:column;justify-content:center;align-items:center;color:",";font-size:.8rem;text-transform:uppercase;padding:0 ",";cursor:pointer;&:hover{color:",";}"],function(e){return e.theme.palette.primary},Object(T.c)("10px"),function(e){return e.theme.palette.primaryDark}),ta=j.d.div.withConfig({displayName:"StyledInfo",componentId:"q0x4v1-0"})(["position:relative;display:flex;justify-content:flex-start;align-items:baseline;max-width:100%;padding:"," 0;strong{padding-right:",";text-transform:uppercase;font-weight:700;color:",";}p{"," margin:0;font-weight:700;text-transform:capitalize;color:",";}"],Object(T.c)("6px"),Object(T.c)("10px"),function(e){return e.theme.palette.primary},A.c,function(e){return e.theme.palette.black}),na=j.d.input.withConfig({displayName:"StyledInputTitle",componentId:"sc-1bbtdy9-0"})(['input[type="text"]&{'," flex:1 0 auto;border:none;box-shadow:none;outline:none;padding:0;margin:0;background-color:transparent;font-weight:700;::placeholder{opacity:0.6;color:currentColor;transition:opacity 0.3s;}&:focus::placeholder{opacity:1;}}"],A.c),ra=j.d.div.withConfig({displayName:"StyledWrapper",componentId:"brmrhi-0"})(["position:relative;display:flex;width:100%;margin-bottom:",";background-color:",";opacity:",";"],Object(T.c)("5px"),function(e){return e.theme.palette.primaryLight},function(e){return e.draft?.5:1}),oa=j.d.div.withConfig({displayName:"StyledWrapperInfo",componentId:"sc-1ofjfvr-0"})(["width:100%;display:flex;flex-direction:column;padding:"," ",";"],Object(T.c)("10px"),Object(T.c)("20px")),ia=j.d.div.withConfig({displayName:"StyledWrapperCta",componentId:"sc-1sgwk6q-0"})(["display:flex;> *{position:relative;&:before{position:absolute;content:'';width:",";;height:",";right:0;top:50%;transform:translateY(-50%);background-color:",";}&:last-child{&:before{display:none;}}}"],Object(T.c)("1px"),Object(T.c)("40px"),function(e){return e.theme.palette.primary}),aa=Object(r.memo)(function(e){var t=e.label,n=void 0===t?"":t,r=e.title,i=void 0===r?"":r,a=e.parentID,u=e.sectionIsDraft,s=e.onChangeTitle,l=e.onToggleDraftButton,c=e.onAccordionButton,f=e.onDeleteButton,p=null===i?"":i;return o.a.createElement(ra,{draft:u},o.a.createElement(jo,null),o.a.createElement(oa,null,o.a.createElement(ta,null,o.a.createElement("strong",null,"Title"),o.a.createElement(na,{type:"text",name:"".concat(a,"-headerTitle"),placeholder:"Add a title",onChange:s,value:p})),o.a.createElement(ta,null,o.a.createElement("strong",null,"type"),o.a.createElement("p",null,n))),o.a.createElement(ia,null,o.a.createElement(ea,{onClick:l},o.a.createElement(ko.a,{icon:u?"hidden":"show"})),o.a.createElement(ea,{onClick:c},o.a.createElement(ko.a,{icon:"edit"})),o.a.createElement(ea,{onClick:f},o.a.createElement(ko.a,{icon:"delete"}))))}),ua=j.d.div.withConfig({displayName:"StyledSection",componentId:"sc-1gf7xjb-0"})(["margin-bottom:",";"],Object(T.c)("10px")),sa=j.d.div.withConfig({displayName:"StyledContainer",componentId:"sc-1yaw019-0"})([""," border-top:0;padding-left:",";padding-right:",";padding-bottom:",";"],F,Object(T.c)("10px"),Object(T.c)("10px"),Object(T.c)("10px"));function la(e){return(la="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ca(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t3&&void 0!==arguments[3]?arguments[3]:0,a=l(e,t);return"min-width"===n&&0===a?function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;o1?t-1:0),c=1;c0&&void 0!==arguments[0]?arguments[0]:"left",t="";switch(e){case"left":t=i?"flex-end":"flex-start";break;case"right":t=i?"flex-start":"flex-end";break;case"center":t="center";break;case"justify-center":t="space-around";break;case"justify":t="space-between";break;default:throw new Error('styled-components-grid: halign must be one of "left", "right", "center", "justify-center" or "justify". Got "'+String(e)+'"')}return"justify-content: "+t+";"})),void 0===(t=e.valign)?"":h(t,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"stretch",t="";switch(e){case"top":t="flex-start";break;case"bottom":t="flex-end";break;case"center":t="center";break;case"stretch":t="stretch";break;default:throw new Error('styled-components-grid: valign must be one of "top", "bottom", "center" or "stretch". Got "'+String(e)+'".')}return"align-items: "+t+";"}),function(e){var t=e.reverse;return void 0===t?"":h(t,function(){return"flex-direction: "+(arguments.length>0&&void 0!==arguments[0]&&arguments[0]?"row-reverse":"row")+";"})}(e),function(e){var t=e.wrap,n=e.reverse;return h(t,function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return e&&n?"flex-wrap: wrap-reverse;":!1===e?"flex-wrap: nowrap;":"flex-wrap: wrap;"})}(e));var t,n,o,i},g=function(e,t){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}(["\n box-sizing: border-box;\n "," ",";\n "],["\n box-sizing: border-box;\n "," ",";\n "]);var w=function(e){return Object(r.c)(g,h(e.size,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;switch(e){case"min":return"\n flex-grow: 0;\n flex-basis: auto;\n width: auto;\n max-width: none;\n ";case"max":return"\n flex-grow: 1;\n flex-basis: auto;\n width: auto;\n max-width: none;\n max-width: 100%; /* TODO: does this always work as expected? */\n ";default:var t=Math.round(100*("number"==typeof e?e:1)*1e4)/1e4;return"\n flex-basis: "+t+"%;\n max-width: "+t+"%;\n "}}),void 0===(t=e.visible)?"":h(t,function(e){return!1===e?"display: none;":"display: flex;"}));var t},x=(n(0),n(87)),O=n.n(x),_=function(e,t){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}(["\n box-sizing: border-box;\n ","\n"],["\n box-sizing: border-box;\n ","\n"]);var E=O()({tag:"div",prop:"component",propsToOmit:["width","visible"]}),k=Object(r.d)(E)(_,w),S=function(e,t){return Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}(["\n display: flex;\n ","\n"],["\n display: flex;\n ","\n"]);var C=O()({tag:"div",prop:"component",propsToOmit:["halign","valign","reverse","wrap"]}),j=Object(r.d)(C)(S,v);v.unit=w,j.Unit=k;t.a=j},function(e,t,n){"use strict";var r=n(15),o=n(79),i=n(61),a=o(2);r({target:"Array",proto:!0,forced:!i("filter")},{filter:function(e){return a(this,e,arguments[1])}})},function(e,t,n){var r=n(15),o=n(20),i=n(34),a=n(47).f,u=n(26),s=o(function(){a(1)});r({target:"Object",stat:!0,forced:!u||s,sham:!u},{getOwnPropertyDescriptor:function(e,t){return a(i(e),t)}})},function(e,t,n){var r=n(15),o=n(26),i=n(120),a=n(34),u=n(47),s=n(60);r({target:"Object",stat:!0,sham:!o},{getOwnPropertyDescriptors:function(e){for(var t,n,r=a(e),o=u.f,l=i(r),c={},f=0;l.length>f;)void 0!==(n=o(r,t=l[f++]))&&s(c,t,n);return c}})},function(e,t,n){"use strict";var r={}.propertyIsEnumerable,o=Object.getOwnPropertyDescriptor,i=o&&!r.call({1:2},1);t.f=i?function(e){var t=o(this,e);return!!t&&t.enumerable}:r},function(e,t,n){var r=n(20),o=n(44),i="".split;e.exports=r(function(){return!Object("z").propertyIsEnumerable(0)})?function(e){return"String"==o(e)?i.call(e,""):Object(e)}:Object},function(e,t){e.exports=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,n){var r=n(56),o=n(74),i=r("keys");e.exports=function(e){return i[e]||(i[e]=o(e))}},function(e,t){var n=0,r=Math.random();e.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+r).toString(36))}},function(e,t){var n=Math.ceil,r=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?r:n)(e)}},function(e,t){t.f=Object.getOwnPropertySymbols},function(e,t,n){var r=n(44);e.exports=Array.isArray||function(e){return"Array"==r(e)}},function(e,t,n){var r=n(29).f,o=n(27),i=n(18)("toStringTag");e.exports=function(e,t,n){e&&!o(e=n?e:e.prototype,i)&&r(e,i,{configurable:!0,value:t})}},function(e,t,n){var r=n(80),o=n(71),i=n(36),a=n(45),u=n(101);e.exports=function(e,t){var n=1==e,s=2==e,l=3==e,c=4==e,f=6==e,p=5==e||f,d=t||u;return function(t,u,h){for(var m,y,b=i(t),v=o(b),g=r(u,h,3),w=a(v.length),x=0,O=n?d(t,w):s?d(t,0):void 0;w>x;x++)if((p||x in v)&&(y=g(m=v[x],x,b),e))if(n)O[x]=y;else if(y)switch(e){case 3:return!0;case 5:return m;case 6:return x;case 2:O.push(m)}else if(c)return!1;return f?-1:l||c?c:O}}},function(e,t,n){var r=n(81);e.exports=function(e,t,n){if(r(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,o){return e.call(t,n,r,o)}}return function(){return e.apply(t,arguments)}}},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e}},function(e,t){},function(e,t,n){(function(t){for(var r=n(227),o="undefined"==typeof window?t:window,i=["moz","webkit"],a="AnimationFrame",u=o["request"+a],s=o["cancel"+a]||o["cancelRequest"+a],l=0;!u&&l=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}(this.props,[]);return function(e){c.forEach(function(t){return delete e[t]})}(o),o.className=this.props.inputClassName,o.id=this.state.inputId,o.style=n,a.default.createElement("div",{className:this.props.className,style:t},this.renderStyles(),a.default.createElement("input",r({},o,{ref:this.inputRef})),a.default.createElement("div",{ref:this.sizerRef,style:l},e),this.props.placeholder?a.default.createElement("div",{ref:this.placeHolderSizerRef,style:l},this.props.placeholder):null)}}]),t}();h.propTypes={className:u.default.string,defaultValue:u.default.any,extraWidth:u.default.oneOfType([u.default.number,u.default.string]),id:u.default.string,injectStyles:u.default.bool,inputClassName:u.default.string,inputRef:u.default.func,inputStyle:u.default.object,minWidth:u.default.oneOfType([u.default.number,u.default.string]),onAutosize:u.default.func,onChange:u.default.func,placeholder:u.default.string,placeholderIsMinWidth:u.default.bool,style:u.default.object,value:u.default.any},h.defaultProps={minWidth:1,injectStyles:!0},t.default=h},function(e,t,n){"use strict";t.a={animationIterationCount:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1}},function(e,t,n){"use strict";t.a=function(e){var t={};return function(n){return void 0===t[n]&&(t[n]=e(n)),t[n]}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r,o=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{},t=e.tag,n=void 0===t?"div":t,r=e.prop,o=void 0===r?"tag":r,i=e.propsToOmit,s=void 0===i?[]:i;return function(e){var t=e.children,r=function(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}(e,["children"]),i=r[o]||n,l=u([o].concat(function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(f,["className","excludeStateCSS","children","transition","style","render","elementType","layoutEffect","isOpen","collapseHeight","onInit","onChange"]),k=e.useRef(),S=o(e.useState(w?s:i),2),C=S[0],j=S[1],T=o(e.useState({height:w?null:M(),visibility:w?null:N()}),2),A=T[0],P=T[1],I=o(e.useState(!1),2),R=I[0],D=I[1],F=e.useRef(!0);(g?e.useLayoutEffect:e.useEffect)(function(){if(k.current){if(F.current)return L(O),void(F.current=!1);switch(C){case u:l(function(){if(k.current){var e=z();P({height:e,visibility:""}),L(_)}});break;case a:!function(){if(k.current){var e=z();P({height:e,visibility:""}),l(function(){P({height:M(),visibility:""}),L(_)})}}();break;case s:k.current&&(P({height:"",visibility:""}),L(_));break;case i:k.current&&(P({height:M(),visibility:N()}),L(_))}}},[C]);var L=function(e){e&&(e.name,e({collapseState:C,collapseStyle:A,hasReversed:R,isMoving:c(C)}))};function M(){return x||"0px"}function N(){return x?"":"hidden"}function z(){return"".concat(k.current.scrollHeight,"px")}var B=C===s||C===u;!B&&w&&(D(C===a),j(u)),B&&!w&&(D(C===u),j(a));var U=function(e){for(var t=1;tc;)if((u=s[c++])!=u)return!0}else for(;l>c;c++)if((e||c in s)&&s[c]===n)return e||c||0;return!e&&-1}}},function(e,t,n){var r=n(75),o=Math.max,i=Math.min;e.exports=function(e,t){var n=r(e);return n<0?o(n+t,0):i(n,t)}},function(e,t){e.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},function(e,t,n){e.exports=n(17)},function(e,t,n){var r=n(28),o=n(180),i=n(98),a=n(59),u=n(127),s=n(93),l=n(73)("IE_PROTO"),c=function(){},f=function(){var e,t=s("iframe"),n=i.length;for(t.style.display="none",u.appendChild(t),t.src=String("javascript:"),(e=t.contentWindow.document).open(),e.write("