Short description of method buildFromArray

@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param  array array
@return common_configuration_Component
9303
public static function buildFromArray($array)
    {
        $returnValue = null;

        
        if (!empty($array)){
        	if (!empty($array['type'])){
        		$acceptedTypes = array('PHPRuntime', 'PHPINIValue', 'PHPExtension', 'PHPDatabaseDriver', 'FileSystemComponent', 'Custom', 'Mock');
        		$cleanType = preg_replace('/^Check/i', '', $array['type']);
        		if (in_array($cleanType, $acceptedTypes)){
        			
        			if (!empty($array['value'])){
        				$values = $array['value'];
        				
        				// Optional parameter is always used.
        				$optional = false;
        				if (!empty($values['optional'])){
        					$optional = $values['optional'];
        				}
        				
	        			switch ($cleanType){
	        				case 'PHPRuntime':
	        					$max = null;
	        					if (!empty($values['max'])){
	        						$max = $values['max'];
	        					}
	        					
	        					if (empty($values['min'])){
	        						$msg = "Mandatory attribute 'min' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}
	        					
	        					$returnValue = self::buildPHPRuntime($values['min'], $max, $optional);
	        				break;
	        				
	        				case 'PHPINIValue':
	        					if (empty($values['name'])){
	        						$msg = "Mandatory attribute 'name' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}
	        					
	        					if (empty($values['value']) && $values['value'] !== '0'){
	        						$msg = "Mandatory attribute 'value' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}
	        					
	        					$returnValue = self::buildPHPINIValue($values['name'], $values['value'], $optional);
	        				break;
	        				
	        				case 'PHPExtension':
	        					if (empty($values['name'])){
	        						$msg = "Mandatory attribute 'name' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}
	        					
	        					$min = null;
	        					if (!empty($values['min'])){
	        						$min = $values['min'];	
	        					}
	        					
	        					$max = null;
	        					if (!empty($values['max'])){
	        						$max = $values['max'];	
	        					}
	        					
	        					$returnValue = self::buildPHPExtension($values['name'], $min, $max, $optional);
	        				break;
	        				
	        				case 'PHPDatabaseDriver':
	        					if (empty($values['name'])){
	        						$msg = "Mandatory attribute 'name' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}
	        					
	        					$returnValue = self::buildPHPDatabaseDriver($values['name'], $optional);
	        				break;
	        				
	        				case 'FileSystemComponent':
	        					if (empty($values['location'])){
	        						$msg = "Mandatory attribute 'location' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}
	        					
	        					if (empty($values['rights'])){
	        						$msg = "Mandatory attribute 'rights' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}
	        					
	        					$returnValue = self::buildFileSystemComponent($values['location'], $values['rights'], $optional);
	        				break;
	        				
	        				case 'Custom':
	        					if (empty($values['name'])){
	        						$msg = "Mandatory attribute 'name' is missing.";
	        						throw new common_configuration_ComponentFactoryException($msg);	
	        					}

	        					$extension = 'generis';
	        					if (!empty($values['extension'])){
	        						$extension = $values['extension'];
	        					}
	        					
	        					$returnValue = self::buildCustom($values['name'], $extension, $optional);
	        				break;
	        				
	        				case 'Mock':
	        					$status = common_configuration_Report::VALID; 
	        					if (!empty($values['status'])){
	        						$status = $values['status'];
	        					}
	        					
	        					$returnValue = self::buildMock($status, $optional);
	        				break;
	        			}	
        			}
        			else{
        				$msg = "No 'value' array provided.";
        				throw new common_configuration_ComponentFactoryException($msg);
        			}
        		}
        		else{
        			$msg = "Unknown 'type' = '${cleanType}'.";
        			throw new common_configuration_ComponentFactoryException($msg);
        		}
        	}
        	else{
        		$msg = "Cannot build a Configuration Component without 'type'.";
        		throw new common_configuration_ComponentFactoryException($msg);
        	}
        }
        else{
        	$msg = 'Cannot build a Configuration Component with an empty array.';
        	throw new common_configuration_ComponentFactoryException($msg);
        }
        

        return $returnValue;
    }
1072308
public function build(array $arguments = [])
    {
        $arguments = Arrays::arrayMergeRecursiveOverrule($this->arguments, $arguments);
        $arguments = $this->mergeArgumentsWithRequestArguments($arguments);

        $httpRequest = $this->request->getHttpRequest();

        $uriPathPrefix = $this->environment->isRewriteEnabled() ? '' : 'index.php/';
        $uriPathPrefix = $httpRequest->getScriptRequestPath() . $uriPathPrefix;
        $resolveContext = new ResolveContext($httpRequest->getBaseUri(), $arguments, $this->createAbsoluteUri, $uriPathPrefix);
        $resolvedUri = $this->router->resolve($resolveContext);
        if ($this->section !== '') {
            $resolvedUri = $resolvedUri->withFragment($this->section);
        }

        $this->lastArguments = $arguments;
        return (string)$resolvedUri;
    }
372229
public static function createFromArray(array $array)
    {
        return new self(
            $array['id'],
            $array['source'],
            isset($array['parent'])
                ? self::createFromArray($array['parent'])
                : null,
            isset($array['children'])
                ? array_map(function (array $child) {
                    return Comment::createFromArray($child);
                }, $array['children'])
                : [],
            (string) $array['author_uuid'],
            $array['author_name'] ?? null,
            $array['author_email'] ?? null,
            $array['author_avatar'] ?? null,
            $array['author_role'] ?? null,
            $array['thumb'] ?? null,
            isset($array['rating'])
                ? (int) $array['rating']
                : null,
            $array['content'] ?? '',
            (int) $array['state'],
            isset($array['created_at'])
                ? DateTime::createFromFormat(DATE_ATOM, $array['created_at'])
                : null
        );
    }
1266356
public function build(array $config)
    {
        // Fix path in output dir
        $config['output_dir'] = $this->normalizePath($config['output_dir']);
        $config['output_dir'] = trim($config['output_dir'], DIRECTORY_SEPARATOR);
        if (!strlen($config['output_dir'])) {
            unset($config['output_dir']);
        }
        $output = array();
        if (in_array($config['less_filter'], array('sass', 'scssphp'))) {
            $output += $this->buildCssWithSass($config);
        } elseif ('none' !== $config['less_filter']) {
            $output += $this->buildCssWithLess($config);
        } else {
            $output += $this->buildCss($config);
        }

        $output['bootstrap_css']['output'] = $this->normalizePath(isset($config['output_dir']) ? array($config['output_dir'], 'css/bootstrap.css') : 'css/bootstrap.css');
        if ($config['font_awesome']) {
            $output['font_awesome_css']['output'] = $this->normalizePath(isset($config['output_dir']) ? array($config['output_dir'], 'css/font-awesome.css') : 'css/font-awesome.css');
        }
        $output += $this->buildJs($config);
        return $output;
    }
328898
public static function createFromArray(array $array): self
    {
        $map = new self;

        foreach ($array as $key => $value) {
            $map->put($key, $value);
        }

        return $map;
    }
1185401
public static function createFromArray(array $array): self
    {
        $query = isset($array['coordinate'])
            ? self::createLocated(
                Coordinate::createFromArray($array['coordinate']),
                $array['q'] ?? '',
                (int) ($array['page'] ?? self::DEFAULT_PAGE),
                (int) ($array['size'] ?? self::DEFAULT_SIZE)
            )
            : self::create(
                $array['q'] ?? '',
                (int) ($array['page'] ?? self::DEFAULT_PAGE),
                (int) ($array['size'] ?? self::DEFAULT_SIZE)
            );
        $query->fields = $array['fields'] ?? [];
        $query->aggregations = array_map(function (array $aggregation) {
            return Aggregation::createFromArray($aggregation);
        }, $array['aggregations'] ?? []);

        $query->sortBy = SortBy::createFromArray($array['sort'] ?? []);
        $query->filters = array_merge(
            $query->filters,
            array_map(function (array $filter) {
                return Filter::createFromArray($filter);
            }, $array['filters'] ?? [])
        );
        $query->universeFilters = array_merge(
            $query->universeFilters,
            array_map(function (array $filter) {
                return Filter::createFromArray($filter);
            }, $array['universe_filters'] ?? [])
        );
        $query->resultsEnabled = $array['results_enabled'] ?? true;
        $query->suggestionsEnabled = $array['suggestions_enabled'] ?? false;
        $query->aggregationsEnabled = $array['aggregations_enabled'] ?? true;
        $query->highlightEnabled = $array['highlight_enabled'] ?? false;
        $query->itemsPromoted = array_values(array_map(function (array $itemUUID) {
            return ItemUUID::createFromArray($itemUUID);
        }, $array['items_promoted'] ?? []));
        $query->fuzziness = $array['fuzziness'] ?? null;
        $query->searchableFields = $array['searchable_fields'] ?? [];
        $query->scoreStrategies = isset($array['score_strategies'])
            ? ScoreStrategies::createFromArray($array['score_strategies'])
            : null;
        $query->minScore = $array['min_score'] ?? self::NO_MIN_SCORE;
        $query->metadata = $array['metadata'] ?? [];

        if (isset($array['user'])) {
            $query->user = User::createFromArray($array['user']);
        }

        $query->subqueries = array_map(function (array $query) {
            return Query::createFromArray($query);
        }, $array['subqueries'] ?? []);

        if (isset($array['uuid'])) {
            $query->UUID = $array['uuid'];
        }
        if (isset($array['index_uuid'])) {
            $query->indexUUID = IndexUUID::createFromArray($array['index_uuid']);
        }

        return $query;
    }
514589
private static function configArrayMergeRecursive($array1, $array2) {
        if (is_array($array1) && is_array($array2)) {
            foreach ($array2 as $key => $value) {
                if (isset($array1[$key])) {
                    $array1[$key] = self::configArrayMergeRecursive($array1[$key], $array2[$key]);
                } else {
                    $array1[$key] = $value;
                }
            }
        } else {
            $array1 = $array2;
        }
        return $array1;
    }
1167415
public static function createFromArray(array $data)
    {
        $self = new self();

        if (isset($data['assets'])) {
            $self->setAssets($data['assets']);
        }
        if (isset($data['locales'])) {
            $self->setLocales($data['locales']);
        }

        return $self;
    }
743164
private function buildDefinition(array $array)
    {
        $definition = null;
        if (isset($array['parent'])) {
            $definition = new DefinitionDecorator($array['parent']);
        } else {
            $definition = new Definition();
        }

        if (isset($array['synthetic'])) {
            $definition->setSynthetic($array['synthetic']);
        }

        $this->setDefinitionClass($definition, $array);
        $this->setDefinitionArguments($definition, $array);
        $this->setDefinitionFactory($definition, $array);
        $this->setDefinitionTags($definition, $array);
        $this->setDefinitionMethodCalls($definition, $array);
        $this->setDefinitionProperties($definition, $array);
        $this->setDefinitionConfigurator($definition, $array);

        return $definition;
    }
261275
public static Object concat(Object[] arrs)
    {
        int   totalLen            = 0;
        Class commonComponentType = null;
        for (int i = 0, len = arrs.length; i < len; i++)
        {
            // skip all null arrays
            if (arrs[i] == null)
            {
                continue;
            }

            int arrayLen = Array.getLength(arrs[i]);

            // skip all empty arrays
            if (arrayLen == 0)
            {
                continue;
            }

            totalLen += arrayLen;

            Class componentType = arrs[i].getClass().getComponentType();
            commonComponentType =
                (commonComponentType == null) ? componentType
                                              : commonClass(commonComponentType, componentType);
        }

        if (commonComponentType == null)
        {
            return null;
        }

        return concat(Array.newInstance(commonComponentType, totalLen), totalLen, arrs);
    }
823526
public function build(array $config)
    {
        $output = array();

        // Fix path in output dir
        if ('/' !== substr($config['output_dir'], -1) && strlen($config['output_dir']) > 0) {
            $config['output_dir'] .= '/';
        }

        // changed from css_preprocessor to css_preprocessor for 3.0
        if (in_array($config['css_preprocessor'], array('sass', 'scssphp'))) {
            $output['bootstrap_css'] = $this->buildCssWithSass($config);
        } elseif ('none' !== $config['css_preprocessor']) {
            $output['bootstrap_css'] = $this->buildCssWithLess($config);
        } else {
            $output['bootstrap_css'] = $this->buildCssWithoutLess($config);
        }

        $output['bootstrap_js'] = $this->buildJs($config);
        $output['jquery'] = $this->buildJquery($config);

        return $output;
    }
67635
public static function create(array $configuration)
    {
        $currentConfiguration = is_array($configuration) ? array_merge(self::$defaultConfiguration, $configuration)
            : self::$defaultConfiguration;

        $class = self::className($currentConfiguration);

        $adapter = new $class($currentConfiguration[Config::PARAMS]);

        return new Storage($adapter);
    }
569670
public static function createFromArray(array $values)
    {
        $collection = new self();

        foreach ($values as $key => $value) {
            $collection->set($key, $value);
        }

        return $collection;
    }
1248322
protected function createModelFromArray(array $array)
    {
        $account = new SEPAAccount();
        $account->setIban($array[1]);
        $account->setBic($array[2]);
        $account->setAccountNumber($array[3]);
        $account->setSubAccount($array[4]);
        $account->setBlz($array[6]);

        return $account;
    }
860716
private function _fromAssociativeArray(array $array)
    {
        foreach ($this->_fields as $fieldName => $field) {
            $fieldType = $field['FieldType'];   
            if (is_array($fieldType)) {
                if ($this->_isComplexType($fieldType[0])) {
                    if (array_key_exists($fieldName, $array)) { 
                        $elements = $array[$fieldName];
                        if (!$this->_isNumericArray($elements)) {
                            $elements =  array($elements);    
                        }
                        if (count ($elements) >= 1) {
                            require_once (dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $fieldType[0]) . ".php");

                            foreach ($elements as $element) {
                                $this->_fields[$fieldName]['FieldValue'][] = new $fieldType[0]($element);
                            }
                        }
                    } 
                } else {
                    if (array_key_exists($fieldName, $array)) {
                        $elements = $array[$fieldName];
                        if (!$this->_isNumericArray($elements)) {
                            $elements =  array($elements);    
                        }
                        if (count ($elements) >= 1) {
                            foreach ($elements as $element) {
                                $this->_fields[$fieldName]['FieldValue'][] = $element;
                            }
                        }  
                    }
                }
            } else {
                 if ($this->_isComplexType($fieldType)) {
                    if (array_key_exists($fieldName, $array)) {
                        require_once (dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $fieldType) . ".php");
                        $this->_fields[$fieldName]['FieldValue'] = new $fieldType($array[$fieldName]);
                    }   
                 } else {
                    if (array_key_exists($fieldName, $array)) {
                        $this->_fields[$fieldName]['FieldValue'] = $array[$fieldName];
                    }
                 }
            }
        }
    }
69081
public static function createFromArray(array $data)
    {
        $self = new self();

        foreach ($data as $translation) {
            $self->addTranslation(Translation::createFromArray($translation));
        }

        return $self;
    }
962008
public function buildArray()
    {
        // Initialization
        $query = ProductQuery::create();
        $this->country = Country::getShopLocation();
        $this->calculator = new Calculator();
        $this->currencies = CurrencyQuery::create()->find();
        $this->locales = $this->getExistingLocales();

        // Loop application
        if (BooleanOrBothType::ANY !== $visible = $this->getVisible()) {
            $query->filterByVisible($visible);
        }

        $limit = $this->getLimit();

        // Array building
        $results = [];

        /** @var \Thelia\Model\Product $product */
        foreach ($query->find() as $i => $product) {
            if ($i >= $limit) {
                break;
            }

            $row = &$results[];
            $productPrices = [];

            // Add descriptive
            foreach ($this->locales as $locale) {
                $translation = $product->getTranslation($locale);

                $row["url_".$locale] = $product->getUrl($locale);
                $row["title_".$locale] =  $translation->getTitle();
                $row["description_".$locale] =  $translation->getDescription();
            }

            $row["id"] = $product->getId();
            $row["ref"] = $product->getRef();

            $row["attribute"] = "";
            $row["attribute_av"] = "";

            // Handle PSE / price information
            /** @var \Thelia\Model\ProductSaleElements $pse */
            foreach ($product->getProductSaleElementss() as $pse) {
                $this->handleProductSaleElements($row, $productPrices, $pse);
            }

            foreach ($productPrices as $currencyCode => $productPrice) {
                $row["price_".$currencyCode] = $productPrice;
            }

            // Them add image url
            $image = ProductImageQuery::create()
                ->filterByProduct($product)
                ->orderByPosition()
                ->findOne()
            ;

            if (null !== $image) {
                $event = new ImageEvent();
                $width = $this->getWidth();
                $height = $this->getHeight();

                if (! is_null($width)) {
                    $event->setWidth($width);
                }
                if (! is_null($height)) {
                    $event->setHeight($height);
                }

                $sourceFilePath = sprintf(
                    "%s%s/%s/%s",
                    THELIA_ROOT,
                    ConfigQuery::read('images_library_path', 'local'.DS.'media'.DS.'images'),
                    "product",
                    $image->getFile()
                );

                $event->setSourceFilepath($sourceFilePath);
                $event->setCacheSubdirectory("product");

                $this->container->get("event_dispatcher")->dispatch(TheliaEvents::IMAGE_PROCESS, $event);

                $row["image_url"] = $event->getFileUrl();
            } else {
                $row["image_url"] = null;
            }
        }

        return $results;
    }