Skip to content

Commit

Permalink
Version bump to 3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Parziale committed Sep 4, 2019
1 parent 7a9edb6 commit 1c09a12
Show file tree
Hide file tree
Showing 26 changed files with 763 additions and 452 deletions.
2 changes: 1 addition & 1 deletion Aeria/Aeria.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class Aeria extends Container
{
public const VERSION = '3.0.1';
public const VERSION = '3.0.2';

public function __construct()
{
Expand Down
150 changes: 142 additions & 8 deletions Aeria/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Config implements ExtensibleInterface, JsonSerializable, ValidateConfInter
protected $drivers = [];
protected $root_path = '';
protected $active_driver = 'json';
private $_kind;

public function __construct()
{
Expand All @@ -36,19 +37,151 @@ public function __construct()

public function getValidationStructure() : array
{
switch ($this->_kind){
case 'meta':
$spec = [
'title' => $this->makeRegExValidator(
"/^.{1,30}$/"
),
'context' => $this->makeRegExValidator(
"/^normal|side|advanced$/"
),
'post_type' => function ($value) {
return [
'result' => is_array($value),
'message' => 'post_type should be an array'
];
},
'fields' => function ($value) {
return [
'result' => is_array($value),
'message' => 'fields should be an array'
];
}
];
break;
case 'post-type':
$spec = [
'menu_icon' => $this->makeRegExValidator(
"/^[a-z0-9_-]{1,30}$/"
),
'labels' => function ($value) {
return [
'result' => is_array($value),
'message' => 'labels should be an array'
];
},
'public' => function ($value) {
return [
'result' => is_bool($value),
'message' => 'public should be a bool'
];
},
'show_ui' => function ($value) {
return [
'result' => is_bool($value),
'message' => 'show_ui should be a bool'
];
},
'show_in_menu' => function ($value) {
return [
'result' => is_bool($value),
'message' => 'show_in_menu should be a bool'
];
},
'menu_position' => function ($value) {
return [
'result' => is_int($value),
'message' => 'menu_position should be an int'
];
}
];
break;
case 'taxonomy':
$spec = [
'label' => $this->makeRegExValidator(
"/^.{1,30}$/"
),
'labels' => function ($value) {
return [
'result' => is_array($value),
'message' => 'labels should be an array'
];
}
];
break;
case 'section':
$spec = [
'id' => $this->makeRegExValidator(
"/^[a-z0-9_-]{1,20}$/"
),
'label' => $this->makeRegExValidator(
"/^.{1,30}$/"
),
'description' => $this->makeRegExValidator(
"/^.{1,60}$/"
),
'fields' => function ($value) {
return [
'result' => is_array($value),
'message' => 'fields should be an array'
];
}
];
break;
case 'controller':
$spec = [
'namespace' => $this->makeRegExValidator(
"/^[A-Za-z0-9_-]{1,30}$/"
),
];
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}$/"
)
];
break;
case 'options':
$spec = [
'title' => $this->makeRegExValidator(
"/^.{1,40}$/"
),
'menu-slug' => $this->makeRegExValidator(
"/^[a-z0-9_-]{1,20}$/"
),
'capability' => $this->makeRegExValidator(
"/^[a-z0-9_-]{1,30}$/"
),
'parent' => $this->makeRegExValidator(
"/^[a-z0-9_-]{1,30}$/"
),
'fields' => function ($value) {
return [
'result' => is_array($value),
'message' => 'fields should be an array'
];
}
];
break;
default:
$spec = [];
break;
}
return [
'name' => $this->makeRegExValidator(
"/^[a-z0-9_-]{1,20}$/"
),
'spec' => function ($value) {
return [
'result' => is_array($value),
'message' => 'Spec should be an array'
];
},
'spec' => $spec,
'kind' => $this->makeRegExValidator(
// TODO: Aggiungere i vari tipi nella validazione
"/^post-type|renderer|taxonomy|meta|section|controller|route|options$/"
"/^post-type|taxonomy|meta|section|controller|route|options$/"
)
];
}
Expand Down Expand Up @@ -124,6 +257,7 @@ protected static function createNamespaceTree(

public function isValidStandardConfiguration($data)
{
$this->_kind = $data['kind'];
$exeption = $this->isValid($data);
if (!is_null($exeption)) {
throw $exeption;
Expand Down
21 changes: 12 additions & 9 deletions Aeria/Config/Traits/ValidateConfTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,19 @@ public static function validateStructure(
) {
foreach ($validation_structure as $key => $value) {
if (isset($array_to_validate[$key])) {
$error = static::handleClosure(
$array_to_validate[$key],
$value,
$key
);
if (!is_null($error)) {
return $error;
if (is_array($value)) {
$error = static::validateStructure($value, $array_to_validate[$key]);
} else {
$error = static::handleClosure(
$array_to_validate[$key],
$value,
$key
);
}
} else {
return "key:{$key} is not present in the configuration";
if (!is_null($error)) {
return $error;
}

}
}
return null;
Expand Down
68 changes: 35 additions & 33 deletions Aeria/Field/Fields/SectionsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,43 @@ public function get(array $metas, bool $skipFilter = false) {
}

public function getAdmin(array $metas, array $errors) {
$stored_value = parent::get($metas, true);
$stored_value = (bool)$stored_value ? explode(',', $stored_value) : [];

$children = [];

foreach ($stored_value as $type_index => $type) {
$section_config = $this->getSectionConfig($type);

$fields = [];

foreach ($section_config['fields'] as $field_index => $field_config) {
$fields[] = array_merge(
$field_config,
FieldNodeFactory::make(
$this->key, $field_config, $this->sections, $type_index
)->getAdmin($metas, $errors)
);
$stored_value = parent::get($metas, true);
$stored_value = (bool)$stored_value ? explode(',', $stored_value) : [];

$children = [];

foreach ($stored_value as $type_index => $type) {
$section_config = $this->getSectionConfig($type);

$fields = [];
if (isset($section_config['fields'])) {
foreach ($section_config['fields'] as $field_index => $field_config) {
$fields[] = array_merge(
$field_config,
FieldNodeFactory::make(
$this->key, $field_config, $this->sections, $type_index
)->getAdmin($metas, $errors)
);
}
}
if (is_array($section_config)) {
$children[] = array_merge(
$section_config,
[
'title' => $this->getTitle($type_index)->get($metas),
'isDraft' => $this->getDraftMode($type_index)->get($metas),
'fields' => $fields
]
);
}
}

$children[] = array_merge(
$section_config,
[
'title' => $this->getTitle($type_index)->get($metas),
'isDraft' => $this->getDraftMode($type_index)->get($metas),
'fields' => $fields
]
return array_merge(
$this->config,
[
"value" => $stored_value,
"children" => $children
]
);
}
return array_merge(
$this->config,
[
"value" => $stored_value,
"children" => $children
]
);
}

public function set($context_ID, $context_type, array $metas, array $newValues, $validator_service, $query_service) {
Expand Down
16 changes: 16 additions & 0 deletions Aeria/Kernel/AbstractClasses/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Aeria\Kernel\AbstractClasses;

use Aeria\Kernel\Exceptions\CallableNotDefinedException;

abstract class Task
{
public $priority;
public $admin_only;

public function do(array $args)
{
throw new CallableNotDefinedException();
}
}
7 changes: 7 additions & 0 deletions Aeria/Kernel/Exceptions/CallableNotDefinedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Aeria\Kernel\Exceptions;

class CallableNotDefinedException extends \Exception
{
}
Loading

0 comments on commit 1c09a12

Please sign in to comment.