/**
     * Adds a route collection at the end of the current set by appending all
     * routes of the added collection.
     *
     * @param RouteCollection $collection      A RouteCollection instance
     *
     * @api
     */
    public function addCollection(RouteCollection $collection)
    {
        // This is to keep BC for getParent() and getRoot(). It does not prevent
        // infinite loops by recursive referencing. But we don't need that logic
        // anymore as the tree logic has been deprecated and we are just widening
        // the accepted range.
        $collection->parent = $this;

        // this is to keep BC
        $numargs = func_num_args();
        if ($numargs > 1) {
            $collection->addPrefix($this->prefix . func_get_arg(1));
            if ($numargs > 2) {
                $collection->addDefaults(func_get_arg(2));
                if ($numargs > 3) {
                    $collection->addRequirements(func_get_arg(3));
                    if ($numargs > 4) {
                        $collection->addOptions(func_get_arg(4));
                    }
                }
            }
        } else {
            // the sub-collection must have the prefix of the parent (current instance) prepended because it does not
            // necessarily already have it applied (depending on the order RouteCollections are added to each other)
            // this will be removed when the BC layer for getPrefix() is removed
            $collection->addPrefix($this->prefix);
        }

        // we need to remove all routes with the same names first because just replacing them
        // would not place the new route at the end of the merged array
        foreach ($collection->all() as $name => $route) {
            unset($this->routes[$name]);
            $this->routes[$name] = $route;
        }

        $this->resources = array_merge($this->resources, $collection->getResources());
    }
 public function testAddDefaultsAndRequirementsAndOptions()
 {
     $collection = new RouteCollection();
     $collection->add('foo', new Route('/{placeholder}'));
     $collection1 = new RouteCollection();
     $collection1->add('bar', new Route('/{placeholder}', array('_controller' => 'fixed', 'placeholder' => 'default'), array('placeholder' => '.+'), array('option' => 'value')));
     $collection->addCollection($collection1);
     $collection->addDefaults(array('placeholder' => 'new-default'));
     $this->assertEquals(array('placeholder' => 'new-default'), $collection->get('foo')->getDefaults(), '->addDefaults() adds defaults to all routes');
     $this->assertEquals(array('_controller' => 'fixed', 'placeholder' => 'new-default'), $collection->get('bar')->getDefaults(), '->addDefaults() adds defaults to all routes and overwrites existing ones');
     $collection->addRequirements(array('placeholder' => '\\d+'));
     $this->assertEquals(array('placeholder' => '\\d+'), $collection->get('foo')->getRequirements(), '->addRequirements() adds requirements to all routes');
     $this->assertEquals(array('placeholder' => '\\d+'), $collection->get('bar')->getRequirements(), '->addRequirements() adds requirements to all routes and overwrites existing ones');
     $collection->addOptions(array('option' => 'new-value'));
     $this->assertEquals(array('option' => 'new-value', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), $collection->get('bar')->getOptions(), '->addOptions() adds options to all routes and overwrites existing ones');
 }