Creating items object using given config data collection

@param array $collection
@throws InvalidConfigException
341908
protected function generateItems(array $collection)
    {
        $this->_items = [];
        $this->_children = [];

        foreach ($collection as $c) {

            foreach ($c as $key => $value) {
                if (is_array($value)) {

                    if (count($value) == 1 && isset($value['children']) && is_array($value['children'])) {
                        if (!isset($this->_children[$key])) {
                            $this->_children[$key] = [];
                        }

                        foreach ($value['children'] as $kid) {
                            $this->_children[$key][] = $kid;
                        }

                        continue;
                    }

                    if (!isset($value['type'])) {
                        throw new InvalidConfigException('Please specify type for ' . $key . ' auth item!');
                    }

                    if ($value['type'] == Item::TYPE_ROLE) {
                        $item = $this->_auth->createRole($key);
                    } elseif ($value['type'] == Item::TYPE_PERMISSION) {
                        $item = $this->_auth->createPermission($key);
                    } else {
                        throw new InvalidConfigException('Wrong type for ' . $key . ' auth item! Type can be ' . Item::TYPE_ROLE . ' (role) or ' . Item::TYPE_PERMISSION . ' (permission).');
                    }

                    $item->description = isset($value['description']) ? $value['description'] : null;
                    $item->data = isset($value['data']) ? $value['data'] : null;

                    if (isset($value['rule']) && $value['rule'] instanceof Rule) {
                        /** @var Rule $rule */
                        $rule = $value['rule'];
                        $rule->updatedAt = time();
                        $item->ruleName = !empty($rule->name) ? $rule->name : get_class($rule);
                        $this->_items[$item->ruleName] = $rule;
                    }

                    if (isset($value['children']) && is_array($value['children'])) {

                        if (!isset($this->_children[$key])) {
                            $this->_children[$key] = [];
                        }

                        foreach ($value['children'] as $kid) {
                            $this->_children[$key][] = $kid;
                        }
                    }

                } else {
                    $item = $this->_auth->createPermission($key);
                    $item->description = $value;
                }

                $this->_items[$key] = $item;
            }
        }
    }
845365
protected function guardType($items) : void {
        // this allows guardType($items) to receive
        // both a single item or an array of items
        if ( ! is_array($items)) {
            $items = array($items);
        }

        // throw an exception if any items are not
        // an instance of the required type
        foreach ($items as $item) {
            if ( ! $item instanceof $this->collectionType) {
                throw new \InvalidArgumentException(
                    "Got " . (is_object($item) ? get_class($item) : $item) . " but expected " . $this->collectionType
                );
            }
        }
    }
1155346
private function AddCookieToConfig($collection)
	{
		foreach($collection as $key => $value)
		{
			$this->addPairToConfig('cookie.' . $key, $value);
		}
	}
1268071
public function setCollectors(array $collectors)
    {
        $this->collectors = [];
        foreach ($collectors as $collector) {
            $this->addCollector($collector);
        }
    }
1282259
public function merge(ArrayCollection $collection)
    {
        if (!$collection instanceof GeometryCollection || $collection->getGeometryType() !== $this->getGeometryType()) {
            throw new InvalidArgumentException("Collections types don't match, you can't merge.");
        }

        return parent::merge($collection);
    }
1084323
protected function validate($config): void
    {
        // Check that $config is an array
        if (! Validator::arrayType()->validate($config)) {
            throw new InvalidConfigException('The config must be an array.');
        }

        // Check boolean parameters
        if (! Validator::key('interface', Validator::boolType())->validate($config)) {
            throw new InvalidConfigException('"interface" parameter must be set as a boolean.');
        }
        if (! Validator::key('private', Validator::boolType())->validate($config)) {
            throw new InvalidConfigException('"private" parameter must be set as a boolean.');
        }
        if (! Validator::key('auto', Validator::boolType())->validate($config)) {
            throw new InvalidConfigException('"auto" parameter must be set as a boolean.');
        }

        $this->validatePhpdoc($config);
    }
791839
private function verifyElementsType(array $elements): void
    {
        $allowedType = $this->getAllowedType();
        if ($allowedType !== DTO::class
            && (!\class_exists($allowedType) || !\in_array(DTO::class, \class_implements($allowedType), true))
        ) {
            throw new InvalidCollectionTypeException(\sprintf(
                'Allowed class type for %s should be a %s, %s given',
                static::class,
                DTO::class,
                $allowedType
            ));
        }

        foreach ($elements as $element) {
            if (!\is_object($element) || !\is_a($element, $allowedType)) {
                throw new InvalidParameterException(\sprintf(
                    'All elements of %s should be instances of %s, %s given',
                    static::class,
                    $allowedType,
                    \is_object($element) ? \get_class($element) : \gettype($element)
                ));
            }
        }
    }
