Created
January 2, 2011 22:15
-
-
Save Rendez/762872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StaticFilesConfigHandler extends AgaviXmlConfigHandler | |
{ | |
const XML_NAMESPACE = 'http://domain.com/config/parts/static_files/1.0'; | |
const VERSION_REPLACEMENT_VAR = 'timestamp'; | |
public function execute(AgaviXmlConfigDomDocument $document) | |
{ | |
// settig up our default namespace | |
$document->setDefaultNamespace(self::XML_NAMESPACE, 'static_files'); | |
$routing = AgaviContext::getInstance($this->context)->getRouting(); | |
$data = array(); | |
// let's do our fancy work | |
foreach($document->getConfigurationElements() as $cfg) { | |
if($cfg->has('routes')) { | |
$this->parseRoutesAndFiles($routing, $cfg->get('routes'), $data); | |
} | |
} | |
$code = sprintf('$this->files = %s;', var_export($data, true)); | |
return $this->generate($code, $document->documentURI); | |
} | |
protected function parseRoutesAndFiles(AgaviRouting $routing, $routes, &$data) | |
{ | |
$controller = $this->context->getController(); | |
$request = $this->context->getRequest(); | |
foreach($routes as $route) { | |
$outputTypes = array(); | |
$routeName = $route->getAttribute('name'); | |
if($route->hasAttribute('output_type')) { | |
foreach(explode(' ', $route->getAttribute('output_type')) as $ot) { | |
if($controller->getOutputType($ot)){ | |
$outputTypes[] = $ot; | |
} | |
} | |
} else { | |
$outputTypes[] = $controller->getOutputType()->getName(); // Defaults to HTML | |
} | |
foreach($route->get('filelist') as $filelist){ | |
$metatype = $filelist->getAttribute('metatype'); | |
foreach($filelist->getElementsByTagName('file') as $file) { | |
foreach($outputTypes as $ot) { | |
if ($file->hasAttribute('name')) { | |
$data[$routeName][$ot][$metatype][$file->getAttribute('name')] = AgaviToolkit::expandDirectives($file->getValue()); | |
} else { | |
$data[$routeName][$ot][$metatype][] = AgaviToolkit::expandDirectives($file->getValue()); | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment