Skip to content

Commit

Permalink
[AsseticBundle] added resources to the routing loader
Browse files Browse the repository at this point in the history
now the router will be aware of any changes assetic is aware of
  • Loading branch information
kriswallsmith committed Feb 25, 2011
1 parent 05055d4 commit d4db531
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Symfony/Bundle/AsseticBundle/Factory/FileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Bundle\AsseticBundle\Factory;

use Assetic\Factory\Resource\ResourceInterface;
use Assetic\Factory\Resource\FileResourceInterface;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Component\Templating\Loader\LoaderInterface;

Expand All @@ -20,7 +20,7 @@
*
* @author Kris Wallsmith <kris.wallsmith@symfony-project.com>
*/
class FileResource implements ResourceInterface
class FileResource implements FileResourceInterface
{
protected $loader;
protected $parser;
Expand Down Expand Up @@ -56,6 +56,11 @@ public function getContent()
return $this->loader->load($this->getTemplate())->getContent();
}

public function getPath()
{
return $this->path;
}

protected function getTemplate()
{
if (null === $this->template) {
Expand Down
20 changes: 18 additions & 2 deletions src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Bundle\AsseticBundle\Routing;

use Assetic\AssetManager;
use Assetic\Factory\LazyAssetManager;
use Assetic\Factory\Resource\FileResourceInterface;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

Expand All @@ -37,14 +39,28 @@ class AsseticLoader extends Loader
{
protected $am;

public function __construct(AssetManager $am)
public function __construct(LazyAssetManager $am)
{
$this->am = $am;
}

public function load($resource, $type = null)
{
$routes = new RouteCollection();

// resources
foreach ($this->am->getResources() as $resource) {
if (!$resource instanceof \Traversable) {
$resource = array($resource);
}
foreach ($resource as $r) {
if ($r instanceof FileResourceInterface) {
$routes->addResource(new FileResource($r->getPath()));
}
}
}

// routes
foreach ($this->am->getNames() as $name) {
$asset = $this->am->get($name);

Expand Down

0 comments on commit d4db531

Please sign in to comment.