373713
public function setCollections($collections)
    {
        if (!is_array($collections) && !$collections instanceof Traversable) {
            throw new Exception\InvalidArgumentException(sprintf(
                '%s: expects an array or Traversable, received "%s"',
                __METHOD__,
                (is_object($collections) ? get_class($collections) : gettype($collections))
            ));
        }

        if ($collections instanceof Traversable) {
            $collections = ArrayUtils::iteratorToArray($collections);
        }

        $this->collections = $collections;
    }
1141144
public function create(SmartCollection &$smartCollection)
    {
        $data = $smartCollection->exportData();
        $endpoint = '/admin/smart_collections.json';
        $response = $this->request(
            $endpoint, 'POST', array(
            'smart_collection' => $data
            )
        );
        $smartCollection->setData($response['smart_collection']);
    }
94645
public function exchangeArray($collection)
    {
        if (!is_array($collection) && !($collection instanceof Traversable)) {
            throw new Exception\InvalidArgumentException(
                sprintf(
                    'Expected argument "array" or "Traversable"; "%s" given',
                    gettype($collection) . (is_object($collection) ? '(' . get_class($collection) . ')' : '')
                )
            );
        }

        if ($collection instanceof Traversable) {
            $collection = ArrayUtils::iteratorToArray($collection);
        }

        foreach ($collection as $key => $value) {
            $this->set($key, $value);
        }
    }
1281935
public function setCollection(\collection $collection = null)
    {
        if ($collection === null) {
            $this->baseId = null;

            return;
        }
        $this->baseId = $collection->get_base_id();
    }
845420
protected function configureRoutes(RouteCollection $collection)
    {
        parent::configureRoutes($collection);
        $collection->add('duplicate', $this->getRouterIdParameter() . '/duplicate');
        $collection->add('generateEntityCode');

        /* Needed or not needed ...
         * in sonata-project/admin-bundle/Controller/CRUDController.php
         * the batchAction method
         * throw exception if the http method is not POST
        */
        if ($collection->get('batch')) {
            $collection->get('batch')->setMethods(['POST']);
        }
    }
396985
public function setCollection($collection)
    {
        $this->collection = (array) $collection;
        $this->setCount(count($this->collection));

        return $this;
    }
1221417
public function merge(CollectionInterface ...$collections): CollectionInterface
    {
        $temp = [$this->data];

        foreach ($collections as $index => $collection) {
            if (!$collection instanceof static) {
                throw new CollectionMismatchException(
                    \sprintf('Collection with index %d must be of type %s', $index, static::class)
                );
            }

            $temp[] = $collection->toArray();
        }

        return new static(\array_merge(...$temp));
    }
915141
public function init()
    {
        NestableAsset::register($this->getView());
        if ($this->dataProvider !== null) {
            $this->prepareItems();
        }
        if ($this->items === null) {
            throw new InvalidConfigException('The "dataProvider" property or "items" property must be set at least one.');
        }
        Html::addCssClass($this->options, $this->rootClass);

        if (!ArrayHelper::keyExists('id', $this->options)) {
            $this->options['id'] = uniqid('w_');
        }

    }
1148672
public function update(array $collection)
    {
        $this->_auth = Yii::$app->authManager;
        $this->generateItems($collection);
        $this->manageItems();
        $this->manageRelations();
        if ($this->_auth instanceof \yii\rbac\DbManager) {
            $this->_auth->invalidateCache();
        }
    }
759056
protected function configureOptions(array $optionsArray): OptionCollection
    {
        $options = new OptionCollection\ArrayOptionCollection();
        foreach ($optionsArray as $key => $option) {
            if ($key === OptionRepository::PREFIX) {
                continue;
            }

            if ($option instanceof Option) {
                $options->add($option);
                continue;
            }

            if (is_callable($option)) {
                $option = $option($this->config);
            }

            if (is_string($option)) {
                $option = new $option();
            }

            if (! $option instanceof Option) {
                throw InvalidOption::fromOption($option);
            }

            $options->add($option);
        }

        return $options;
    }