sensio/SensioGeneratorBundle — pull request #100 by shiroyuki (2012-01-24 15:58:26+00:00)
Title: Patch to fix problem 

As I am suggested from https://github.com/sensio/SensioGeneratorBundle/issues/40, I re-worked on the fix and now send a pull request for the fix to *bundle generator error*.

The following is the original patch put in the comment.

```diff
diff --git a/Manipulator/RoutingManipulator.php b/Manipulator/RoutingManipulator.php
index 0026c47..71be1ea 100644
--- a/Manipulator/RoutingManipulator.php
+++ b/Manipulator/RoutingManipulator.php
@@ -48,9 +48,22 @@ class RoutingManipulator extends Manipulator
if (file_exists($this->file)) {
$current = file_get_contents($this->file);

- // Don't add same bundle twice
- if (false !== strpos($current, $bundle)) {
- throw new \RuntimeException(sprintf('Bundle "%s" is already imported.', $bundle));
+ // Don't add same bundle twice.
+ $currentRoutingLines = explode("\n", $current);
+ $currentRoutes = array();
+
+ // First, gather all routing keys.
+ foreach ($currentRoutingLines as $currentRoutingLine) {
+ if (empty($currentRoutingLine) || preg_match("/^[\s]/", $currentRoutingLine))
+ continue;
+
+ $currentRoutingLine = trim($currentRoutingLine);
+ $currentRoutes[] = substr($currentRoutingLine, 0, -1);
+ }
+
+ // Then, prevent a duplicate route from being added.
+ if (in_array($bundle, $currentRoutes)) {
+ throw new \RuntimeException(sprintf("Bundle \"%s\" is already imported.", $bundle));
}
} elseif (!is_dir($dir = dirname($this->file))) {
mkdir($dir, 0777, true);
```