@@ -26,26 +26,23 @@ class ServiceBuilder extends BaseBuilder
26
26
*/
27
27
protected function prepare ()
28
28
{
29
- $ instances = $ this ->container ->getParameter ( $ this ->getAlias () . '.instance ' );
29
+ $ instances = $ this ->container ->getParameter ($ this ->getAlias () . '.instance ' );
30
30
31
31
foreach ($ instances as $ name => $ instance ) {
32
- $ this ->buildInstance ( $ name , $ instance );
32
+ $ this ->buildInstance ($ name , $ instance );
33
33
}
34
34
}
35
35
36
- private function buildInstance ( $ name , array $ instance )
36
+ private function buildInstance ($ name , array $ instance )
37
37
{
38
- $ typeId = $ this ->getAlias () . '.abstract. ' . $ instance [ 'type ' ];
39
- if (!$ this ->container ->hasDefinition ( $ typeId )) {
40
- throw new InvalidConfigurationException ( sprintf (
41
- "`%s` is not a valid cache type. If you are using a custom type, make sure to add your service. " ,
42
- $ instance [ 'type ' ]
43
- ) );
38
+ $ typeId = $ this ->getAlias () . '.abstract. ' . $ instance ['type ' ];
39
+ if (!$ this ->container ->hasDefinition ($ typeId )) {
40
+ throw new InvalidConfigurationException (sprintf ("`%s` is not a valid cache type. If you are using a custom type, make sure to add your service. " , $ instance ['type ' ]));
44
41
}
45
42
46
- $ service = $ this ->buildService ( $ typeId , $ name , $ instance );
43
+ $ service = $ this ->buildService ($ typeId , $ name , $ instance );
47
44
48
- $ this ->prepareCacheClass ( $ service , $ name , $ instance );
45
+ $ this ->prepareCacheClass ($ service , $ name , $ instance );
49
46
}
50
47
51
48
/**
@@ -55,104 +52,96 @@ private function buildInstance( $name, array $instance )
55
52
*
56
53
* @return Definition
57
54
*/
58
- private function buildService ( $ typeId , $ name , array $ instance )
55
+ private function buildService ($ typeId , $ name , array $ instance )
59
56
{
60
- $ namespace = is_null ( $ instance [ 'namespace ' ] ) ? $ name : $ instance [ 'namespace ' ];
57
+ $ namespace = is_null ($ instance ['namespace ' ] ) ? $ name : $ instance ['namespace ' ];
61
58
62
59
$ coreName = $ this ->getAlias () . '.instance. ' . $ name . '.core ' ;
63
- $ service = $ this ->container ->setDefinition (
64
- $ coreName ,
65
- new Definition ( $ this ->container ->getParameter ( $ typeId . '.class ' ) )
66
- )
67
- ->addMethodCall ( 'setNamespace ' , array ( $ namespace ) )
68
- ->setPublic ( false );
69
-
70
- $ this ->container ->setDefinition (
71
- $ this ->getAlias () . '.instance. ' . $ name ,
72
- new Definition ( $ this ->container ->getParameter ( 'aequasi_cache.service.class ' ) )
73
- )
74
- ->addMethodCall ( 'setCache ' , array ( new Reference ( $ coreName ) ) )
75
- ->addMethodCall ( 'setLogging ' , array ( $ this ->container ->getParameter ( 'kernel.debug ' ) ) );
76
-
77
- $ alias = new Alias ( $ this ->getAlias () . '.instance. ' . $ name );
78
- $ this ->container ->setAlias ( $ this ->getAlias () . '. ' . $ name , $ alias );
60
+ $ service = $ this ->container ->setDefinition ($ coreName , new Definition ($ this ->container ->getParameter ($ typeId . '.class ' )))
61
+ ->addMethodCall ('setNamespace ' , array ($ namespace ))
62
+ ->setPublic (false );
63
+
64
+ $ this ->container ->setDefinition ($ this ->getAlias () . '.instance. ' . $ name , new Definition ($ this ->container ->getParameter ('aequasi_cache.service.class ' )))
65
+ ->addMethodCall ('setCache ' , array (new Reference ($ coreName )))
66
+ ->addMethodCall ('setLogging ' , array ($ this ->container ->getParameter ('kernel.debug ' )));
67
+
68
+ $ alias = new Alias ($ this ->getAlias () . '.instance. ' . $ name );
69
+ $ this ->container ->setAlias ($ this ->getAlias () . '. ' . $ name , $ alias );
79
70
80
71
return $ service ;
81
72
}
82
73
83
- private function prepareCacheClass ( Definition $ service , $ name , array $ instance )
74
+ private function prepareCacheClass (Definition $ service , $ name , array $ instance )
84
75
{
85
- $ type = $ instance [ 'type ' ];
86
- $ id = sprintf ( "%s.instance.%s.%s_instance " , $ this ->getAlias (), $ name , $ type );
76
+ $ type = $ instance ['type ' ];
77
+ $ id = sprintf ("%s.instance.%s.%s_instance " , $ this ->getAlias (), $ name , $ type );
87
78
$ cache = null ;
88
79
89
80
switch ($ type ) {
90
81
case 'memcache ' :
91
- if (empty ( $ instance [ 'id ' ] )) {
92
- $ cache = new Definition ( 'Memcache ' );
93
- $ cache ->setPublic ( false );
94
- foreach ($ instance [ 'hosts ' ] as $ config ) {
95
- $ host = empty ( $ config [ 'host ' ] ) ? 'localhost ' : $ config [ 'host ' ];
96
- $ port = empty ( $ config [ 'port ' ] ) ? 11211 : $ config [ 'port ' ];
97
- $ timeout = is_null ( $ config [ 'timeout ' ] ) ? 0 : $ config [ 'timeout ' ];
98
- $ cache ->addMethodCall ( 'addServer ' , array ( $ host , $ port , $ timeout ) );
82
+ if (empty ($ instance ['id ' ] )) {
83
+ $ cache = new Definition ('Memcache ' );
84
+ $ cache ->setPublic (false );
85
+ foreach ($ instance ['hosts ' ] as $ config ) {
86
+ $ host = empty ($ config ['host ' ] ) ? 'localhost ' : $ config ['host ' ];
87
+ $ port = empty ($ config ['port ' ] ) ? 11211 : $ config ['port ' ];
88
+ $ timeout = is_null ($ config ['timeout ' ] ) ? 0 : $ config ['timeout ' ];
89
+ $ cache ->addMethodCall ('addServer ' , array ($ host , $ port , $ timeout) );
99
90
}
100
- unset( $ config );
91
+ unset($ config );
101
92
102
- $ this ->container ->setDefinition ( $ id , $ cache );
93
+ $ this ->container ->setDefinition ($ id , $ cache );
103
94
} else {
104
- $ id = $ instance [ 'id ' ];
95
+ $ id = $ instance ['id ' ];
105
96
}
106
- $ service ->addMethodCall ( sprintf ( 'set%s ' , ucwords ( $ type ) ), array ( new Reference ( $ id ) ) );
97
+ $ service ->addMethodCall (sprintf ('set%s ' , ucwords ($ type) ), array (new Reference ($ id)) );
107
98
break ;
108
99
case 'memcached ' :
109
- if (empty ( $ instance [ 'id ' ] )) {
110
- $ cache = new Definition ( 'Memcached ' );
111
- if ($ instance [ 'persistent ' ]) {
112
- $ cache ->setArguments ( array ( serialize ( $ instance [ 'hosts ' ] ) ) );
100
+ if (empty ($ instance ['id ' ] )) {
101
+ $ cache = new Definition ('Memcached ' );
102
+ if ($ instance ['persistent ' ]) {
103
+ $ cache ->setArguments (array (serialize ($ instance ['hosts ' ])) );
113
104
}
114
105
115
- $ cache ->setPublic ( false );
116
- foreach ($ instance [ 'hosts ' ] as $ config ) {
117
- $ host = is_null ( $ config [ 'host ' ] ) ? 'localhost ' : $ config [ 'host ' ];
118
- $ port = is_null ( $ config [ 'port ' ] ) ? 11211 : $ config [ 'port ' ];
119
- $ weight = is_null ( $ config [ 'weight ' ] ) ? 0 : $ config [ 'weight ' ];
120
- $ cache ->addMethodCall ( 'addServer ' , array ( $ host , $ port , $ weight ) );
106
+ $ cache ->setPublic (false );
107
+ foreach ($ instance ['hosts ' ] as $ config ) {
108
+ $ host = is_null ($ config ['host ' ] ) ? 'localhost ' : $ config ['host ' ];
109
+ $ port = is_null ($ config ['port ' ] ) ? 11211 : $ config ['port ' ];
110
+ $ weight = is_null ($ config ['weight ' ] ) ? 0 : $ config ['weight ' ];
111
+ $ cache ->addMethodCall ('addServer ' , array ($ host , $ port , $ weight) );
121
112
}
122
- unset( $ config );
113
+ unset($ config );
123
114
124
- $ this ->container ->setDefinition ( $ id , $ cache );
115
+ $ this ->container ->setDefinition ($ id , $ cache );
125
116
} else {
126
- $ id = $ instance [ 'id ' ];
117
+ $ id = $ instance ['id ' ];
127
118
}
128
- $ service ->addMethodCall ( sprintf ( 'set%s ' , ucwords ( $ type ) ), array ( new Reference ( $ id ) ) );
119
+ $ service ->addMethodCall (sprintf ('set%s ' , ucwords ($ type) ), array (new Reference ($ id)) );
129
120
break ;
130
121
case 'redis ' :
131
- if (empty ( $ instance [ 'id ' ] )) {
132
- $ cache = new Definition ( 'Redis ' );
133
- $ cache ->setPublic ( false );
134
- foreach ($ instance [ 'hosts ' ] as $ config ) {
135
- $ host = empty ( $ config [ 'host ' ] ) ? 'localhost ' : $ config [ 'host ' ];
136
- $ port = empty ( $ config [ 'port ' ] ) ? 6379 : $ config [ 'port ' ];
137
- $ timeout = is_null ( $ config [ 'timeout ' ] ) ? 2 : $ config [ 'timeout ' ];
138
- $ cache ->addMethodCall ( 'connect ' , array ( $ host , $ port , $ timeout ) );
122
+ if (empty ($ instance ['id ' ] )) {
123
+ $ cache = new Definition ('Redis ' );
124
+ $ cache ->setPublic (false );
125
+ foreach ($ instance ['hosts ' ] as $ config ) {
126
+ $ host = empty ($ config ['host ' ] ) ? 'localhost ' : $ config ['host ' ];
127
+ $ port = empty ($ config ['port ' ] ) ? 6379 : $ config ['port ' ];
128
+ $ timeout = is_null ($ config ['timeout ' ] ) ? 2 : $ config ['timeout ' ];
129
+ $ cache ->addMethodCall ('connect ' , array ($ host , $ port , $ timeout) );
139
130
}
140
- unset( $ config );
131
+ unset($ config );
141
132
142
- $ this ->container ->setDefinition ( $ id , $ cache );
133
+ $ this ->container ->setDefinition ($ id , $ cache );
143
134
} else {
144
- $ id = $ instance [ 'id ' ];
135
+ $ id = $ instance ['id ' ];
145
136
}
146
- $ service ->addMethodCall ( sprintf ( 'set%s ' , ucwords ( $ type ) ), array ( new Reference ( $ id ) ) );
137
+ $ service ->addMethodCall (sprintf ('set%s ' , ucwords ($ type) ), array (new Reference ($ id)) );
147
138
break ;
148
139
case 'file_system ' :
149
140
case 'php_file ' :
150
- $ directory = is_null (
151
- $ instance [ 'directory ' ]
152
- ) ? '%kernel.cache_dir%/doctrine/cache ' : $ instance [ 'directory ' ];
153
- $ extension = is_null ( $ instance [ 'extension ' ] ) ? null : $ instance [ 'extension ' ];
141
+ $ directory = is_null ($ instance ['directory ' ]) ? '%kernel.cache_dir%/doctrine/cache ' : $ instance ['directory ' ];
142
+ $ extension = is_null ($ instance ['extension ' ]) ? null : $ instance ['extension ' ];
154
143
155
- $ service ->setArguments ( array ( $ directory , $ extension ) );
144
+ $ service ->setArguments (array ($ directory , $ extension) );
156
145
break ;
157
146
}
158
147
}
0 commit comments