Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7defbc707e
Fetching contributors…

Cannot retrieve contributors at this time

file 139 lines (127 sloc) 4.338 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
<?php
/**
* This file is part of NoiseLabs-SmartyBundle
*
* NoiseLabs-SmartyBundle is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* NoiseLabs-SmartyBundle is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with NoiseLabs-SmartyBundle; if not, see
* <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2011 Vítor Brandão
*
* @category NoiseLabs
* @package SmartyBundle
* @copyright (C) 2011 Vítor Brandão <noisebleed@noiselabs.org>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL-3
* @link http://www.noiselabs.org
*/

namespace NoiseLabs\Bundle\SmartyBundle\Extension;

use NoiseLabs\Bundle\SmartyBundle\Extension\Plugin\BlockPlugin;
use NoiseLabs\Bundle\SmartyBundle\Extension\Plugin\FunctionPlugin;
use NoiseLabs\Bundle\SmartyBundle\Extension\Plugin\ModifierPlugin;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides helper functions to link to assets (images, Javascript,
* stylesheets, etc.).
*
* @author Vítor Brandão <noisebleed@noiselabs.org>
*/
class AssetsExtension extends AbstractExtension
{
    protected $container;

    /**
* Constructor.
*/
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
* {@inheritdoc}
*/
    public function getPlugins()
    {
        return array(
            new BlockPlugin('asset', $this, 'getAssetUrl_block'),
            new ModifierPlugin('asset', $this, 'getAssetUrl_modifier'),
            new FunctionPlugin('assets_version', $this, 'getAssetsVersion')
        );
    }

    /**
* Returns the public path of an asset.
*
* Absolute paths (i.e. http://...) are returned unmodified.
*
* @param string $path A public path
* @param string $packageName The name of the asset package to use
*
* @return string A public path which takes into account the base path and URL path
*/
    public function getAssetUrl($path, $packageName = null)
    {
        return $this->container->get('templating.helper.assets')->getUrl($path, $packageName);
    }

    /**
* Returns the public path of an asset
*
* Absolute paths (i.e. http://...) are returned unmodified.
*
* @param string $path A public path
*
* @return string A public path which takes into account the base path and URL path
*/
    public function getAssetUrl_block(array $parameters = array(), $path = null, $template, &$repeat)
    {
        // only output on the closing tag
        if (!$repeat) {
            $parameters = array_merge(array(
                'package' => null,
            ), $parameters);

            return $this->container->get('templating.helper.assets')->getUrl($path, $parameters['package']);
        }
    }

    /**
* Returns the public path of an asset
*
* Absolute paths (i.e. http://...) are returned unmodified.
*
* @param string $path A public path
*
* @return string A public path which takes into account the base path
* and URL path
*/
    public function getAssetUrl_modifier($path, $package = null)
    {
        return $this->container->get('templating.helper.assets')->getUrl($path, $package);
    }

    /**
* Returns the version of the assets in a package
*
* @return int
*/
    public function getAssetsVersion(array $parameters = array(), \Smarty_Internal_Template $template)
    {
        $parameters = array_merge(array(
                'package' => null,
        ), $parameters);

        return $this->container->get('templating.helper.assets')->getVersion($parameters['package']);
    }

    /**
* Returns the name of the extension.
*
* @return string The extension name
*/
    public function getName()
    {
        return 'assets';
    }
}
Something went wrong with that request. Please try again.