Skip to content

Commit

Permalink
[Routing] refactored resources
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 28, 2010
1 parent 7dfa995 commit 87ae06c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Components/Routing/Loader/XmlFileLoader.php
Expand Up @@ -4,7 +4,7 @@

use Symfony\Components\Routing\RouteCollection;
use Symfony\Components\Routing\Route;
use Symfony\Components\Routing\FileResource;
use Symfony\Components\Routing\Resource\FileResource;

/*
* This file is part of the Symfony framework.
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Components/Routing/Loader/YamlFileLoader.php
Expand Up @@ -4,7 +4,7 @@

use Symfony\Components\Routing\RouteCollection;
use Symfony\Components\Routing\Route;
use Symfony\Components\Routing\FileResource;
use Symfony\Components\Routing\Resource\FileResource;
use Symfony\Components\Yaml\Yaml;

/*
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Symfony\Components\Routing;
namespace Symfony\Components\Routing\Resource;

/*
* This file is part of the Symfony framework.
Expand Down Expand Up @@ -29,7 +29,17 @@ class FileResource implements ResourceInterface
*/
public function __construct($resource)
{
$this->resource = $resource;
$this->resource = realpath($resource);
}

/**
* Returns a string representation of the Resource.
*
* @return string A string representation of the Resource
*/
public function __toString()
{
return $this->resource;
}

/**
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Symfony\Components\Routing;
namespace Symfony\Components\Routing\Resource;

/*
* This file is part of the Symfony framework.
Expand All @@ -20,6 +20,13 @@
*/
interface ResourceInterface
{
/**
* Returns a string representation of the Resource.
*
* @return string A string representation of the Resource
*/
function __toString();

/**
* Returns true if the resource has not been updated since the given timestamp.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Components/Routing/RouteCollection.php
Expand Up @@ -2,6 +2,8 @@

namespace Symfony\Components\Routing;

use Symfony\Components\Routing\Resource\ResourceInterface;

/*
* This file is part of the Symfony framework.
*
Expand Down Expand Up @@ -111,7 +113,7 @@ public function addPrefix($prefix)
*/
public function getResources()
{
return $this->resources;
return array_unique($this->resources);
}

/**
Expand Down
Empty file.
Empty file.
Expand Up @@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/

namespace Symfony\Tests\Components\Routing;
namespace Symfony\Tests\Components\Routing\Resource;

use Symfony\Components\Routing\FileResource;
use Symfony\Components\Routing\Resource\FileResource;

class FileResourceTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -20,7 +20,7 @@ public function testGetResource()
$file = sys_get_temp_dir().'/tmp.xml';
touch($file);
$resource = new FileResource($file);
$this->assertEquals($file, $resource->getResource(), '->getResource() returns the path to the resource');
$this->assertEquals(realpath($file), $resource->getResource(), '->getResource() returns the path to the resource');
unlink($file);
}

Expand Down
Expand Up @@ -13,7 +13,7 @@

use Symfony\Components\Routing\RouteCollection;
use Symfony\Components\Routing\Route;
use Symfony\Components\Routing\FileResource;
use Symfony\Components\Routing\Resource\FileResource;

class RouteCollectionTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -45,9 +45,9 @@ public function testAddCollection()
$this->assertEquals('/foo/foo1', $collection->getRoute('foo')->getPattern(), '->addCollection() can add a prefix to all merged routes');

$collection = new RouteCollection();
$collection->addResource($foo = new FileResource('foo'));
$collection->addResource($foo = new FileResource(__DIR__.'/Fixtures/foo.xml'));
$collection1 = new RouteCollection();
$collection1->addResource($foo1 = new FileResource('foo1'));
$collection1->addResource($foo1 = new FileResource(__DIR__.'/Fixtures/foo1.xml'));
$collection->addCollection($collection1);
$this->assertEquals(array($foo, $foo1), $collection->getResources(), '->addCollection() merges resources');
}
Expand All @@ -65,7 +65,7 @@ public function testAddPrefix()
public function testResource()
{
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource('foo'));
$collection->addResource($foo = new FileResource(__DIR__.'/Fixtures/foo.xml'));
$this->assertEquals(array($foo), $collection->getResources(), '->addResources() adds a resource');
}
}

0 comments on commit 87ae06c

Please sign in to comment.