/** * Creates an object and uses it as a Singleton. * This can should though be used as a regular object. Only use this if specifically required. * @return sfAssetManager */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * @see lib/vendor/symfony/lib/debug/sfWebDebugPanel#getPanelContent() */ public function getPanelContent() { try { $manager = sfAssetsManager::getInstance(); $packages = $manager->getPackages(); $loadedPackages = self::$loadedPackages; ob_start(); include dirname(__FILE__) . '/_panel.html.php'; $html = ob_get_contents(); ob_end_clean(); } catch (Exception $e) { $html = 'Unable to render the sfAssetsManager toolbar'; } return $html; }
/** * Loads assets into the Response from configuration file * @param string $package * @param string $assetsType optional */ function load_assets($package, $assetsType = null) { sfAssetsManager::getInstance()->load($package, $assetsType); }
<?php require dirname(__FILE__) . '/../bootstrap/unit.php'; require dirname(__FILE__) . '/../../lib/model/sfAssetsManagerPackageCollection.class.php'; require dirname(__FILE__) . '/../../lib/compressor/sfAssetsManagerJSMinifier.class.php'; $config = (include dirname(__FILE__) . '/../fixtures/assets_manager.yml.php'); sfConfig::set('app_sf_assets_manager_plugin_filename_format', '%s.package'); $response = new sfWebResponse(new sfEventDispatcher()); $manager = new sfAssetsManager(clone $response, false); $manager->setConfiguration($config); $t = new lime_test(15, new lime_output_color()); $manager->load('basic'); $t->diag('Basic js/css package'); $t->is_deeply(array_keys($manager->getResponse()->getJavascripts()), array('basic.js', '/folder/otherbasic.js'), '->load(basic) includes multiple js in specified order'); $t->is_deeply(array_keys($manager->getResponse()->getStylesheets()), array('basic.css', '/folder/otherbasic.css'), '->load(basic) includes multiple css in specified order'); $manager->setResponse(clone $response); $manager->load('complex'); $t->diag('Importing package'); $t->is_deeply(array_keys($manager->getResponse()->getJavascripts()), array('basic.js', '/folder/otherbasic.js', 'complex1.js', 'complex2.js'), '->load(complex) imports specified package and includes specific js'); $t->is_deeply(array_keys($manager->getResponse()->getStylesheets()), array('basic.css', '/folder/otherbasic.css', 'complex1.css', 'complex2.css'), '->load(complex) imports specified package and includes specific js'); $manager->setResponse(clone $response); $manager->load('nested'); $t->diag('Importing nested packages'); $t->is_deeply(array_keys($manager->getResponse()->getJavascripts()), array('basic.js', '/folder/otherbasic.js', 'complex1.js', 'complex2.js', 'nested.js'), '->load(nested) imports specified package and includes specific js'); $t->is_deeply(array_keys($manager->getResponse()->getStylesheets()), array('basic.css', '/folder/otherbasic.css', 'complex1.css', 'complex2.css'), '->load(nested) imports specified package and includes specific css'); $manager->setResponse(clone $response); $manager->load('full'); $t->diag('Importing multiple and nested packages'); $t->is_deeply(array_keys($manager->getResponse()->getJavascripts()), array('framework.js', 'basic.js', '/folder/otherbasic.js', 'complex1.js', 'complex2.js', 'nested.js', 'full.js'), '->load(full) imports specified package and includes specific js'); $t->is_deeply(array_keys($manager->getResponse()->getStylesheets()), array('basic.css', '/folder/otherbasic.css', 'complex1.css', 'complex2.css', 'full.css'), '->load(full) imports specified package and includes specific css'); $manager->setResponse(clone $response);
/** * Loads js and css files to the response. This is an abstraction layer * for no dependency of sfAssetsManagerPlugin * @see sfAssetsManagerPlugin * @param string $package package name to load * @param sfWebResponse optional. Context Response by default */ public static function loadAssets($package, sfWebResponse $response = null) { $response = $response ? $response : sfContext::getInstance()->getResponse(); // sfAssetsManager if (class_exists('sfAssetsManager')) { $manager = sfAssetsManager::getInstance(); $manager->load(sprintf('sfMediaBrowser.%s', $package)); } else { $config = sfConfig::get(sprintf('app_sf_media_browser_assets_%s', $package)); if (isset($config['js']) && !empty($config['js'])) { foreach ((array) $config['js'] as $js) { $response->addJavascript($js); } } if (isset($config['css']) && !empty($config['css'])) { foreach ((array) $config['css'] as $css) { $response->addStylesheet($css); } } } }