-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependency.py
More file actions
82 lines (61 loc) · 2.34 KB
/
dependency.py
File metadata and controls
82 lines (61 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
# This file is part of the pymfony package.
#
# (c) Alexandre Quercia <alquerci@email.com>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
from __future__ import absolute_import;
from pymfony.component.system.oop import abstract;
from pymfony.component.system.oop import final;
from pymfony.component.dependency.compilerpass import MergeExtensionConfigurationPass as BaseMergeExtensionConfigurationPass;
from pymfony.component.dependency.extension import Extension as BaseExtension;
from pymfony.component.dependency import ContainerBuilder;
"""
"""
@abstract
class Extension(BaseExtension):
"""Allow adding classes to the class cache."""
def __init__(self):
self.__classes = list();
def getClassesToCompile(self):
"""Gets the classes to cache.
@return: dict A dict of classes
"""
return self.__classes;
def addClassesToCompile(self, classes):
"""Adds classes to the class cache.
@param classes: list A list of classes
"""
assert isinstance(classes, list);
self.__classes.extend(classes);
@abstract
class ConfigurableExtension(Extension):
@final
def load(self, configs, container):
"""
"""
self._loadInternal(self._processConfiguration(self.getConfiguration(list(), container), configs), container);
@abstract
def _loadInternal(self, mergedConfig, container):
"""Configures the passed container according to the merged
configuration.
@param mergedConfig: dict
@param container: ContainerBuilder
"""
pass;
class MergeExtensionConfigurationPass(BaseMergeExtensionConfigurationPass):
"""Ensures certain extensions are always loaded.
"""
def __init__(self, extensions):
"""Constructor.
@param extensions: list A list of extension name
"""
assert isinstance(extensions, list);
self.__extensions = extensions;
def process(self, container):
assert isinstance(container, ContainerBuilder);
for extension in self.__extensions:
if not container.getExtensionConfig(extension):
container.loadFromExtension(extension, dict());
BaseMergeExtensionConfigurationPass.process(self, container);