def _initializeBundles(self): """Initializes the data structures related to the bundle management. - the bundles property maps a bundle name to the bundle instance, - the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first). @raise LogicException: if two bundles share a common name @raise LogicException: if a bundle tries to extend a non-registered bundle @raise LogicException: if a bundle tries to extend itself @raise LogicException: if two bundles extend the same ancestor """ # init bundle self._bundles = dict(); topMostBundles = dict(); directChildren = dict(); for bundle in self.registerBundles(): assert isinstance(bundle, BundleInterface); name = bundle.getName(); if name in self._bundles.keys(): raise LogicException( 'Trying to register two bundles with the same name "{0}"' ''.format(name) ); self._bundles[name] = bundle; parentName = bundle.getParent(); if parentName: if parentName in directChildren.keys(): raise LogicException( 'Bundle "{0}" is directly extended by two bundles ' '"{1}" and "{2}".' ''.format(parentName, name, directChildren[parentName]) ); if parentName == name: raise LogicException( 'Bundle "{0}" can not extend itself.'.format(name) ); directChildren[parentName] = name; else: topMostBundles[name] = bundle; # look for orphans diff = Array.diff( list(directChildren.keys()), list(self._bundles.keys()), ); if diff: raise LogicException( 'Bundle "{0}" extends bundle "{1}", which is not registered.' ''.format(directChildren[diff[0]], diff[0]) ); # inheritance self._bundleMap = dict(); for name, bundle in topMostBundles.items(): bundleMap = [bundle]; hierarchy = [name]; while name in directChildren.keys(): name = directChildren[name]; bundleMap.insert(0, self._bundles[name]); hierarchy.append(name); for name in hierarchy: self._bundleMap[name] = list(bundleMap); bundleMap.pop();
def _initializeBundles(self): """Initializes the data structures related to the bundle management. - the bundles property maps a bundle name to the bundle instance, - the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first). @raise LogicException: if two bundles share a common name @raise LogicException: if a bundle tries to extend a non-registered bundle @raise LogicException: if a bundle tries to extend itself @raise LogicException: if two bundles extend the same ancestor """ # init bundle self._bundles = dict() topMostBundles = dict() directChildren = dict() for bundle in self.registerBundles(): assert isinstance(bundle, BundleInterface) name = bundle.getName() if name in self._bundles.keys(): raise LogicException( 'Trying to register two bundles with the same name "{0}"' ''.format(name)) self._bundles[name] = bundle parentName = bundle.getParent() if parentName: if parentName in directChildren.keys(): raise LogicException( 'Bundle "{0}" is directly extended by two bundles ' '"{1}" and "{2}".' ''.format(parentName, name, directChildren[parentName])) if parentName == name: raise LogicException( 'Bundle "{0}" can not extend itself.'.format(name)) directChildren[parentName] = name else: topMostBundles[name] = bundle # look for orphans diff = Array.diff( list(directChildren.keys()), list(self._bundles.keys()), ) if diff: raise LogicException( 'Bundle "{0}" extends bundle "{1}", which is not registered.' ''.format(directChildren[diff[0]], diff[0])) # inheritance self._bundleMap = dict() for name, bundle in topMostBundles.items(): bundleMap = [bundle] hierarchy = [name] while name in directChildren.keys(): name = directChildren[name] bundleMap.insert(0, self._bundles[name]) hierarchy.append(name) for name in hierarchy: self._bundleMap[name] = list(bundleMap) bundleMap.pop()
def _validate(self, config, name, path): """Validates the route configuration. @param: dict config A resource config @param string name The config key @param string path The loaded file path @raise InvalidArgumentException If one of the provided config keys is not supported, something is missing or the combination is nonsense """ if not isinstance(config, dict): raise InvalidArgumentException( 'The definition of "{0}" in "{1}" must be a Json object.' ''.format(name, path)) extraKeys = Array.diff(config.keys(), self.__availableKeys) if (extraKeys): raise InvalidArgumentException( 'The routing file "{0}" contains unsupported keys for "{1}": ' '"{2}". Expected one of: "{3}".'.format( path, name, '", "'.join(extraKeys), '", "'.join(self.__availableKeys), )) if 'resource' in config and 'path' in config: raise InvalidArgumentException( 'The routing file "{0}" must not specify both the "resource" ' 'key and the "path" key for "{1}". Choose between an import ' 'and a route definition.'.format(path, name)) if 'resource' in config and 'description' in config: raise InvalidArgumentException( 'The routing file "{0}" must not specify both the "resource" ' 'key and the "description" key for "{1}". Choose between an ' 'import and a route definition.'.format(path, name)) if 'resource' not in config and 'type' in config: raise InvalidArgumentException( 'The "type" key for the route definition "{0}" in "{1}" is ' 'unsupported. It is only available for imports in combination ' 'with the "resource" key.'.format(name, path)) if 'resource' not in config and 'path' not in config: raise InvalidArgumentException( 'You must define a "path" for the route "{0}" in file "{1}".' ''.format(name, path)) if 'path' in config and not config['path']: raise InvalidArgumentException( 'The "path" for the route "{0}" in file "{1}" cannot be empty.' ''.format(name, path)) if 'definition' in config: if 'arguments' in config['definition']: if not isinstance(config['definition']['arguments'], OrderedDict): raise InvalidArgumentException( 'The definition.arguments key should be a JSON object ' 'in route "{0}" in file "{1}".' ''.format(name, path)) if 'options' in config['definition']: if not isinstance(config['definition']['options'], dict): raise InvalidArgumentException( 'The definition.options key should be a JSON object ' 'in route "{0}" in file "{1}".' ''.format(name, path))
def _validate(self, config, name, path): """Validates the route configuration. @param: dict config A resource config @param string name The config key @param string path The loaded file path @raise InvalidArgumentException If one of the provided config keys is not supported, something is missing or the combination is nonsense """ if not isinstance(config, dict) : raise InvalidArgumentException( 'The definition of "{0}" in "{1}" must be a Json object.' ''.format(name, path) ); extraKeys = Array.diff(config.keys(), self.__availableKeys); if (extraKeys) : raise InvalidArgumentException( 'The routing file "{0}" contains unsupported keys for "{1}": ' '"{2}". Expected one of: "{3}".'.format( path, name, '", "'.join(extraKeys), '", "'.join(self.__availableKeys), )); if 'resource' in config and 'path' in config : raise InvalidArgumentException( 'The routing file "{0}" must not specify both the "resource" ' 'key and the "path" key for "{1}". Choose between an import ' 'and a route definition.'.format( path, name )); if 'resource' in config and 'description' in config : raise InvalidArgumentException( 'The routing file "{0}" must not specify both the "resource" ' 'key and the "description" key for "{1}". Choose between an ' 'import and a route definition.'.format( path, name )); if 'resource' not in config and 'type' in config : raise InvalidArgumentException( 'The "type" key for the route definition "{0}" in "{1}" is ' 'unsupported. It is only available for imports in combination ' 'with the "resource" key.'.format( name, path )); if 'resource' not in config and 'path' not in config : raise InvalidArgumentException( 'You must define a "path" for the route "{0}" in file "{1}".' ''.format(name, path) ); if 'path' in config and not config['path']: raise InvalidArgumentException( 'The "path" for the route "{0}" in file "{1}" cannot be empty.' ''.format(name, path) ); if 'definition' in config: if 'arguments' in config['definition']: if not isinstance(config['definition']['arguments'], OrderedDict): raise InvalidArgumentException( 'The definition.arguments key should be a JSON object ' 'in route "{0}" in file "{1}".' ''.format(name, path) ); if 'options' in config['definition']: if not isinstance(config['definition']['options'], dict): raise InvalidArgumentException( 'The definition.options key should be a JSON object ' 'in route "{0}" in file "{1}".' ''.format(name, path) );