/** * getAsset - render assets of a given type for a package * * @param string $name * @param sfDynamicsAssetCollectionDefinition $package * @param string $type * @return string */ public function getAsset($name, sfDynamicsAssetCollectionDefinition $package, $type) { $extension = sfDynamics::getExtensionFromType($type); $getAssets = 'get' . ucfirst($type) . 's'; if (count($assets = $package->{$getAssets}())) { $paths = $package->getPaths('/' . $extension); if (sfDynamicsConfig::isCacheEnabled()) { $cacheKey = sfDynamicsCache::generateKey($package, $type); $cache = sfDynamics::getCache(); if ($cache->has($cacheKey)) { if (sfDynamicsConfig::isCacheUpToDateCheckEnabled()) { foreach ($assets as $asset) { // this is needed to know the actual file path on disk, and to know its mtime. $asset->computePath($paths); } if ($cache->isStillUpToDate($package, $type, $cacheKey)) { $result = $cache->get($cacheKey); } } else { $result = $cache->get($cacheKey); } } } // still no result? let's build it! if (!isset($result)) { $result = $this->getConcatenatedAssets($package, $paths, $assets); $result = sfDynamicsConfig::getConcatenatedAssetFilterChainFor($type)->filter($result); if (sfDynamicsConfig::isCacheEnabled()) { $cache->set($cacheKey, $result); } } return $result; } else { return ''; } }
public function parseXml($xml) { $xml = parent::parseXml($xml); if (isset($xml->path)) { foreach ($xml->path as $path) { switch (isset($path['priority']) ? $path['priority'] : 'high') { case 'high': $this->appendPaths[] = $this->parsePath((string) $path); break; case 'low': $this->prependPaths[] = $this->parsePath((string) $path); break; default: throw new sfConfigurationException('Path «priority» attribute can only be «high» or «low».'); } } } if (isset($xml->require)) { foreach ($xml->require as $require) { $this->requires[] = (string) $require; } } if (isset($xml->conflict)) { foreach ($xml->conflict as $conflict) { $this->conflicts[] = (string) $conflict; } } if (isset($xml->i18n)) { foreach ($xml->i18n as $i18n) { if (!strlen($language = (string) $i18n['language'])) { throw new sfConfigurationException('Each I18n tag should have a language attribute.'); } $this->i18n[$language] = new sfDynamicsAssetCollectionDefinition($i18n); } } if (isset($xml->theme)) { $hasDefault = false; foreach ($xml->theme as $theme) { if (!strlen($themeName = (string) $theme['name'])) { throw new sfConfigurationException('Each theme tag should have a name attribute.'); } $this->themes[$themeName] = new sfDynamicsAssetCollectionDefinition($theme); } } return $xml; }
<?php require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; require_once dirname(__FILE__) . '/../../../lib/config/sfDynamicsBaseDefinition.class.php'; require_once dirname(__FILE__) . '/../../../lib/config/sfDynamicsAssetCollectionDefinition.class.php'; $testCount = 4; $jsArray = array('testjs'); $cssArray = array('testcss'); $t = new lime_test($testCount, new lime_output_color()); try { $i = sfDynamicsAssetCollectionDefinition::__set_state(array('javascripts' => $jsArray, 'stylesheets' => $cssArray)); $t->isa_ok($i, 'sfDynamicsAssetCollectionDefinition', '__set_state works and returns an instance of right class'); } catch (Exception $e) { $t->fail('__set_state failed'); } $t->is($i->getJavascripts(), $jsArray, 'Javascripts getter'); $t->is($i->getStylesheets(), $cssArray, 'Stylesheets getter'); try { $i = sfDynamicsAssetCollectionDefinition::__set_state(array('wrong' => $jsArray)); $t->fail('__set_state should fail if wrong initialization data is sen.'); } catch (sfConfigurationException $e) { $t->ok(1, '__set_state failed because of wrong parameters given'); } catch (Exception $e) { $t->fail('__set_state failed, but with wrong exception type'); }
public static function generateKey(sfDynamicsAssetCollectionDefinition $package, $type) { return '/' . sfConfig::get('sf_environment') . (sfConfig::get('sf_debug') ? '/debug' : '') . '/' . $type . '/' . md5($package->getCacheKey()); }