| | |
| | | <?php |
| | | namespace JVBase\managers\SEO\render\Traits\_Helpers; |
| | | |
| | | use JVBase\base\SchemaHelper; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | | } |
| | | trait arrayHelper { |
| | | protected function classArray(string $property, array $array, string $className):array |
| | | { |
| | | return array_filter($array, function ($item) use ($property, $className) { |
| | | return array_filter(array_map(function ($item) { |
| | | if (is_array($item) && array_key_exists('type', $item)) { |
| | | $item = SchemaHelper::classFromConfig($item); |
| | | } |
| | | return $item; |
| | | },$array), function ($item) use ($property, $className) { |
| | | $test = class_exists($className) && is_a($item, $className); |
| | | if (!$test) { |
| | | error_log('[SEO]Item property '.$property.' is not an instance of '.$className); |
| | |
| | | } |
| | | protected function mixedArray(string $property, array $array, array $allowedTypes):array |
| | | { |
| | | return array_filter($array, function($item) use ($property, $allowedTypes) { |
| | | |
| | | return array_filter(array_map(function($item) { |
| | | if (is_array($item) && array_key_exists('type', $item)) { |
| | | return JVB()->schemaHelper()::classFromConfig($item); |
| | | } else { |
| | | return $item; |
| | | } |
| | | },$array), function($item) use ($property, $allowedTypes) { |
| | | $test = in_array(gettype($item), $allowedTypes) || $this->testClasses($item, $allowedTypes); |
| | | if (!$test) { |
| | | error_log('[SEO]Item property '.$property.' is not an allowed type: '.print_r($item, true)); |