@@ -46,7 +46,7 @@ |
||
46 | 46 | /** |
47 | 47 | * Drop tables if exists |
48 | 48 | * |
49 | - * @param array $tables |
|
49 | + * @param string[] $tables |
|
50 | 50 | */ |
51 | 51 | protected function dropTables(array $tables) |
52 | 52 | { |
@@ -16,7 +16,7 @@ |
||
16 | 16 | * |
17 | 17 | * @param string $bundle |
18 | 18 | * @param string $tag |
19 | - * @param $implements Fully qualified interface name must be implemented |
|
19 | + * @param string $implements Fully qualified interface name must be implemented |
|
20 | 20 | * @return array |
21 | 21 | * @throws StructureException |
22 | 22 | */ |
@@ -10,33 +10,33 @@ |
||
10 | 10 | class TaggedServicesPass implements CompilerPassInterface |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * Save tagged service into a cache file |
|
15 | - * |
|
16 | - * @param ContainerBuilder $container |
|
17 | - * @param string $tag |
|
18 | - * @param string $fileName |
|
19 | - */ |
|
20 | - private function saveTaggedServices(ContainerBuilder $container, $tag, $fileName) |
|
21 | - { |
|
22 | - $services = array(); |
|
23 | - foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) { |
|
24 | - $services[] = $id; |
|
25 | - } |
|
26 | - $php = '<?php return ' . var_export($services, true) . ';'; |
|
27 | - file_put_contents($container->getParameter('kernel.cache_dir') . DIRECTORY_SEPARATOR . $fileName, $php); |
|
28 | - } |
|
13 | + /** |
|
14 | + * Save tagged service into a cache file |
|
15 | + * |
|
16 | + * @param ContainerBuilder $container |
|
17 | + * @param string $tag |
|
18 | + * @param string $fileName |
|
19 | + */ |
|
20 | + private function saveTaggedServices(ContainerBuilder $container, $tag, $fileName) |
|
21 | + { |
|
22 | + $services = array(); |
|
23 | + foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) { |
|
24 | + $services[] = $id; |
|
25 | + } |
|
26 | + $php = '<?php return ' . var_export($services, true) . ';'; |
|
27 | + file_put_contents($container->getParameter('kernel.cache_dir') . DIRECTORY_SEPARATOR . $fileName, $php); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Process the build |
|
32 | - * |
|
33 | - * @param ContainerBuilder $container |
|
34 | - */ |
|
35 | - public function process(ContainerBuilder $container) |
|
36 | - { |
|
37 | - $this->saveTaggedServices($container, 'bundle.install', 'services.bundle.install.php'); |
|
38 | - $this->saveTaggedServices($container, 'bundle.update', 'services.bundle.update.php'); |
|
39 | - $this->saveTaggedServices($container, 'bundle.uninstall', 'services.bundle.uninstall.php'); |
|
40 | - } |
|
30 | + /** |
|
31 | + * Process the build |
|
32 | + * |
|
33 | + * @param ContainerBuilder $container |
|
34 | + */ |
|
35 | + public function process(ContainerBuilder $container) |
|
36 | + { |
|
37 | + $this->saveTaggedServices($container, 'bundle.install', 'services.bundle.install.php'); |
|
38 | + $this->saveTaggedServices($container, 'bundle.update', 'services.bundle.update.php'); |
|
39 | + $this->saveTaggedServices($container, 'bundle.uninstall', 'services.bundle.uninstall.php'); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -12,173 +12,173 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Generator |
14 | 14 | { |
15 | - use BundleInformations; |
|
15 | + use BundleInformations; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Return services.yml file path |
|
19 | - * |
|
20 | - * @param BaseBundle $bundle |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - protected function getYamlFilePath(BaseBundle $bundle) |
|
24 | - { |
|
25 | - return $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'services.yml'; |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Parse Yaml service declaration |
|
30 | - * |
|
31 | - * @param BaseBundle $bundle |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - protected function parseServicesYaml(BaseBundle $bundle) |
|
35 | - { |
|
36 | - $servicesFilePath = $this->getYamlFilePath($bundle); |
|
37 | - $return = array(); |
|
38 | - if (file_exists($servicesFilePath)) { |
|
39 | - $return = Yaml::parse(file_get_contents($servicesFilePath)); |
|
40 | - if ($return === null) { |
|
41 | - $return = array(); |
|
42 | - } |
|
43 | - } |
|
44 | - if (array_key_exists('services', $return) === false || is_array($return['services']) === false) { |
|
45 | - $return['services'] = array(); |
|
46 | - } |
|
47 | - return $return; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Return a ClassGenerator |
|
52 | - * |
|
53 | - * @param BaseBundle $bundleInfos |
|
54 | - * @param string $class Class name |
|
55 | - * @param string $interface Interface to use, just class name |
|
56 | - * @return ClassGenerator |
|
57 | - */ |
|
58 | - protected function initGenerator(BaseBundle $bundleInfos, $class, $interface) |
|
59 | - { |
|
60 | - $return = new ClassGenerator(); |
|
61 | - $return->setClassName($class); |
|
62 | - $return->setNamespace($bundleInfos->getNamespace() . '\Service\Install'); |
|
63 | - $return->setTraits(array( |
|
64 | - 'kujaff\VersionsBundle\Model\BundleNameFromClassName', |
|
65 | - 'kujaff\VersionsBundle\Model\DoctrineHelper', |
|
66 | - )); |
|
67 | - $return->setExtends('Symfony\Component\DependencyInjection\ContainerAware'); |
|
68 | - $return->addUse('kujaff\VersionsBundle\Model\\' . $interface, 'Base' . $interface); |
|
69 | - $return->addInterface('Base' . $interface); |
|
70 | - $return->setConcatTraits(true); |
|
71 | - |
|
72 | - return $return; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Register an installer service |
|
77 | - * |
|
78 | - * @param BaseBundle $bundleInfos |
|
79 | - * @param string $type Type (install, update or uninstall) |
|
80 | - * @param string $class Class (Install, Update or Uninstall) |
|
81 | - */ |
|
82 | - protected function registerInstallerService(BaseBundle $bundleInfos, $type, $class) |
|
83 | - { |
|
84 | - $serviceId = strtolower($bundleInfos->getName()) . '.installer.' . $type; |
|
85 | - $fullyQualifiedClass = $bundleInfos->getNamespace() . '\Service\Install\\' . $class; |
|
86 | - $serviceOptions = array( |
|
87 | - 'calls' => array(array('setContainer' => array('@service_container'))), |
|
88 | - 'tags' => array(array('name' => 'bundle.' . $type)) |
|
89 | - ); |
|
90 | - $this->registerService($bundleInfos->getName(), $serviceId, $fullyQualifiedClass, $serviceOptions); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Register a new service in Resources/config/services.yml |
|
95 | - * |
|
96 | - * @param string $bundle Bundle name, ex 'FooBundle' |
|
97 | - * @param string $service Service name, ex 'foobundle.service' |
|
98 | - * @param string $class Fully qualified class name, ex 'Foo\Bar\ClassName' |
|
99 | - * @param array $options Options, ex array('arguments' => array('@service_container'), 'tags' => array(array('name' => 'bundle.install')) |
|
17 | + /** |
|
18 | + * Return services.yml file path |
|
19 | + * |
|
20 | + * @param BaseBundle $bundle |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + protected function getYamlFilePath(BaseBundle $bundle) |
|
24 | + { |
|
25 | + return $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'services.yml'; |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Parse Yaml service declaration |
|
30 | + * |
|
31 | + * @param BaseBundle $bundle |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + protected function parseServicesYaml(BaseBundle $bundle) |
|
35 | + { |
|
36 | + $servicesFilePath = $this->getYamlFilePath($bundle); |
|
37 | + $return = array(); |
|
38 | + if (file_exists($servicesFilePath)) { |
|
39 | + $return = Yaml::parse(file_get_contents($servicesFilePath)); |
|
40 | + if ($return === null) { |
|
41 | + $return = array(); |
|
42 | + } |
|
43 | + } |
|
44 | + if (array_key_exists('services', $return) === false || is_array($return['services']) === false) { |
|
45 | + $return['services'] = array(); |
|
46 | + } |
|
47 | + return $return; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Return a ClassGenerator |
|
52 | + * |
|
53 | + * @param BaseBundle $bundleInfos |
|
54 | + * @param string $class Class name |
|
55 | + * @param string $interface Interface to use, just class name |
|
56 | + * @return ClassGenerator |
|
57 | + */ |
|
58 | + protected function initGenerator(BaseBundle $bundleInfos, $class, $interface) |
|
59 | + { |
|
60 | + $return = new ClassGenerator(); |
|
61 | + $return->setClassName($class); |
|
62 | + $return->setNamespace($bundleInfos->getNamespace() . '\Service\Install'); |
|
63 | + $return->setTraits(array( |
|
64 | + 'kujaff\VersionsBundle\Model\BundleNameFromClassName', |
|
65 | + 'kujaff\VersionsBundle\Model\DoctrineHelper', |
|
66 | + )); |
|
67 | + $return->setExtends('Symfony\Component\DependencyInjection\ContainerAware'); |
|
68 | + $return->addUse('kujaff\VersionsBundle\Model\\' . $interface, 'Base' . $interface); |
|
69 | + $return->addInterface('Base' . $interface); |
|
70 | + $return->setConcatTraits(true); |
|
71 | + |
|
72 | + return $return; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Register an installer service |
|
77 | + * |
|
78 | + * @param BaseBundle $bundleInfos |
|
79 | + * @param string $type Type (install, update or uninstall) |
|
80 | + * @param string $class Class (Install, Update or Uninstall) |
|
81 | + */ |
|
82 | + protected function registerInstallerService(BaseBundle $bundleInfos, $type, $class) |
|
83 | + { |
|
84 | + $serviceId = strtolower($bundleInfos->getName()) . '.installer.' . $type; |
|
85 | + $fullyQualifiedClass = $bundleInfos->getNamespace() . '\Service\Install\\' . $class; |
|
86 | + $serviceOptions = array( |
|
87 | + 'calls' => array(array('setContainer' => array('@service_container'))), |
|
88 | + 'tags' => array(array('name' => 'bundle.' . $type)) |
|
89 | + ); |
|
90 | + $this->registerService($bundleInfos->getName(), $serviceId, $fullyQualifiedClass, $serviceOptions); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Register a new service in Resources/config/services.yml |
|
95 | + * |
|
96 | + * @param string $bundle Bundle name, ex 'FooBundle' |
|
97 | + * @param string $service Service name, ex 'foobundle.service' |
|
98 | + * @param string $class Fully qualified class name, ex 'Foo\Bar\ClassName' |
|
99 | + * @param array $options Options, ex array('arguments' => array('@service_container'), 'tags' => array(array('name' => 'bundle.install')) |
|
100 | 100 | * @throws \Exception |
101 | - */ |
|
102 | - public function registerService($bundle, $service, $class, $options = array()) |
|
103 | - { |
|
104 | - $bundleInfos = $this->getBundleInformations($bundle); |
|
105 | - $services = $this->parseServicesYaml($bundleInfos); |
|
106 | - |
|
107 | - $services['services'][$service] = array_merge(array('class' => $class), $options); |
|
108 | - $yamlFilePath = $this->getYamlFilePath($bundleInfos); |
|
109 | - $yamlContent = Yaml::dump($services, 4); |
|
110 | - |
|
111 | - $result = file_put_contents($yamlFilePath, $yamlContent); |
|
112 | - if ($result === false) { |
|
113 | - throw new \Exception('Error while writing "' . $yamlFilePath . '", maybe directory or file can\'t be written.'); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Indicate if a tagged service exists in bundle |
|
119 | - * |
|
120 | - * @param string $bundle Bundle name, ex 'FooBundle' |
|
121 | - * @param string $tag Tag name, ex 'bundle.install' |
|
122 | - * @return boolean |
|
123 | - */ |
|
124 | - public function existsTaggedService($bundle, $tag) |
|
125 | - { |
|
126 | - $services = $this->parseServicesYaml($this->getBundleInformations($bundle)); |
|
127 | - foreach ($services['services'] as $params) { |
|
128 | - if (array_key_exists('tags', $params) && is_array($params['tags'])) { |
|
129 | - foreach ($params['tags'] as $tagInfos) { |
|
130 | - if (array_key_exists('name', $tagInfos) && $tagInfos['name'] == $tag) { |
|
131 | - return true; |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Generate everything to make your bundle versionned |
|
141 | - * |
|
142 | - * @param string $bundle Name of your bundle, ex 'FooBundle' |
|
143 | - * @param string $versionAfterInstallation Version after installation, ex '1.0.0' |
|
144 | - * @param string $updateTrait Trait to use in Update service, like kujaff\VersionsBundle\Model\UpdateOneVersionOneMethod |
|
145 | - */ |
|
146 | - public function generate($bundle, $versionAfterInstallation, $updateTrait = null, $force = false) |
|
147 | - { |
|
148 | - $this->generateInstallService($bundle, $versionAfterInstallation, $force); |
|
149 | - $this->generateUpdateService($bundle, $updateTrait, $force); |
|
150 | - $this->generateUninstallService($bundle, $force); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Generate service and register it for installation |
|
155 | - * |
|
156 | - * @param string $bundle Name of your bundle, ex 'FooBundle' |
|
157 | - * @param string $version Version after installation, ex '1.0.0' |
|
158 | - * @param boolean $force Indicate if you want to regenerate it although it exists |
|
159 | - * @return boolean |
|
160 | - */ |
|
161 | - public function generateInstallService($bundle, $version, $force = false) |
|
162 | - { |
|
163 | - $bundleInfos = $this->getBundleInformations($bundle); |
|
164 | - // do not create service if another one is already registered |
|
165 | - if ($this->existsTaggedService($bundle, 'bundle.install') && $force === false) { |
|
166 | - return false; |
|
167 | - } |
|
168 | - |
|
169 | - $generator = $this->initGenerator($bundleInfos, 'Install', 'Install'); |
|
170 | - |
|
171 | - $generator->startMethod('install', ClassGenerator::VISIBILITY_PUBLIC, false, array('Installation'), 'kujaff\VersionsBundle\Entity\Version'); |
|
172 | - $generator->addMethodLine($generator->getCode4Comment('Do your stuff here')); |
|
173 | - $generator->addMethodLine($generator->getCode4Line('return new Version(\'' . $version . '\');', 0, 0)); |
|
174 | - $generator->finishMethod(); |
|
175 | - |
|
176 | - $generator->write($bundleInfos->getPath() . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR . 'Install.php'); |
|
177 | - |
|
178 | - $this->registerInstallerService($bundleInfos, 'install', 'Install'); |
|
179 | - |
|
180 | - return true; |
|
181 | - } |
|
101 | + */ |
|
102 | + public function registerService($bundle, $service, $class, $options = array()) |
|
103 | + { |
|
104 | + $bundleInfos = $this->getBundleInformations($bundle); |
|
105 | + $services = $this->parseServicesYaml($bundleInfos); |
|
106 | + |
|
107 | + $services['services'][$service] = array_merge(array('class' => $class), $options); |
|
108 | + $yamlFilePath = $this->getYamlFilePath($bundleInfos); |
|
109 | + $yamlContent = Yaml::dump($services, 4); |
|
110 | + |
|
111 | + $result = file_put_contents($yamlFilePath, $yamlContent); |
|
112 | + if ($result === false) { |
|
113 | + throw new \Exception('Error while writing "' . $yamlFilePath . '", maybe directory or file can\'t be written.'); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Indicate if a tagged service exists in bundle |
|
119 | + * |
|
120 | + * @param string $bundle Bundle name, ex 'FooBundle' |
|
121 | + * @param string $tag Tag name, ex 'bundle.install' |
|
122 | + * @return boolean |
|
123 | + */ |
|
124 | + public function existsTaggedService($bundle, $tag) |
|
125 | + { |
|
126 | + $services = $this->parseServicesYaml($this->getBundleInformations($bundle)); |
|
127 | + foreach ($services['services'] as $params) { |
|
128 | + if (array_key_exists('tags', $params) && is_array($params['tags'])) { |
|
129 | + foreach ($params['tags'] as $tagInfos) { |
|
130 | + if (array_key_exists('name', $tagInfos) && $tagInfos['name'] == $tag) { |
|
131 | + return true; |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | + } |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Generate everything to make your bundle versionned |
|
141 | + * |
|
142 | + * @param string $bundle Name of your bundle, ex 'FooBundle' |
|
143 | + * @param string $versionAfterInstallation Version after installation, ex '1.0.0' |
|
144 | + * @param string $updateTrait Trait to use in Update service, like kujaff\VersionsBundle\Model\UpdateOneVersionOneMethod |
|
145 | + */ |
|
146 | + public function generate($bundle, $versionAfterInstallation, $updateTrait = null, $force = false) |
|
147 | + { |
|
148 | + $this->generateInstallService($bundle, $versionAfterInstallation, $force); |
|
149 | + $this->generateUpdateService($bundle, $updateTrait, $force); |
|
150 | + $this->generateUninstallService($bundle, $force); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Generate service and register it for installation |
|
155 | + * |
|
156 | + * @param string $bundle Name of your bundle, ex 'FooBundle' |
|
157 | + * @param string $version Version after installation, ex '1.0.0' |
|
158 | + * @param boolean $force Indicate if you want to regenerate it although it exists |
|
159 | + * @return boolean |
|
160 | + */ |
|
161 | + public function generateInstallService($bundle, $version, $force = false) |
|
162 | + { |
|
163 | + $bundleInfos = $this->getBundleInformations($bundle); |
|
164 | + // do not create service if another one is already registered |
|
165 | + if ($this->existsTaggedService($bundle, 'bundle.install') && $force === false) { |
|
166 | + return false; |
|
167 | + } |
|
168 | + |
|
169 | + $generator = $this->initGenerator($bundleInfos, 'Install', 'Install'); |
|
170 | + |
|
171 | + $generator->startMethod('install', ClassGenerator::VISIBILITY_PUBLIC, false, array('Installation'), 'kujaff\VersionsBundle\Entity\Version'); |
|
172 | + $generator->addMethodLine($generator->getCode4Comment('Do your stuff here')); |
|
173 | + $generator->addMethodLine($generator->getCode4Line('return new Version(\'' . $version . '\');', 0, 0)); |
|
174 | + $generator->finishMethod(); |
|
175 | + |
|
176 | + $generator->write($bundleInfos->getPath() . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR . 'Install.php'); |
|
177 | + |
|
178 | + $this->registerInstallerService($bundleInfos, 'install', 'Install'); |
|
179 | + |
|
180 | + return true; |
|
181 | + } |
|
182 | 182 | |
183 | 183 | /** |
184 | 184 | * @param string $bundle |
@@ -187,60 +187,60 @@ discard block |
||
187 | 187 | * @return bool |
188 | 188 | * @throws \kujaff\VersionsBundle\Exception\BundleNotFoundException |
189 | 189 | */ |
190 | - public function generateUpdateService($bundle, $trait = null, $force = false) |
|
191 | - { |
|
192 | - $bundleInfos = $this->getBundleInformations($bundle); |
|
193 | - // do not create service if another one is already registered |
|
194 | - if ($this->existsTaggedService($bundle, 'bundle.update') && $force === false) { |
|
195 | - return false; |
|
196 | - } |
|
197 | - |
|
198 | - $generator = $this->initGenerator($bundleInfos, 'Update', 'Update'); |
|
199 | - |
|
200 | - if ($trait !== null) { |
|
201 | - $generator->addTrait($trait); |
|
202 | - } else { |
|
203 | - $generator->startMethod('update', ClassGenerator::VISIBILITY_PUBLIC, false, array('Updates'), 'kujaff\VersionsBundle\Entity\Version'); |
|
204 | - $generator->addMethodParameter('bundleVersion', 'kujaff\VersionsBundle\Entity\BundleVersion', null, true, 'Current installed version'); |
|
205 | - $generator->addMethodParameter('version', 'kujaff\VersionsBundle\Entity\Version', null, true, 'Update to this version'); |
|
206 | - $generator->addMethodLine($generator->getCode4Comment('Do your stuff here')); |
|
207 | - $generator->addMethodLine($generator->getCode4Comment('Return updated version after your patchs', 0, 0)); |
|
208 | - $generator->addMethodLine($generator->getCode4Line('return $version;', 0, 0)); |
|
209 | - $generator->finishMethod(); |
|
210 | - } |
|
211 | - |
|
212 | - $generator->write($bundleInfos->getPath() . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR . 'Update.php'); |
|
213 | - |
|
214 | - $this->registerInstallerService($bundleInfos, 'update', 'Update'); |
|
215 | - |
|
216 | - return true; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Generate service and register it for uninstall |
|
221 | - * |
|
222 | - * @param string $bundle Name of your bundle, ex 'FooBundle' |
|
223 | - * @param boolean $force Indicate if you want to regenerate it although it exists |
|
224 | - * @return boolean |
|
225 | - */ |
|
226 | - public function generateUninstallService($bundle, $force = false) |
|
227 | - { |
|
228 | - $bundleInfos = $this->getBundleInformations($bundle); |
|
229 | - // do not create service if another one is already registered |
|
230 | - if ($this->existsTaggedService($bundle, 'bundle.uninstall') && $force === false) { |
|
231 | - return false; |
|
232 | - } |
|
233 | - |
|
234 | - $generator = $this->initGenerator($bundleInfos, 'Uninstall', 'Uninstall'); |
|
235 | - |
|
236 | - $generator->startMethod('uninstall', ClassGenerator::VISIBILITY_PUBLIC, false, array('Uninstall')); |
|
237 | - $generator->addMethodLine($generator->getCode4Comment('Do your stuff here', 0, 0)); |
|
238 | - $generator->finishMethod(); |
|
239 | - |
|
240 | - $generator->write($bundleInfos->getPath() . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR . 'Uninstall.php'); |
|
241 | - |
|
242 | - $this->registerInstallerService($bundleInfos, 'uninstall', 'Uninstall'); |
|
243 | - |
|
244 | - return true; |
|
245 | - } |
|
190 | + public function generateUpdateService($bundle, $trait = null, $force = false) |
|
191 | + { |
|
192 | + $bundleInfos = $this->getBundleInformations($bundle); |
|
193 | + // do not create service if another one is already registered |
|
194 | + if ($this->existsTaggedService($bundle, 'bundle.update') && $force === false) { |
|
195 | + return false; |
|
196 | + } |
|
197 | + |
|
198 | + $generator = $this->initGenerator($bundleInfos, 'Update', 'Update'); |
|
199 | + |
|
200 | + if ($trait !== null) { |
|
201 | + $generator->addTrait($trait); |
|
202 | + } else { |
|
203 | + $generator->startMethod('update', ClassGenerator::VISIBILITY_PUBLIC, false, array('Updates'), 'kujaff\VersionsBundle\Entity\Version'); |
|
204 | + $generator->addMethodParameter('bundleVersion', 'kujaff\VersionsBundle\Entity\BundleVersion', null, true, 'Current installed version'); |
|
205 | + $generator->addMethodParameter('version', 'kujaff\VersionsBundle\Entity\Version', null, true, 'Update to this version'); |
|
206 | + $generator->addMethodLine($generator->getCode4Comment('Do your stuff here')); |
|
207 | + $generator->addMethodLine($generator->getCode4Comment('Return updated version after your patchs', 0, 0)); |
|
208 | + $generator->addMethodLine($generator->getCode4Line('return $version;', 0, 0)); |
|
209 | + $generator->finishMethod(); |
|
210 | + } |
|
211 | + |
|
212 | + $generator->write($bundleInfos->getPath() . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR . 'Update.php'); |
|
213 | + |
|
214 | + $this->registerInstallerService($bundleInfos, 'update', 'Update'); |
|
215 | + |
|
216 | + return true; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Generate service and register it for uninstall |
|
221 | + * |
|
222 | + * @param string $bundle Name of your bundle, ex 'FooBundle' |
|
223 | + * @param boolean $force Indicate if you want to regenerate it although it exists |
|
224 | + * @return boolean |
|
225 | + */ |
|
226 | + public function generateUninstallService($bundle, $force = false) |
|
227 | + { |
|
228 | + $bundleInfos = $this->getBundleInformations($bundle); |
|
229 | + // do not create service if another one is already registered |
|
230 | + if ($this->existsTaggedService($bundle, 'bundle.uninstall') && $force === false) { |
|
231 | + return false; |
|
232 | + } |
|
233 | + |
|
234 | + $generator = $this->initGenerator($bundleInfos, 'Uninstall', 'Uninstall'); |
|
235 | + |
|
236 | + $generator->startMethod('uninstall', ClassGenerator::VISIBILITY_PUBLIC, false, array('Uninstall')); |
|
237 | + $generator->addMethodLine($generator->getCode4Comment('Do your stuff here', 0, 0)); |
|
238 | + $generator->finishMethod(); |
|
239 | + |
|
240 | + $generator->write($bundleInfos->getPath() . DIRECTORY_SEPARATOR . 'Service' . DIRECTORY_SEPARATOR . 'Install' . DIRECTORY_SEPARATOR . 'Uninstall.php'); |
|
241 | + |
|
242 | + $this->registerInstallerService($bundleInfos, 'uninstall', 'Uninstall'); |
|
243 | + |
|
244 | + return true; |
|
245 | + } |
|
246 | 246 | } |
@@ -7,10 +7,10 @@ |
||
7 | 7 | interface UninstallInterface |
8 | 8 | { |
9 | 9 | |
10 | - public function getBundleName(); |
|
10 | + public function getBundleName(); |
|
11 | 11 | |
12 | - /** |
|
13 | - * Uninstall |
|
14 | - */ |
|
15 | - public function uninstall(); |
|
12 | + /** |
|
13 | + * Uninstall |
|
14 | + */ |
|
15 | + public function uninstall(); |
|
16 | 16 | } |
@@ -7,21 +7,21 @@ |
||
7 | 7 | trait BundleNameFromClassName |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * Return bundle name, search for it in class namespace |
|
12 | - * |
|
13 | - * @return string |
|
10 | + /** |
|
11 | + * Return bundle name, search for it in class namespace |
|
12 | + * |
|
13 | + * @return string |
|
14 | 14 | * @throws \Exception |
15 | - */ |
|
16 | - public function getBundleName() |
|
17 | - { |
|
18 | - $parts = array_reverse(explode('\\', get_called_class())); |
|
19 | - foreach ($parts as $part) { |
|
20 | - if (substr($part, -6) == 'Bundle') { |
|
21 | - return $part; |
|
22 | - } |
|
23 | - } |
|
24 | - throw \Exception('Bundle name cannot be found in "' . get_called_class() . '" class name.'); |
|
25 | - } |
|
15 | + */ |
|
16 | + public function getBundleName() |
|
17 | + { |
|
18 | + $parts = array_reverse(explode('\\', get_called_class())); |
|
19 | + foreach ($parts as $part) { |
|
20 | + if (substr($part, -6) == 'Bundle') { |
|
21 | + return $part; |
|
22 | + } |
|
23 | + } |
|
24 | + throw \Exception('Bundle name cannot be found in "' . get_called_class() . '" class name.'); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | } |
@@ -7,20 +7,20 @@ |
||
7 | 7 | trait BundleInformations |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * Return bundle informations |
|
12 | - * |
|
13 | - * @param string $name |
|
14 | - * @return \Symfony\Component\HttpKernel\Bundle\Bundle |
|
10 | + /** |
|
11 | + * Return bundle informations |
|
12 | + * |
|
13 | + * @param string $name |
|
14 | + * @return \Symfony\Component\HttpKernel\Bundle\Bundle |
|
15 | 15 | * @throws BundleNotFoundException |
16 | - */ |
|
17 | - protected function getBundleInformations($name) |
|
18 | - { |
|
19 | - $bundles = $this->container->get('kernel')->getBundles(); |
|
20 | - if (array_key_exists($name, $bundles) === false) { |
|
21 | - throw new BundleNotFoundException('Bundle "' . $name . '" not found.'); |
|
22 | - } |
|
23 | - return $bundles[$name]; |
|
24 | - } |
|
16 | + */ |
|
17 | + protected function getBundleInformations($name) |
|
18 | + { |
|
19 | + $bundles = $this->container->get('kernel')->getBundles(); |
|
20 | + if (array_key_exists($name, $bundles) === false) { |
|
21 | + throw new BundleNotFoundException('Bundle "' . $name . '" not found.'); |
|
22 | + } |
|
23 | + return $bundles[$name]; |
|
24 | + } |
|
25 | 25 | |
26 | 26 | } |
@@ -11,11 +11,11 @@ |
||
11 | 11 | interface UpdatePatchInterface |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Do the update |
|
16 | - * |
|
17 | - * @param BundleVersion $version |
|
18 | - * @return Version |
|
19 | - */ |
|
20 | - public function update(BundleVersion $version); |
|
14 | + /** |
|
15 | + * Do the update |
|
16 | + * |
|
17 | + * @param BundleVersion $version |
|
18 | + * @return Version |
|
19 | + */ |
|
20 | + public function update(BundleVersion $version); |
|
21 | 21 | } |