first commit
This commit is contained in:
		
							
								
								
									
										600
									
								
								vendor/rockettheme/toolbox/Blueprints/src/BlueprintForm.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										600
									
								
								vendor/rockettheme/toolbox/Blueprints/src/BlueprintForm.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,600 @@ | ||||
| <?php | ||||
| namespace RocketTheme\Toolbox\Blueprints; | ||||
|  | ||||
| use RocketTheme\Toolbox\ArrayTraits\Export; | ||||
| use RocketTheme\Toolbox\ArrayTraits\ExportInterface; | ||||
| use RocketTheme\Toolbox\ArrayTraits\NestedArrayAccessWithGetters; | ||||
| use RuntimeException; | ||||
|  | ||||
| /** | ||||
|  * The Config class contains configuration information. | ||||
|  * | ||||
|  * @author RocketTheme | ||||
|  */ | ||||
| abstract class BlueprintForm implements \ArrayAccess, ExportInterface | ||||
| { | ||||
|     use NestedArrayAccessWithGetters; | ||||
|     use Export; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $items; | ||||
|  | ||||
|     /** @var string */ | ||||
|     protected $filename; | ||||
|  | ||||
|     /** @var string */ | ||||
|     protected $context; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $overrides = []; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $dynamic = []; | ||||
|  | ||||
|     /** | ||||
|      * Load file and return its contents. | ||||
|      * | ||||
|      * @param string $filename | ||||
|      * @return array | ||||
|      */ | ||||
|     abstract protected function loadFile($filename); | ||||
|  | ||||
|     /** | ||||
|      * Get list of blueprint form files (file and its parents for overrides). | ||||
|      * | ||||
|      * @param string|array $path | ||||
|      * @param string $context | ||||
|      * @return array | ||||
|      */ | ||||
|     abstract protected function getFiles($path, $context = null); | ||||
|  | ||||
|     /** | ||||
|      * Constructor. | ||||
|      * | ||||
|      * @param string|array $filename | ||||
|      * @param array $items | ||||
|      */ | ||||
|     public function __construct($filename = null, array $items = []) | ||||
|     { | ||||
|         $this->nestedSeparator = '/'; | ||||
|         $this->filename = $filename; | ||||
|         $this->items = $items; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set filename for the blueprint. Can also be array of files for parent lookup. | ||||
|      * | ||||
|      * @param string|array $filename | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setFilename($filename) | ||||
|     { | ||||
|         $this->filename = $filename; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the filename of the blueprint. | ||||
|      * | ||||
|      * @return array|null|string | ||||
|      */ | ||||
|     public function getFilename() | ||||
|     { | ||||
|         return $this->filename; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set context for import@ and extend@. | ||||
|      * | ||||
|      * @param $context | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setContext($context) | ||||
|     { | ||||
|         $this->context = $context; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set custom overrides for import@ and extend@. | ||||
|      * | ||||
|      * @param array $overrides | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setOverrides($overrides) | ||||
|     { | ||||
|         $this->overrides = $overrides; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Load blueprint. | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function load($extends = null) | ||||
|     { | ||||
|         // Only load and extend blueprint if it has not yet been loaded. | ||||
|         if (empty($this->items) && $this->filename) { | ||||
|             // Get list of files. | ||||
|             $files = $this->getFiles($this->filename); | ||||
|  | ||||
|             // Load and extend blueprints. | ||||
|             $data = $this->doLoad($files, $extends); | ||||
|  | ||||
|             $this->items = (array) array_shift($data); | ||||
|  | ||||
|             foreach ($data as $content) { | ||||
|                 $this->extend($content, true); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Import blueprints. | ||||
|         $this->deepInit($this->items); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Initialize blueprints with its dynamic fields. | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function init() | ||||
|     { | ||||
|         foreach ($this->dynamic as $key => $data) { | ||||
|             // Locate field. | ||||
|             $path = explode('/', $key); | ||||
|             $current = &$this->items; | ||||
|  | ||||
|             foreach ($path as $field) { | ||||
|                 if (\is_object($current)) { | ||||
|                     // Handle objects. | ||||
|                     if (!isset($current->{$field})) { | ||||
|                         $current->{$field} = []; | ||||
|                     } | ||||
|  | ||||
|                     $current = &$current->{$field}; | ||||
|                 } else { | ||||
|                     // Handle arrays and scalars. | ||||
|                     if (!\is_array($current)) { | ||||
|                         $current = [$field => []]; | ||||
|                     } elseif (!isset($current[$field])) { | ||||
|                         $current[$field] = []; | ||||
|                     } | ||||
|  | ||||
|                     $current = &$current[$field]; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             // Set dynamic property. | ||||
|             foreach ($data as $property => $call) { | ||||
|                 $action = 'dynamic' . ucfirst($call['action']); | ||||
|  | ||||
|                 if (method_exists($this, $action)) { | ||||
|                     $this->{$action}($current, $property, $call); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Get form. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function form() | ||||
|     { | ||||
|         return (array) $this->get('form'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get form fields. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function fields() | ||||
|     { | ||||
|         $fields = $this->get('form/fields'); | ||||
|  | ||||
|         if ($fields === null) { | ||||
|             $field = $this->get('form/field'); | ||||
|             $fields = $field !== null ? ['' => (array) $field] : $fields; | ||||
|         } | ||||
|  | ||||
|         return (array) $fields; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Extend blueprint with another blueprint. | ||||
|      * | ||||
|      * @param BlueprintForm|array $extends | ||||
|      * @param bool $append | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function extend($extends, $append = false) | ||||
|     { | ||||
|         if ($extends instanceof self) { | ||||
|             $extends = $extends->toArray(); | ||||
|         } | ||||
|  | ||||
|         if ($append) { | ||||
|             $a = $this->items; | ||||
|             $b = $extends; | ||||
|         } else { | ||||
|             $a = $extends; | ||||
|             $b = $this->items; | ||||
|         } | ||||
|  | ||||
|         $this->items = $this->deepMerge($a, $b); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param string $name | ||||
|      * @param mixed $value | ||||
|      * @param string $separator | ||||
|      * @param bool $append | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function embed($name, $value, $separator = '/', $append = false) | ||||
|     { | ||||
|         $oldValue = $this->get($name, null, $separator); | ||||
|  | ||||
|         if (\is_array($oldValue) && \is_array($value)) { | ||||
|             if ($append) { | ||||
|                 $a = $oldValue; | ||||
|                 $b = $value; | ||||
|             } else { | ||||
|                 $a = $value; | ||||
|                 $b = $oldValue; | ||||
|             } | ||||
|  | ||||
|             $value = $this->deepMerge($a, $b); | ||||
|         } | ||||
|  | ||||
|         $this->set($name, $value, $separator); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get blueprints by using slash notation for nested arrays/objects. | ||||
|      * | ||||
|      * @example $value = $this->resolve('this/is/my/nested/variable'); | ||||
|      * returns ['this/is/my', 'nested/variable'] | ||||
|      * | ||||
|      * @param array  $path | ||||
|      * @param string  $separator | ||||
|      * @return array | ||||
|      */ | ||||
|     public function resolve(array $path, $separator = '/') | ||||
|     { | ||||
|         $fields = false; | ||||
|         $parts = []; | ||||
|         $current = $this['form/fields']; | ||||
|         $result = [null, null, null]; | ||||
|  | ||||
|         while (($field = current($path)) !== null) { | ||||
|             if (!$fields && isset($current['fields'])) { | ||||
|                 if (!empty($current['array'])) { | ||||
|                     $result = [$current, $parts, $path ? implode($separator, $path) : null]; | ||||
|                     // Skip item offset. | ||||
|                     $parts[] = array_shift($path); | ||||
|                 } | ||||
|  | ||||
|                 $current = $current['fields']; | ||||
|                 $fields = true; | ||||
|  | ||||
|             } elseif (isset($current[$field])) { | ||||
|                 $parts[] = array_shift($path); | ||||
|                 $current = $current[$field]; | ||||
|                 $fields = false; | ||||
|  | ||||
|             } elseif (isset($current[$index = '.' . $field])) { | ||||
|                 $parts[] = array_shift($path); | ||||
|                 $current = $current[$index]; | ||||
|                 $fields = false; | ||||
|  | ||||
|             } else { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Deep merge two arrays together. | ||||
|      * | ||||
|      * @param array $a | ||||
|      * @param array $b | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function deepMerge(array $a, array $b) | ||||
|     { | ||||
|         $bref_stack = [&$a]; | ||||
|         $head_stack = [$b]; | ||||
|  | ||||
|         do { | ||||
|             end($bref_stack); | ||||
|             $bref = &$bref_stack[key($bref_stack)]; | ||||
|             $head = array_pop($head_stack); | ||||
|             unset($bref_stack[key($bref_stack)]); | ||||
|  | ||||
|             foreach ($head as $key => $value) { | ||||
|                 if (strpos($key, '@') !== false) { | ||||
|                     // Remove @ from the start and the end. Key syntax `import@2` is supported to allow multiple operations of the same type. | ||||
|                     $list = explode('-', preg_replace('/^(@*)?([^@]+)(@\d*)?$/', '\2', $key), 2); | ||||
|                     $action = array_shift($list); | ||||
|                     $property = array_shift($list); | ||||
|  | ||||
|                     switch ($action) { | ||||
|                         case 'unset': | ||||
|                         case 'replace': | ||||
|                             if (!$property) { | ||||
|                                 $bref = ['unset@' => true]; | ||||
|                             } else { | ||||
|                                 unset($bref[$property]); | ||||
|                             } | ||||
|                             continue 2; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (isset($key, $bref[$key]) && \is_array($bref[$key]) && \is_array($head[$key])) { | ||||
|                     $bref_stack[] = &$bref[$key]; | ||||
|                     $head_stack[] = $head[$key]; | ||||
|                 } else { | ||||
|                     $bref = array_merge($bref, [$key => $head[$key]]); | ||||
|                 } | ||||
|             } | ||||
|         } while (\count($head_stack)); | ||||
|  | ||||
|         return $a; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $items | ||||
|      * @param array $path | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function deepInit(array &$items, $path = []) | ||||
|     { | ||||
|         $ordering = ''; | ||||
|         $order = []; | ||||
|         $field = end($path) === 'fields'; | ||||
|  | ||||
|         foreach ($items as $key => &$item) { | ||||
|             // Set name for nested field. | ||||
|             if ($field && isset($item['type'])) { | ||||
|                 $item['name'] = $key; | ||||
|             } | ||||
|  | ||||
|             // Handle special instructions in the form. | ||||
|             if (strpos($key, '@') !== false) { | ||||
|                 // Remove @ from the start and the end. Key syntax `import@2` is supported to allow multiple operations of the same type. | ||||
|                 $list = explode('-', preg_replace('/^(@*)?([^@]+)(@\d*)?$/', '\2', $key), 2); | ||||
|                 $action = array_shift($list); | ||||
|                 $property = array_shift($list); | ||||
|  | ||||
|                 switch ($action) { | ||||
|                     case 'unset': | ||||
|                         unset($items[$key]); | ||||
|                         if (empty($items)) { | ||||
|                             return null; | ||||
|                         } | ||||
|                         break; | ||||
|                     case 'import': | ||||
|                         unset($items[$key]); | ||||
|                         $this->doImport($item, $path); | ||||
|                         break; | ||||
|                     case 'ordering': | ||||
|                         $ordering = $item; | ||||
|                         unset($items[$key]); | ||||
|                         break; | ||||
|                     default: | ||||
|                         $this->dynamic[implode('/', $path)][$property] = ['action' => $action, 'params' => $item]; | ||||
|                 } | ||||
|  | ||||
|             } elseif (\is_array($item)) { | ||||
|                 // Recursively initialize form. | ||||
|                 $newPath = array_merge($path, [$key]); | ||||
|  | ||||
|                 $location = $this->deepInit($item, $newPath); | ||||
|                 if ($location) { | ||||
|                     $order[$key] = $location; | ||||
|                 } elseif ($location === null) { | ||||
|                     unset($items[$key]); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         unset($item); | ||||
|  | ||||
|         if ($order) { | ||||
|             // Reorder fields if needed. | ||||
|             $items = $this->doReorder($items, $order); | ||||
|         } | ||||
|  | ||||
|         return $ordering; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array|string $value | ||||
|      * @return array|null | ||||
|      */ | ||||
|     protected function loadImport($value) | ||||
|     { | ||||
|         $type = !\is_string($value) ? (!isset($value['type']) ? null : $value['type']) : $value; | ||||
|         $field = 'form'; | ||||
|  | ||||
|         if ($type && strpos($type, ':') !== false) { | ||||
|             list ($type, $field) = explode(':', $type, 2); | ||||
|         } | ||||
|  | ||||
|         if (!$type && !$field) { | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         if ($type) { | ||||
|             $files = $this->getFiles($type, isset($value['context']) ? $value['context'] : null); | ||||
|  | ||||
|             if (!$files) { | ||||
|                 return null; | ||||
|             } | ||||
|  | ||||
|             /** @var BlueprintForm $blueprint */ | ||||
|             $blueprint = new static($files); | ||||
|             $blueprint->setContext($this->context)->setOverrides($this->overrides)->load(); | ||||
|         } else { | ||||
|             $blueprint = $this; | ||||
|         } | ||||
|  | ||||
|         $import = $blueprint->get($field); | ||||
|  | ||||
|         return \is_array($import) ? $import : null; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array|string $value | ||||
|      * @param array $path | ||||
|      */ | ||||
|     protected function doImport($value, array &$path) | ||||
|     { | ||||
|         $imported = $this->loadImport($value); | ||||
|  | ||||
|         if ($imported) { | ||||
|             $this->deepInit($imported, $path); | ||||
|             $name = implode('/', $path); | ||||
|             $this->embed($name, $imported, '/', false); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Internal function that handles loading extended blueprints. | ||||
|      * | ||||
|      * @param array $files | ||||
|      * @param string|array|null $extends | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function doLoad(array $files, $extends = null) | ||||
|     { | ||||
|         $filename = array_shift($files); | ||||
|         $content = $this->loadFile($filename); | ||||
|  | ||||
|         $key = ''; | ||||
|         if (isset($content['extends@'])) { | ||||
|             $key = 'extends@'; | ||||
|         } elseif (isset($content['@extends'])) { | ||||
|             $key = '@extends'; | ||||
|         } elseif (isset($content['@extends@'])) { | ||||
|             $key = '@extends@'; | ||||
|         } | ||||
|  | ||||
|         $override = (bool)$extends; | ||||
|         $extends = (array)($key && !$extends ? $content[$key] : $extends); | ||||
|  | ||||
|         unset($content['extends@'], $content['@extends'], $content['@extends@']); | ||||
|  | ||||
|         $data = $extends ? $this->doExtend($filename, $files, $extends, $override) : []; | ||||
|         $data[] = $content; | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Internal function to recursively load extended blueprints. | ||||
|      * | ||||
|      * @param string $filename | ||||
|      * @param array $parents | ||||
|      * @param array $extends | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function doExtend($filename, array $parents, array $extends, $override = false) | ||||
|     { | ||||
|         if (\is_string(key($extends))) { | ||||
|             $extends = [$extends]; | ||||
|         } | ||||
|  | ||||
|         $data = [[]]; | ||||
|         foreach ($extends as $value) { | ||||
|             // Accept array of type and context or a string. | ||||
|             $type = !\is_string($value) ? (!isset($value['type']) ? null : $value['type']) : $value; | ||||
|  | ||||
|             if (!$type) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             if ($type === '@parent' || $type === 'parent@') { | ||||
|                 if (!$parents) { | ||||
|                     throw new RuntimeException("Parent blueprint missing for '{$filename}'"); | ||||
|                 } | ||||
|  | ||||
|                 $files = $parents; | ||||
|             } else { | ||||
|                 $files = $this->getFiles($type, isset($value['context']) ? $value['context'] : null); | ||||
|  | ||||
|                 if ($override && !$files) { | ||||
|                     throw new RuntimeException("Blueprint '{$type}' missing for '{$filename}'"); | ||||
|                 } | ||||
|  | ||||
|                 // Detect extend loops. | ||||
|                 if ($files && array_intersect($files, $parents)) { | ||||
|                     // Let's check if user really meant extends@: parent@. | ||||
|                     $index = \array_search($filename, $files, true); | ||||
|                     if ($index !== false) { | ||||
|                         // We want to grab only the parents of the file which is currently being loaded. | ||||
|                         $files = \array_slice($files, $index + 1); | ||||
|                     } | ||||
|                     if ($files !== $parents) { | ||||
|                         throw new RuntimeException("Loop detected while extending blueprint file '{$filename}'"); | ||||
|                     } | ||||
|                     if (!$parents) { | ||||
|                         throw new RuntimeException("Parent blueprint missing for '{$filename}'"); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if ($files) { | ||||
|                 $data[] = $this->doLoad($files); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // TODO: In PHP 5.6+ use array_merge(...$data); | ||||
|         return call_user_func_array('array_merge', $data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Internal function to reorder items. | ||||
|      * | ||||
|      * @param array $items | ||||
|      * @param array $keys | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function doReorder(array $items, array $keys) | ||||
|     { | ||||
|         $reordered = array_keys($items); | ||||
|  | ||||
|         foreach ($keys as $item => $ordering) { | ||||
|             if ((string)(int) $ordering === (string) $ordering) { | ||||
|                 $location = array_search($item, $reordered, true); | ||||
|                 $rel = array_splice($reordered, $location, 1); | ||||
|                 array_splice($reordered, $ordering, 0, $rel); | ||||
|  | ||||
|             } elseif (isset($items[$ordering])) { | ||||
|                 $location = array_search($item, $reordered, true); | ||||
|                 $rel = array_splice($reordered, $location, 1); | ||||
|                 $location = array_search($ordering, $reordered, true); | ||||
|                 array_splice($reordered, $location + 1, 0, $rel); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return array_merge(array_flip($reordered), $items); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										716
									
								
								vendor/rockettheme/toolbox/Blueprints/src/BlueprintSchema.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										716
									
								
								vendor/rockettheme/toolbox/Blueprints/src/BlueprintSchema.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,716 @@ | ||||
| <?php | ||||
| namespace RocketTheme\Toolbox\Blueprints; | ||||
|  | ||||
| /** | ||||
|  * BlueprintSchema is used to define a data structure. | ||||
|  * | ||||
|  * @package RocketTheme\Toolbox\Blueprints | ||||
|  * @author RocketTheme | ||||
|  * @license MIT | ||||
|  */ | ||||
| class BlueprintSchema | ||||
| { | ||||
|     /** @var array */ | ||||
|     protected $items = []; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $rules = []; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $nested = []; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $dynamic = []; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $filter = ['validation' => true]; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $ignoreFormKeys = ['fields' => 1]; | ||||
|  | ||||
|     /** @var array */ | ||||
|     protected $types = []; | ||||
|  | ||||
|     /** | ||||
|      * Constructor. | ||||
|      * | ||||
|      * @param array $serialized  Serialized content if available. | ||||
|      */ | ||||
|     public function __construct($serialized = null) | ||||
|     { | ||||
|         if (\is_array($serialized) && !empty($serialized)) { | ||||
|             $this->items = (array) $serialized['items']; | ||||
|             $this->rules = (array) $serialized['rules']; | ||||
|             $this->nested = (array) $serialized['nested']; | ||||
|             $this->dynamic = (array) $serialized['dynamic']; | ||||
|             $this->filter = (array) $serialized['filter']; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $types | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setTypes(array $types) | ||||
|     { | ||||
|         $this->types = $types; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Restore Blueprints object. | ||||
|      * | ||||
|      * @param array $serialized | ||||
|      * @return static | ||||
|      */ | ||||
|     public static function restore(array $serialized) | ||||
|     { | ||||
|         return new static($serialized); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Initialize blueprints with its dynamic fields. | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function init() | ||||
|     { | ||||
|         foreach ($this->dynamic as $key => $data) { | ||||
|             $field = &$this->items[$key]; | ||||
|  | ||||
|             foreach ($data as $property => $call) { | ||||
|                 $action = 'dynamic' . ucfirst($call['action']); | ||||
|  | ||||
|                 if (method_exists($this, $action)) { | ||||
|                     $this->{$action}($field, $property, $call); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set filter for inherited properties. | ||||
|      * | ||||
|      * @param array $filter     List of field names to be inherited. | ||||
|      */ | ||||
|     public function setFilter(array $filter) | ||||
|     { | ||||
|         $this->filter = array_flip($filter); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get value by using dot notation for nested arrays/objects. | ||||
|      * | ||||
|      * @example $value = $data->get('this.is.my.nested.variable'); | ||||
|      * | ||||
|      * @param string  $name       Dot separated path to the requested value. | ||||
|      * @param mixed   $default    Default value (or null). | ||||
|      * @param string  $separator  Separator, defaults to '.' | ||||
|      * | ||||
|      * @return mixed  Value. | ||||
|      */ | ||||
|     public function get($name, $default = null, $separator = '.') | ||||
|     { | ||||
|         $name = $separator !== '.' ? str_replace($separator, '.', $name) : $name; | ||||
|  | ||||
|         return isset($this->items[$name]) ? $this->items[$name] : $default; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set value by using dot notation for nested arrays/objects. | ||||
|      * | ||||
|      * @example $value = $data->set('this.is.my.nested.variable', $newField); | ||||
|      * | ||||
|      * @param string  $name       Dot separated path to the requested value. | ||||
|      * @param mixed   $value      New value. | ||||
|      * @param string  $separator  Separator, defaults to '.' | ||||
|      */ | ||||
|     public function set($name, $value, $separator = '.') | ||||
|     { | ||||
|         $name = $separator !== '.' ? str_replace($separator, '.', $name) : $name; | ||||
|  | ||||
|         $this->items[$name] = $value; | ||||
|         $this->addProperty($name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Define value by using dot notation for nested arrays/objects. | ||||
|      * | ||||
|      * @example $value = $data->set('this.is.my.nested.variable', true); | ||||
|      * | ||||
|      * @param string  $name       Dot separated path to the requested value. | ||||
|      * @param mixed   $value      New value. | ||||
|      * @param string  $separator  Separator, defaults to '.' | ||||
|      */ | ||||
|     public function def($name, $value, $separator = '.') | ||||
|     { | ||||
|         $this->set($name, $this->get($name, $value, $separator), $separator); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      * @deprecated | ||||
|      */ | ||||
|     public function toArray() | ||||
|     { | ||||
|         return $this->getState(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Convert object into an array. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getState() | ||||
|     { | ||||
|         return [ | ||||
|             'items' => $this->items, | ||||
|             'rules' => $this->rules, | ||||
|             'nested' => $this->nested, | ||||
|             'dynamic' => $this->dynamic, | ||||
|             'filter' => $this->filter | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get nested structure containing default values defined in the blueprints. | ||||
|      * | ||||
|      * Fields without default value are ignored in the list. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getDefaults() | ||||
|     { | ||||
|         return $this->buildDefaults($this->nested); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Embed an array to the blueprint. | ||||
|      * | ||||
|      * @param $name | ||||
|      * @param array $value | ||||
|      * @param string $separator | ||||
|      * @param bool $merge   Merge fields instead replacing them. | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function embed($name, array $value, $separator = '.', $merge = false) | ||||
|     { | ||||
|         if (isset($value['rules'])) { | ||||
|             $this->rules = array_merge($this->rules, $value['rules']); | ||||
|         } | ||||
|  | ||||
|         $name = $separator !== '.' ? str_replace($separator, '.', $name) : $name; | ||||
|  | ||||
|         if (isset($value['form'])) { | ||||
|             $form = array_diff_key($value['form'], ['fields' => 1, 'field' => 1]); | ||||
|         } else { | ||||
|             $form = []; | ||||
|         } | ||||
|  | ||||
|         $items = isset($this->items[$name]) ? $this->items[$name] : ['type' => '_root', 'form_field' => false]; | ||||
|  | ||||
|         $this->items[$name] = $items; | ||||
|         $this->addProperty($name); | ||||
|  | ||||
|         $prefix = $name ? $name . '.' : ''; | ||||
|         $params = array_intersect_key($form, $this->filter); | ||||
|         $location = [$name]; | ||||
|  | ||||
|         if (isset($value['form']['field'])) { | ||||
|             $this->parseFormField($name, $value['form']['field'], $params, $prefix, '', $merge, $location); | ||||
|         } elseif (isset($value['form']['fields'])) { | ||||
|             $this->parseFormFields($value['form']['fields'], $params, $prefix, '', $merge, $location); | ||||
|         } | ||||
|  | ||||
|         $this->items[$name] += ['form' => $form]; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Merge two arrays by using blueprints. | ||||
|      * | ||||
|      * @param  array $data1 | ||||
|      * @param  array $data2 | ||||
|      * @param  string $name         Optional | ||||
|      * @param  string $separator    Optional | ||||
|      * @return array | ||||
|      */ | ||||
|     public function mergeData(array $data1, array $data2, $name = null, $separator = '.') | ||||
|     { | ||||
|         $nested = $this->getNested($name, $separator); | ||||
|  | ||||
|         if (!\is_array($nested)) { | ||||
|             $nested = []; | ||||
|         } | ||||
|  | ||||
|         return $this->mergeArrays($data1, $data2, $nested); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the property with given path. | ||||
|      * | ||||
|      * @param string $path | ||||
|      * @param string $separator | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function getProperty($path = null, $separator = '.') | ||||
|     { | ||||
|         $name = $this->getPropertyName($path, $separator); | ||||
|         $property = $this->get($name); | ||||
|         $nested = $this->getNested($name); | ||||
|  | ||||
|         return $this->getPropertyRecursion($property, $nested); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns name of the property with given path. | ||||
|      * | ||||
|      * @param string $path | ||||
|      * @param string $separator | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getPropertyName($path = null, $separator = '.') | ||||
|     { | ||||
|         $parts = explode($separator, $path); | ||||
|         $nested = $this->nested; | ||||
|  | ||||
|         $result = []; | ||||
|         while (($part = array_shift($parts)) !== null) { | ||||
|             if (!isset($nested[$part])) { | ||||
|                 if (isset($nested['*'])) { | ||||
|                     $part = '*'; | ||||
|                 } else { | ||||
|                     return implode($separator, array_merge($result, [$part], $parts)); | ||||
|                 } | ||||
|             } | ||||
|             $result[] = $part; | ||||
|             $nested = $nested[$part]; | ||||
|         } | ||||
|  | ||||
|         return implode('.', $result); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return data fields that do not exist in blueprints. | ||||
|      * | ||||
|      * @param  array  $data | ||||
|      * @param  string $prefix | ||||
|      * @return array | ||||
|      */ | ||||
|     public function extra(array $data, $prefix = '') | ||||
|     { | ||||
|         $rules = $this->nested; | ||||
|  | ||||
|         // Drill down to prefix level | ||||
|         if (!empty($prefix)) { | ||||
|             $parts = explode('.', trim($prefix, '.')); | ||||
|             foreach ($parts as $part) { | ||||
|                 $rules = isset($rules[$part]) ? $rules[$part] : []; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Check if the form cannot have extra fields. | ||||
|         if (isset($rules[''])) { | ||||
|             $rule = $this->items['']; | ||||
|             if (isset($rule['type']) && $rule['type'] !== '_root') { | ||||
|                 return []; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $this->extraArray($data, $rules, $prefix); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the property with given path. | ||||
|      * | ||||
|      * @param $property | ||||
|      * @param $nested | ||||
|      * @return mixed | ||||
|      */ | ||||
|     protected function getPropertyRecursion($property, $nested) | ||||
|     { | ||||
|         if (empty($nested) || !\is_array($nested) || !isset($property['type'])) { | ||||
|             return $property; | ||||
|         } | ||||
|  | ||||
|         if ($property['type'] === '_root') { | ||||
|             foreach ($nested as $key => $value) { | ||||
|                 if ($key === '') { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 $name = \is_array($value) ? $key : $value; | ||||
|                 $property['fields'][$key] = $this->getPropertyRecursion($this->get($name), $value); | ||||
|             } | ||||
|         } elseif ($property['type'] === '_parent' || !empty($property['array'])) { | ||||
|             foreach ($nested as $key => $value) { | ||||
|                 $name = \is_array($value) ? "{$property['name']}.{$key}" : $value; | ||||
|                 $property['fields'][$key] = $this->getPropertyRecursion($this->get($name), $value); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $property; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get property from the definition. | ||||
|      * | ||||
|      * @param  string  $path  Comma separated path to the property. | ||||
|      * @param  string  $separator | ||||
|      * @return array|string|null | ||||
|      * @internal | ||||
|      */ | ||||
|     protected function getNested($path = null, $separator = '.') | ||||
|     { | ||||
|         if (!$path) { | ||||
|             return $this->nested; | ||||
|         } | ||||
|         $parts = explode($separator, $path); | ||||
|         $item = array_pop($parts); | ||||
|  | ||||
|         $nested = $this->nested; | ||||
|         foreach ($parts as $part) { | ||||
|             if (!isset($nested[$part])) { | ||||
|                 $part = '*'; | ||||
|                 if (!isset($nested[$part])) { | ||||
|                     return []; | ||||
|                 } | ||||
|             } | ||||
|             $nested = $nested[$part]; | ||||
|         } | ||||
|  | ||||
|         return isset($nested[$item]) ? $nested[$item] : (isset($nested['*']) ? $nested['*'] : null); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $nested | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function buildDefaults(array $nested) | ||||
|     { | ||||
|         $defaults = []; | ||||
|  | ||||
|         foreach ($nested as $key => $value) { | ||||
|             if ($key === '*') { | ||||
|                 // TODO: Add support for adding defaults to collections. | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             if (\is_array($value)) { | ||||
|                 // Recursively fetch the items. | ||||
|                 $list = $this->buildDefaults($value); | ||||
|  | ||||
|                 // Only return defaults if there are any. | ||||
|                 if (!empty($list)) { | ||||
|                     $defaults[$key] = $list; | ||||
|                 } | ||||
|             } else { | ||||
|                 // We hit a field; get default from it if it exists. | ||||
|                 $item = $this->get($value); | ||||
|  | ||||
|                 // Only return default value if it exists. | ||||
|                 if (isset($item['default'])) { | ||||
|                     $defaults[$key] = $item['default']; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $defaults; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $data1 | ||||
|      * @param array $data2 | ||||
|      * @param array $rules | ||||
|      * @return array | ||||
|      * @internal | ||||
|      */ | ||||
|     protected function mergeArrays(array $data1, array $data2, array $rules) | ||||
|     { | ||||
|         foreach ($data2 as $key => $field) { | ||||
|             $val = isset($rules[$key]) ? $rules[$key] : null; | ||||
|             $rule = \is_string($val) ? $this->items[$val] : null; | ||||
|  | ||||
|             if ((array_key_exists($key, $data1) && \is_array($data1[$key]) && \is_array($field) && \is_array($val) && !isset($val['*'])) | ||||
|                 || (!empty($rule['type']) && strpos($rule['type'], '_') === 0)) { | ||||
|                 // Array has been defined in blueprints and is not a collection of items. | ||||
|                 $data1[$key] = $this->mergeArrays($data1[$key], $field, $val); | ||||
|             } else { | ||||
|                 // Otherwise just take value from the data2. | ||||
|                 $data1[$key] = $field; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $data1; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Gets all field definitions from the blueprints. | ||||
|      * | ||||
|      * @param array  $fields    Fields to parse. | ||||
|      * @param array  $params    Property parameters. | ||||
|      * @param string $prefix    Property prefix. | ||||
|      * @param string $parent    Parent property. | ||||
|      * @param bool   $merge     Merge fields instead replacing them. | ||||
|      * @param array $formPath | ||||
|      */ | ||||
|     protected function parseFormFields(array $fields, array $params, $prefix = '', $parent = '', $merge = false, array $formPath = []) | ||||
|     { | ||||
|         if (isset($fields['type']) && !\is_array($fields['type'])) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // Go though all the fields in current level. | ||||
|         foreach ($fields as $key => $field) { | ||||
|             $this->parseFormField($key, $field, $params, $prefix, $parent, $merge, $formPath); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param string $key | ||||
|      * @param array $field | ||||
|      * @param array $params | ||||
|      * @param string $prefix | ||||
|      * @param string $parent | ||||
|      * @param bool $merge | ||||
|      * @param array $formPath | ||||
|      */ | ||||
|     protected function parseFormField($key, array $field, array $params, $prefix = '', $parent = '', $merge = false, array $formPath = []) | ||||
|     { | ||||
|         // Skip illegal field (needs to be an array). | ||||
|         if (!\is_array($field)) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         $key = $this->getFieldKey($key, $prefix, $parent); | ||||
|  | ||||
|         $newPath = array_merge($formPath, [$key]); | ||||
|  | ||||
|         $properties = array_diff_key($field, $this->ignoreFormKeys) + $params; | ||||
|         $properties['name'] = $key; | ||||
|  | ||||
|         // Set default properties for the field type. | ||||
|         $type = isset($properties['type']) ? $properties['type'] : ''; | ||||
|         if (isset($this->types[$type])) { | ||||
|             $properties += $this->types[$type]; | ||||
|         } | ||||
|  | ||||
|         // Merge properties with existing ones. | ||||
|         if ($merge && isset($this->items[$key])) { | ||||
|             $properties += $this->items[$key]; | ||||
|         } | ||||
|  | ||||
|         $isInputField = !isset($properties['input@']) || $properties['input@']; | ||||
|  | ||||
|         $propertyExists = isset($this->items[$key]); | ||||
|         if (!$isInputField) { | ||||
|             // Remove property if it exists. | ||||
|             if ($propertyExists) { | ||||
|                 $this->removeProperty($key); | ||||
|             } | ||||
|         } elseif (!$propertyExists) { | ||||
|             // Add missing property. | ||||
|             $this->addProperty($key); | ||||
|         } | ||||
|  | ||||
|         if (isset($field['fields'])) { | ||||
|             // Recursively get all the nested fields. | ||||
|             $isArray = !empty($properties['array']); | ||||
|             $newParams = array_intersect_key($properties, $this->filter); | ||||
|             $this->parseFormFields($field['fields'], $newParams, $prefix, $key . ($isArray ? '.*': ''), $merge, $newPath); | ||||
|         } else { | ||||
|             if (!isset($this->items[$key])) { | ||||
|                 // Add parent rules. | ||||
|                 $path = explode('.', $key); | ||||
|                 array_pop($path); | ||||
|                 $parent = ''; | ||||
|  | ||||
|                 foreach ($path as $part) { | ||||
|                     $parent .= ($parent ? '.' : '') . $part; | ||||
|                     if (!isset($this->items[$parent])) { | ||||
|                         $this->items[$parent] = ['type' => '_parent', 'name' => $parent, 'form_field' => false]; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if ($isInputField) { | ||||
|                 $this->parseProperties($key, $properties); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if ($isInputField) { | ||||
|             $this->items[$key] = $properties; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     protected function getFieldKey($key, $prefix, $parent) | ||||
|     { | ||||
|         // Set name from the array key. | ||||
|         if (strpos($key[0], '.') === 0) { | ||||
|             return ($parent ?: rtrim($prefix, '.')) . $key; | ||||
|         } | ||||
|  | ||||
|         return $prefix . $key; | ||||
|     } | ||||
|  | ||||
|     protected function parseProperties($key, array &$properties) | ||||
|     { | ||||
|         $key = ltrim($key, '.'); | ||||
|  | ||||
|         if (!empty($properties['data'])) { | ||||
|             $this->dynamic[$key] = $properties['data']; | ||||
|         } | ||||
|  | ||||
|         foreach ($properties as $name => $value) { | ||||
|             if (strpos($name[0], '@') !== false) { | ||||
|                 $list = explode('-', trim($name, '@'), 2); | ||||
|                 $action = array_shift($list); | ||||
|                 $property = array_shift($list); | ||||
|  | ||||
|                 $this->dynamic[$key][$property] = ['action' => $action, 'params' => $value]; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Initialize predefined validation rule. | ||||
|         if (isset($properties['validate']['rule'])) { | ||||
|             $properties['validate'] += $this->getRule($properties['validate']['rule']); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add property to the definition. | ||||
|      * | ||||
|      * @param  string  $path  Comma separated path to the property. | ||||
|      * @internal | ||||
|      */ | ||||
|     protected function addProperty($path) | ||||
|     { | ||||
|         $parts = explode('.', $path); | ||||
|         $item = array_pop($parts); | ||||
|  | ||||
|         $nested = &$this->nested; | ||||
|         foreach ($parts as $part) { | ||||
|             if (!isset($nested[$part]) || !\is_array($nested[$part])) { | ||||
|                 $nested[$part] = []; | ||||
|             } | ||||
|  | ||||
|             $nested = &$nested[$part]; | ||||
|         } | ||||
|  | ||||
|         if (!isset($nested[$item])) { | ||||
|             $nested[$item] = $path; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Remove property to the definition. | ||||
|      * | ||||
|      * @param  string  $path  Comma separated path to the property. | ||||
|      * @internal | ||||
|      */ | ||||
|     protected function removeProperty($path) | ||||
|     { | ||||
|         $parts = explode('.', $path); | ||||
|         $item = array_pop($parts); | ||||
|  | ||||
|         $nested = &$this->nested; | ||||
|         foreach ($parts as $part) { | ||||
|             if (!isset($nested[$part]) || !\is_array($nested[$part])) { | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             $nested = &$nested[$part]; | ||||
|         } | ||||
|  | ||||
|         if (isset($nested[$item])) { | ||||
|             unset($nested[$item]); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $rule | ||||
|      * @return array | ||||
|      * @internal | ||||
|      */ | ||||
|     protected function getRule($rule) | ||||
|     { | ||||
|         if (isset($this->rules[$rule]) && \is_array($this->rules[$rule])) { | ||||
|             return $this->rules[$rule]; | ||||
|         } | ||||
|         return []; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $data | ||||
|      * @param array $rules | ||||
|      * @param string $prefix | ||||
|      * @return array | ||||
|      * @internal | ||||
|      */ | ||||
|     protected function extraArray(array $data, array $rules, $prefix) | ||||
|     { | ||||
|         $array = []; | ||||
|  | ||||
|         foreach ($data as $key => $field) { | ||||
|             $val = isset($rules[$key]) ? $rules[$key] : (isset($rules['*']) ? $rules['*'] : null); | ||||
|             $rule = \is_string($val) ? $this->items[$val] : null; | ||||
|  | ||||
|             if ($rule || isset($val['*'])) { | ||||
|                 // Item has been defined in blueprints. | ||||
|             } elseif (\is_array($field) && \is_array($val)) { | ||||
|                 // Array has been defined in blueprints. | ||||
|                 $array += $this->extraArray($field, $val, $prefix . $key . '.'); | ||||
|             } else { | ||||
|                 // Undefined/extra item. | ||||
|                 $array[$prefix.$key] = $field; | ||||
|             } | ||||
|         } | ||||
|         return $array; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $field | ||||
|      * @param string $property | ||||
|      * @param array $call | ||||
|      */ | ||||
|     protected function dynamicData(array &$field, $property, array $call) | ||||
|     { | ||||
|         $params = $call['params']; | ||||
|  | ||||
|         if (\is_array($params)) { | ||||
|             $function = array_shift($params); | ||||
|         } else { | ||||
|             $function = $params; | ||||
|             $params = []; | ||||
|         } | ||||
|  | ||||
|         $list = explode('::', $function, 2); | ||||
|         $f = array_pop($list); | ||||
|         $o = array_pop($list); | ||||
|  | ||||
|         if (!$o) { | ||||
|             if (\function_exists($f)) { | ||||
|                 $data = \call_user_func_array($f, $params); | ||||
|             } | ||||
|         } else { | ||||
|             if (method_exists($o, $f)) { | ||||
|                 $data = \call_user_func_array(array($o, $f), $params); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // If function returns a value, | ||||
|         if (isset($data)) { | ||||
|             if (\is_array($data) && isset($field[$property]) && \is_array($field[$property])) { | ||||
|                 // Combine field and @data-field together. | ||||
|                 $field[$property] += $data; | ||||
|             } else { | ||||
|                 // Or create/replace field with @data-field. | ||||
|                 $field[$property] = $data; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										12
									
								
								vendor/rockettheme/toolbox/Blueprints/src/Blueprints.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								vendor/rockettheme/toolbox/Blueprints/src/Blueprints.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| <?php | ||||
| namespace RocketTheme\Toolbox\Blueprints; | ||||
|  | ||||
| /** | ||||
|  * Deprecated class, use BlueprintSchema instead. | ||||
|  * | ||||
|  * @package RocketTheme\Toolbox\Blueprints | ||||
|  * @author RocketTheme | ||||
|  * @license MIT | ||||
|  * @deprecated | ||||
|  */ | ||||
| class Blueprints extends BlueprintSchema {} | ||||
							
								
								
									
										96
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/BlueprintFormTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/BlueprintFormTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,96 @@ | ||||
| <?php | ||||
| use RocketTheme\Toolbox\Blueprints\BlueprintForm; | ||||
| use RocketTheme\Toolbox\File\YamlFile; | ||||
|  | ||||
| require_once 'helper.php'; | ||||
|  | ||||
| class BlueprintsBlueprintFormTest extends PHPUnit_Framework_TestCase | ||||
| { | ||||
|     /** | ||||
|      * @dataProvider dataProvider | ||||
|      */ | ||||
|     public function testLoad($test) | ||||
|     { | ||||
|         $blueprint = new Blueprint($test); | ||||
|         $blueprint->setOverrides( | ||||
|             ['extends' => ['extends', 'basic']] | ||||
|         ); | ||||
|         $blueprint->load(); | ||||
|  | ||||
|         // Save test results if they do not exist (data needs to be verified by human!) | ||||
|         /* | ||||
|         $resultFile = YamlFile::instance(__DIR__ . '/data/form/items/' . $test . '.yaml'); | ||||
|         if (!$resultFile->exists()) { | ||||
|             $resultFile->content($blueprint->toArray()); | ||||
|             $resultFile->save(); | ||||
|         } | ||||
|         */ | ||||
|  | ||||
|         // Test 1: Loaded form. | ||||
|         $this->assertEquals($this->loadYaml($test, 'form/items'), $blueprint->toArray()); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function dataProvider() | ||||
|     { | ||||
|         return [ | ||||
|             ['empty'], | ||||
|             ['basic'], | ||||
|             ['import'], | ||||
|             ['extends'] | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     protected function loadYaml($test, $type = 'blueprint') | ||||
|     { | ||||
|         $file = YamlFile::instance(__DIR__ . "/data/{$type}/{$test}.yaml"); | ||||
|         $content = $file->content(); | ||||
|         $file->free(); | ||||
|  | ||||
|         return $content; | ||||
|     } | ||||
| } | ||||
|  | ||||
| class Blueprint extends BlueprintForm | ||||
| { | ||||
|     /** | ||||
|      * @param string $filename | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function loadFile($filename) | ||||
|     { | ||||
|         $file = YamlFile::instance(__DIR__ . "/data/blueprint/{$filename}.yaml"); | ||||
|         $content = $file->content(); | ||||
|         $file->free(); | ||||
|  | ||||
|         return $content; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param string|array $path | ||||
|      * @param string $context | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function getFiles($path, $context = null) | ||||
|     { | ||||
|         if (is_string($path)) { | ||||
|             // Resolve filename. | ||||
|             if (isset($this->overrides[$path])) { | ||||
|                 $path = $this->overrides[$path]; | ||||
|             } else { | ||||
|                 if ($context === null) { | ||||
|                     $context = $this->context; | ||||
|                 } | ||||
|                 if ($context && $context[strlen($context)-1] !== '/') { | ||||
|                     $context .= '/'; | ||||
|                 } | ||||
|                 $path = $context . $path; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $files = (array) $path; | ||||
|  | ||||
|         return $files; | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										90
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/BlueprintSchemaTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/BlueprintSchemaTest.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| <?php | ||||
|  | ||||
| use RocketTheme\Toolbox\Blueprints\BlueprintSchema; | ||||
| use RocketTheme\Toolbox\File\YamlFile; | ||||
|  | ||||
| require_once 'helper.php'; | ||||
|  | ||||
| class BlueprintsBlueprintSchemaTest extends PHPUnit_Framework_TestCase | ||||
| { | ||||
|     public function testCreation() | ||||
|     { | ||||
|         $blueprints = new BlueprintSchema; | ||||
|  | ||||
|         $this->assertEquals( | ||||
|             [ | ||||
|                 'items' => [], | ||||
|                 'rules' => [], | ||||
|                 'nested' => [], | ||||
|                 'dynamic' => [], | ||||
|                 'filter' => ['validation' => true] | ||||
|             ], | ||||
|             $blueprints->getState()); | ||||
|  | ||||
|         $this->assertEquals([], $blueprints->getDefaults()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @dataProvider dataProvider | ||||
|      */ | ||||
|     public function testLoad($test) | ||||
|     { | ||||
|         $input = $this->loadYaml($test); | ||||
|  | ||||
|         $blueprint = new BlueprintSchema; | ||||
|         $blueprint->embed('', $input); | ||||
|  | ||||
|         // Save test results if they do not exist (data needs to be verified by human!) | ||||
|         /* | ||||
|         $resultFile = YamlFile::instance(__DIR__ . '/data/schema/state/' . $test . '.yaml'); | ||||
|         if (!$resultFile->exists()) { | ||||
|             $resultFile->content($blueprint->getState()); | ||||
|             $resultFile->save(); | ||||
|         } | ||||
|         */ | ||||
|  | ||||
|         // Test 1: Internal state. | ||||
|         $this->assertEquals($this->loadYaml($test, 'schema/state'), $blueprint->getState()); | ||||
|  | ||||
|         // Save test results if they do not exist (data needs to be verified by human!) | ||||
|  | ||||
|         $resultFile = YamlFile::instance(__DIR__ . '/data/schema/init/' . $test . '.yaml'); | ||||
|         if (!$resultFile->exists()) { | ||||
|             $resultFile->content($blueprint->init()->getState()); | ||||
|             $resultFile->save(); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         // Test 2: Initialize blueprint. | ||||
|         $this->assertEquals($this->loadYaml($test, 'schema/init'), $blueprint->init()->getState()); | ||||
|  | ||||
|         // Test 3: Default values. | ||||
|         $this->assertEquals($this->loadYaml($test, 'schema/defaults'), $blueprint->getDefaults()); | ||||
|  | ||||
|         // Test 4: Extra values. | ||||
|         $this->assertEquals($this->loadYaml($test, 'schema/extra'), $blueprint->extra($this->loadYaml($test, 'input'))); | ||||
|  | ||||
|         // Test 5: Merge data. | ||||
|         $this->assertEquals( | ||||
|             $this->loadYaml($test, 'schema/merge'), | ||||
|             $blueprint->mergeData($blueprint->getDefaults(), $this->loadYaml($test, 'input')) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function dataProvider() | ||||
|     { | ||||
|         return [ | ||||
|             ['empty'], | ||||
|             ['basic'], | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     protected function loadYaml($test, $type = 'blueprint') | ||||
|     { | ||||
|         $file = YamlFile::instance(__DIR__ . "/data/{$type}/{$test}.yaml"); | ||||
|         $content = $file->content(); | ||||
|         $file->free(); | ||||
|  | ||||
|         return $content; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										41
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| rules: | ||||
|   name: | ||||
|     pattern: "[A-Z][a-z]+" | ||||
|     min: 3 | ||||
|     max: 15 | ||||
|  | ||||
| form: | ||||
|   validation: loose | ||||
|   fields: | ||||
|     text: | ||||
|       type: text | ||||
|       label: Text | ||||
|       placeholder: 'Enter your text' | ||||
|  | ||||
|     enabled: | ||||
|       type: select | ||||
|       label: Enabled | ||||
|       default: true | ||||
|       data-options@: blueprint_data_option_test | ||||
|  | ||||
|     user.name: | ||||
|       type: name | ||||
|       label: Name | ||||
|       default: John | ||||
|       validate: | ||||
|         type: name | ||||
|  | ||||
|     user.country: | ||||
|       type: select | ||||
|       label: Enabled | ||||
|       default: fi | ||||
|       data-options@: | ||||
|         - blueprint_data_option_test | ||||
|         - { us: 'United States', fi: 'Finland', po: 'Poland' } | ||||
|         - true | ||||
|  | ||||
|     undefined: | ||||
|       type: select | ||||
|       label: Undefined | ||||
|       data-options@: undefined_function | ||||
|  | ||||
							
								
								
									
										0
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										17
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/extends.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/extends.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| extends@: parent@ | ||||
|  | ||||
| form: | ||||
|   fields: | ||||
|     enabled: | ||||
|       default: false | ||||
|  | ||||
|     text: | ||||
|       default: My text | ||||
|       ordering@: enabled | ||||
|  | ||||
|     user.name: | ||||
|       default: Joe | ||||
|       unset-validate@: true | ||||
|  | ||||
|     undefined: | ||||
|       unset@: true | ||||
							
								
								
									
										4
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/import.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/import.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| form: | ||||
|   fields: | ||||
|     address: | ||||
|       import@: partials/address | ||||
							
								
								
									
										17
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/partials/address.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/blueprint/partials/address.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| form: | ||||
|   fields: | ||||
|     user.address: | ||||
|       type: text | ||||
|       label: Address | ||||
|  | ||||
|     user.zip: | ||||
|       type: text | ||||
|       label: ZIP code | ||||
|  | ||||
|     user.city: | ||||
|       type: text | ||||
|       label: City | ||||
|  | ||||
|     user.country: | ||||
|       type: text | ||||
|       label: Country | ||||
							
								
								
									
										40
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| rules: | ||||
|   name: | ||||
|     pattern: '[A-Z][a-z]+' | ||||
|     min: 3 | ||||
|     max: 15 | ||||
| form: | ||||
|   validation: loose | ||||
|   fields: | ||||
|     text: | ||||
|       type: text | ||||
|       label: Text | ||||
|       placeholder: 'Enter your text' | ||||
|       name: text | ||||
|     enabled: | ||||
|       type: select | ||||
|       label: Enabled | ||||
|       default: true | ||||
|       data-options@: blueprint_data_option_test | ||||
|       name: enabled | ||||
|     user.name: | ||||
|       type: name | ||||
|       label: Name | ||||
|       default: John | ||||
|       validate: | ||||
|         type: name | ||||
|       name: user.name | ||||
|     user.country: | ||||
|       type: select | ||||
|       label: Enabled | ||||
|       default: fi | ||||
|       data-options@: | ||||
|         - blueprint_data_option_test | ||||
|         - { us: 'United States', fi: Finland, po: Poland } | ||||
|         - true | ||||
|       name: user.country | ||||
|     undefined: | ||||
|       type: select | ||||
|       label: Undefined | ||||
|       data-options@: undefined_function | ||||
|       name: undefined | ||||
							
								
								
									
										1
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| {  } | ||||
							
								
								
									
										34
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/extends.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/extends.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| rules: | ||||
|   name: | ||||
|     pattern: '[A-Z][a-z]+' | ||||
|     min: 3 | ||||
|     max: 15 | ||||
| form: | ||||
|   validation: loose | ||||
|   fields: | ||||
|     enabled: | ||||
|       type: select | ||||
|       label: Enabled | ||||
|       default: false | ||||
|       data-options@: blueprint_data_option_test | ||||
|       name: enabled | ||||
|     text: | ||||
|       type: text | ||||
|       label: Text | ||||
|       placeholder: 'Enter your text' | ||||
|       default: 'My text' | ||||
|       name: text | ||||
|     user.name: | ||||
|       type: name | ||||
|       label: Name | ||||
|       default: Joe | ||||
|       name: user.name | ||||
|     user.country: | ||||
|       type: select | ||||
|       label: Enabled | ||||
|       default: fi | ||||
|       data-options@: | ||||
|         - blueprint_data_option_test | ||||
|         - { us: 'United States', fi: Finland, po: Poland } | ||||
|         - true | ||||
|       name: user.country | ||||
							
								
								
									
										8
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/import.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/form/items/import.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| form: | ||||
|   fields: | ||||
|     address: | ||||
|       fields: | ||||
|         user.address: { type: text, label: Address, name: user.address } | ||||
|         user.zip: { type: text, label: 'ZIP code', name: user.zip } | ||||
|         user.city: { type: text, label: City, name: user.city } | ||||
|         user.country: { type: text, label: Country, name: user.country } | ||||
							
								
								
									
										12
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/input/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/input/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| text: Testing... | ||||
| user: | ||||
|   name: Igor | ||||
|   extra: data... | ||||
|  | ||||
| some: | ||||
|   random: false | ||||
|   variables: | ||||
|     - true | ||||
|     - false | ||||
| just: for | ||||
| fun: | ||||
							
								
								
									
										7
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/input/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/input/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| some: | ||||
|   random: false | ||||
|   variables: | ||||
|     - true | ||||
|     - false | ||||
| just: for | ||||
| fun: | ||||
							
								
								
									
										4
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| enabled: true | ||||
| user: | ||||
|   name: John | ||||
|   country: fi | ||||
							
								
								
									
										0
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/defaults/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										8
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| some: | ||||
|   random: false | ||||
|   variables: | ||||
|     - true | ||||
|     - false | ||||
| just: for | ||||
| fun: | ||||
| user.extra: data... | ||||
							
								
								
									
										7
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/extra/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| some: | ||||
|   random: false | ||||
|   variables: | ||||
|     - true | ||||
|     - false | ||||
| just: for | ||||
| fun: | ||||
							
								
								
									
										88
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| items: | ||||
|   '': | ||||
|     form: | ||||
|       validation: loose | ||||
|     type: _root | ||||
|     form_field: false | ||||
|   text: | ||||
|     type: text | ||||
|     label: Text | ||||
|     placeholder: 'Enter your text' | ||||
|     validation: loose | ||||
|     name: text | ||||
|   enabled: | ||||
|     type: select | ||||
|     label: Enabled | ||||
|     default: true | ||||
|     data-options@: blueprint_data_option_test | ||||
|     validation: loose | ||||
|     name: enabled | ||||
|     options: | ||||
|       'yes': 'Yes' | ||||
|       'no': 'No' | ||||
|   user: | ||||
|     type: _parent | ||||
|     name: user | ||||
|     form_field: false | ||||
|   user.name: | ||||
|     type: name | ||||
|     label: Name | ||||
|     default: John | ||||
|     validate: | ||||
|       type: name | ||||
|     validation: loose | ||||
|     name: user.name | ||||
|   user.country: | ||||
|     type: select | ||||
|     label: Enabled | ||||
|     default: fi | ||||
|     data-options@: | ||||
|       - blueprint_data_option_test | ||||
|       - | ||||
|         us: 'United States' | ||||
|         fi: Finland | ||||
|         po: Poland | ||||
|       - true | ||||
|     validation: loose | ||||
|     name: user.country | ||||
|     options: | ||||
|       fi: Finland | ||||
|       po: Poland | ||||
|       us: 'United States' | ||||
|   undefined: | ||||
|     type: select | ||||
|     label: Undefined | ||||
|     data-options@: undefined_function | ||||
|     validation: loose | ||||
|     name: undefined | ||||
| rules: | ||||
|   name: | ||||
|     pattern: '[A-Z][a-z]+' | ||||
|     min: 3 | ||||
|     max: 15 | ||||
| nested: | ||||
|   '': '' | ||||
|   text: text | ||||
|   enabled: enabled | ||||
|   user: | ||||
|     name: user.name | ||||
|     country: user.country | ||||
|   undefined: undefined | ||||
| dynamic: | ||||
|   enabled: | ||||
|     options: | ||||
|       action: data | ||||
|       params: blueprint_data_option_test | ||||
|   user.country: | ||||
|     options: | ||||
|       action: data | ||||
|       params: | ||||
|         - blueprint_data_option_test | ||||
|         - { us: 'United States', fi: Finland, po: Poland } | ||||
|         - true | ||||
|   undefined: | ||||
|     options: | ||||
|       action: data | ||||
|       params: undefined_function | ||||
| filter: | ||||
|   validation: true | ||||
							
								
								
									
										11
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/init/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| items: | ||||
|   '': | ||||
|     form: {  } | ||||
|     type: _root | ||||
|     form_field: false | ||||
| rules: {  } | ||||
| nested: | ||||
|   '': '' | ||||
| dynamic: {  } | ||||
| filter: | ||||
|   validation: true | ||||
							
								
								
									
										14
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| text: Testing... | ||||
| user: | ||||
|   name: Igor | ||||
|   country: fi | ||||
|   extra: data... | ||||
|  | ||||
| some: | ||||
|   random: false | ||||
|   variables: | ||||
|     - true | ||||
|     - false | ||||
| just: for | ||||
| fun: | ||||
| enabled: true | ||||
							
								
								
									
										7
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/merge/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| some: | ||||
|   random: false | ||||
|   variables: | ||||
|     - true | ||||
|     - false | ||||
| just: for | ||||
| fun: | ||||
							
								
								
									
										81
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/basic.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,81 @@ | ||||
| items: | ||||
|   '': | ||||
|     form: | ||||
|       validation: loose | ||||
|     type: _root | ||||
|     form_field: false | ||||
|   text: | ||||
|     type: text | ||||
|     label: Text | ||||
|     placeholder: 'Enter your text' | ||||
|     validation: loose | ||||
|     name: text | ||||
|   enabled: | ||||
|     type: select | ||||
|     label: Enabled | ||||
|     default: true | ||||
|     data-options@: blueprint_data_option_test | ||||
|     validation: loose | ||||
|     name: enabled | ||||
|   user: | ||||
|     type: _parent | ||||
|     name: user | ||||
|     form_field: false | ||||
|   user.name: | ||||
|     type: name | ||||
|     label: Name | ||||
|     default: John | ||||
|     validate: | ||||
|       type: name | ||||
|     validation: loose | ||||
|     name: user.name | ||||
|   user.country: | ||||
|     type: select | ||||
|     label: Enabled | ||||
|     default: fi | ||||
|     data-options@: | ||||
|       - blueprint_data_option_test | ||||
|       - | ||||
|         us: 'United States' | ||||
|         fi: Finland | ||||
|         po: Poland | ||||
|       - true | ||||
|     validation: loose | ||||
|     name: user.country | ||||
|   undefined: | ||||
|     type: select | ||||
|     label: Undefined | ||||
|     data-options@: undefined_function | ||||
|     validation: loose | ||||
|     name: undefined | ||||
| rules: | ||||
|   name: | ||||
|     pattern: '[A-Z][a-z]+' | ||||
|     min: 3 | ||||
|     max: 15 | ||||
| nested: | ||||
|   '': '' | ||||
|   text: text | ||||
|   enabled: enabled | ||||
|   user: | ||||
|     name: user.name | ||||
|     country: user.country | ||||
|   undefined: undefined | ||||
| dynamic: | ||||
|   enabled: | ||||
|     options: | ||||
|       action: data | ||||
|       params: blueprint_data_option_test | ||||
|   user.country: | ||||
|     options: | ||||
|       action: data | ||||
|       params: | ||||
|         - blueprint_data_option_test | ||||
|         - { us: 'United States', fi: Finland, po: Poland } | ||||
|         - true | ||||
|   undefined: | ||||
|     options: | ||||
|       action: data | ||||
|       params: undefined_function | ||||
| filter: | ||||
|   validation: true | ||||
							
								
								
									
										11
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/data/schema/state/empty.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| items: | ||||
|   '': | ||||
|     form: {  } | ||||
|     type: _root | ||||
|     form_field: false | ||||
| rules: {  } | ||||
| nested: | ||||
|   '': '' | ||||
| dynamic: {  } | ||||
| filter: | ||||
|   validation: true | ||||
							
								
								
									
										9
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/helper.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								vendor/rockettheme/toolbox/Blueprints/tests/helper.php
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| <?php | ||||
|  | ||||
| function blueprint_data_option_test(array $param = null, $sort = false) | ||||
| { | ||||
|     if ($sort) { | ||||
|         asort($param); | ||||
|     } | ||||
|     return $param ?: ['yes' => 'Yes', 'no' => 'No']; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user