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;
            }
        }
    }
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;
            }
        }
    }
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 ; } } }
Creating items object using given config data collection

@param array $collection
@throws InvalidConfigException
Creating items object using given config data collection