示例#1
0
    def getContainerExtension(self):
        """Returns the bundle's container extension.

        @return: ExtensionInterface|null The container extension

        @raise LogicException: When alias not respect the naming convention
        """
        if self._extension is None:
            basename = re.sub(r"Bundle$", "", self.getName())

            moduleName = "{0}.dependency".format(self.getNamespace())
            className = "{0}.{1}Extension".format(moduleName, basename)

            r = ReflectionClass(className)

            if r.exists():
                extension = r.newInstance()
                # check naming convention
                expectedAlias = ContainerBuilder.underscore(basename)
                if expectedAlias != extension.getAlias():
                    raise LogicException(
                        'The extension alias for the default extension of a '
                        'bundle must be the underscored version of the '
                        'bundle name ("{0}" instead of "{1}")'
                        ''.format(expectedAlias, extension.getAlias()))

                self._extension = extension
            else:
                self._extension = False

        if self._extension:
            return self._extension
示例#2
0
 def getAlias(self):
     className = str(type(self).__name__)
     if not className.endswith("Extension"):
         raise BadMethodCallException(
             'This extension does not follow the naming convention; '
             'you must overwrite the getAlias() method.')
     classBaseName = className[:-9]
     return ContainerBuilder.underscore(classBaseName)
示例#3
0
 def getAlias(self):
     className = str(type(self).__name__);
     if not className.endswith("Extension"):
         raise BadMethodCallException(
             'This extension does not follow the naming convention; '
             'you must overwrite the getAlias() method.'
         );
     classBaseName = className[:-9];
     return ContainerBuilder.underscore(classBaseName);